feat: add version updater bot

This commit is contained in:
Eugen Eisler 2024-09-29 21:35:20 +02:00
parent 913210d2a9
commit 3a7e1cf527
3 changed files with 50 additions and 3 deletions

47
.github/workflows/update-version.yml vendored Normal file
View File

@ -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

View File

@ -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) {

3
version.go Normal file
View File

@ -0,0 +1,3 @@
package main
var version = "dev"