From 3a7e1cf527dad1c3bda2438fa665a071c72dbe8a Mon Sep 17 00:00:00 2001 From: Eugen Eisler Date: Sun, 29 Sep 2024 21:35:20 +0200 Subject: [PATCH] feat: add version updater bot --- .github/workflows/update-version.yml | 47 ++++++++++++++++++++++++++++ main.go | 3 -- version.go | 3 ++ 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/update-version.yml create mode 100644 version.go diff --git a/.github/workflows/update-version.yml b/.github/workflows/update-version.yml new file mode 100644 index 0000000..89911d3 --- /dev/null +++ b/.github/workflows/update-version.yml @@ -0,0 +1,47 @@ +name: Update Version File + +on: + push: + branches: + - main # Or whichever branch you want to monitor + +jobs: + update-version: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Git + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + - name: Get the latest tag + id: get_latest_tag + run: | + latest_tag=$(git describe --tags --abbrev=0) + echo "Latest tag is: $latest_tag" + echo "::set-output name=tag::$latest_tag" + + - name: Get the latest commit hash + id: get_commit_hash + run: | + commit_hash=$(git rev-parse --short HEAD) + echo "Commit hash is: $commit_hash" + echo "::set-output name=commit_hash::$commit_hash" + + - name: Update version file + run: | + latest_tag=${{ steps.get_latest_tag.outputs.tag }} + commit_hash=${{ steps.get_commit_hash.outputs.commit_hash }} + echo "package main" > version.go + echo "" >> version.go + echo "var version = \"${latest_tag}-${commit_hash}\"" >> version.go + + - name: Commit changes + run: | + git add version.go + git commit -m "Update version to ${{ steps.get_latest_tag.outputs.tag }} and commit ${{ steps.get_commit_hash.outputs.commit_hash }}" + git push origin main # Or the relevant branch diff --git a/main.go b/main.go index 088bad5..26d8a24 100644 --- a/main.go +++ b/main.go @@ -8,9 +8,6 @@ import ( "github.com/danielmiessler/fabric/cli" ) -// use to get latest tag, go install -ldflags "-X main.version=$(git describe --tags --always)" github.com/danielmiessler/fabric@latest -var version = "dev" // Default version - func main() { _, err := cli.Cli(version) if err != nil && !flags.WroteHelp(err) { diff --git a/version.go b/version.go new file mode 100644 index 0000000..81755ea --- /dev/null +++ b/version.go @@ -0,0 +1,3 @@ +package main + +var version = "dev"