|
| 1 | +# Auto-tag when merging to main |
| 2 | +# |
| 3 | +# Reads the version from the VERSION file and, if the matching tag does not |
| 4 | +# already exist, creates and pushes it. For a Go module the tag *is* the |
| 5 | +# release, so this is what makes `go get @latest` / pinned versions resolve. |
| 6 | +name: Tag Release |
| 7 | + |
| 8 | +on: |
| 9 | + push: |
| 10 | + branches: |
| 11 | + - main |
| 12 | + |
| 13 | +jobs: |
| 14 | + tag: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + permissions: |
| 17 | + contents: write |
| 18 | + actions: write |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + |
| 25 | + - name: Get version from VERSION file |
| 26 | + id: version |
| 27 | + run: | |
| 28 | + if [ -f VERSION ]; then |
| 29 | + VERSION=$(cat VERSION) |
| 30 | + else |
| 31 | + VERSION="0.0.0" |
| 32 | + fi |
| 33 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 34 | + echo "Version: $VERSION" |
| 35 | +
|
| 36 | + - name: Check if tag exists |
| 37 | + id: check_tag |
| 38 | + run: | |
| 39 | + if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then |
| 40 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 41 | + echo "Tag v${{ steps.version.outputs.version }} already exists" |
| 42 | + else |
| 43 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 44 | + echo "Tag v${{ steps.version.outputs.version }} does not exist" |
| 45 | + fi |
| 46 | +
|
| 47 | + - name: Create and push tag |
| 48 | + if: steps.check_tag.outputs.exists == 'false' |
| 49 | + run: | |
| 50 | + git config user.name "github-actions[bot]" |
| 51 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 52 | + git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}" |
| 53 | + git push origin "v${{ steps.version.outputs.version }}" |
| 54 | +
|
| 55 | + - name: Trigger release workflow |
| 56 | + if: steps.check_tag.outputs.exists == 'false' |
| 57 | + uses: actions/github-script@v7 |
| 58 | + with: |
| 59 | + script: | |
| 60 | + await github.rest.actions.createWorkflowDispatch({ |
| 61 | + owner: context.repo.owner, |
| 62 | + repo: context.repo.repo, |
| 63 | + workflow_id: 'release.yml', |
| 64 | + ref: 'v${{ steps.version.outputs.version }}' |
| 65 | + }) |
0 commit comments