|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + snapshot: |
| 7 | + description: "Build a snapshot instead of publishing a release" |
| 8 | + required: false |
| 9 | + default: "false" |
| 10 | + version: |
| 11 | + description: "Version to publish from VERSION" |
| 12 | + required: false |
| 13 | + default: "" |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: write |
| 17 | + packages: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + release: |
| 21 | + name: GoReleaser |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + - uses: actions/setup-go@v5 |
| 28 | + with: |
| 29 | + go-version-file: go.mod |
| 30 | + cache: true |
| 31 | + - name: Load version |
| 32 | + shell: bash |
| 33 | + run: echo "VERSION=$(tr -d '\r\n' < VERSION)" >> "$GITHUB_ENV" |
| 34 | + - name: Verify version override |
| 35 | + shell: bash |
| 36 | + run: | |
| 37 | + if [ -n "${{ inputs.version }}" ] && [ "${{ inputs.version }}" != "$VERSION" ]; then |
| 38 | + echo "VERSION file does not match the requested release version." >&2 |
| 39 | + exit 1 |
| 40 | + fi |
| 41 | + - name: Create release tag |
| 42 | + if: ${{ inputs.snapshot != 'true' }} |
| 43 | + shell: bash |
| 44 | + run: | |
| 45 | + git config user.name "github-actions[bot]" |
| 46 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 47 | + TAG="v${VERSION}" |
| 48 | + if git rev-parse -q --verify "refs/tags/${TAG}" >/dev/null; then |
| 49 | + echo "Tag ${TAG} already exists." >&2 |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | + git tag -a "${TAG}" -m "Release ${TAG}" |
| 53 | + git push origin "${TAG}" |
| 54 | + - name: Run GoReleaser snapshot |
| 55 | + if: ${{ inputs.snapshot == 'true' }} |
| 56 | + uses: goreleaser/goreleaser-action@v6 |
| 57 | + with: |
| 58 | + distribution: goreleaser |
| 59 | + version: latest |
| 60 | + args: release --snapshot --clean |
| 61 | + env: |
| 62 | + VERSION: ${{ env.VERSION }} |
| 63 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 64 | + - name: Run GoReleaser release |
| 65 | + if: ${{ inputs.snapshot != 'true' }} |
| 66 | + uses: goreleaser/goreleaser-action@v6 |
| 67 | + with: |
| 68 | + distribution: goreleaser |
| 69 | + version: latest |
| 70 | + args: release --clean |
| 71 | + env: |
| 72 | + VERSION: ${{ env.VERSION }} |
| 73 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments