Skip to content

Commit 94b1eee

Browse files
committed
GoReleaser improvements
1 parent cb772fa commit 94b1eee

File tree

1 file changed

+43
-11
lines changed

1 file changed

+43
-11
lines changed

.github/workflows/build.yml

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
name: Build
22

3-
on: push
4-
3+
on:
4+
# Run automatically when pushing a commit or tag.
5+
push:
6+
# Support manually running the workflow.
7+
workflow_dispatch:
8+
# Configurable input properties when running manually.
9+
inputs:
10+
# Option to run go-releaser, by default publishing a (draft) release from latest tag.
11+
release:
12+
description: Run GoReleaser step
13+
type: boolean
14+
required: true
15+
default: false
16+
# Additional option, when option release is true, to run as snapshot build from
17+
# latest commit instead of latest tag and without publishing as a release.
18+
snapshot:
19+
description: GoReleaser Snapshot mode (latest commit, no publishing)
20+
type: boolean
21+
required: true
22+
default: false
523
jobs:
624
build:
725
name: Build
@@ -49,24 +67,38 @@ jobs:
4967
name: Run govulncheck
5068
run: govulncheck ./...
5169

52-
# If pushing v* tag: Clean workspace to remove remnants from the linter.
53-
# This will remove "undefined/", which avoids goreleaser failing with:
70+
# If pushing v* tag, or manual run with option release: Clean workspace to remove remnants from the linter.
71+
# This will remove "undefined/", which avoids go-release failing with:
5472
# git is currently in a dirty state
5573
# Please check in your pipeline what can be changing the following files:
5674
# ?? undefined/
5775
- id: clean
58-
name: Prepare go release (if pushing v-tag)
59-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
76+
name: Prepare go release (if pushing v-tag or triggered manually)
77+
if: github.event.inputs.release == 'true' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v'))
6078
run: git clean -xdf
6179

62-
# If pushing v* tag: Build and create release.
63-
- id: go-release
64-
name: Run go release (if pushing v-tag)
80+
# If pushing v* tag, or manual run with option "release" but not "snapshot": Build and create release from latest tag.
81+
# Note: If manual run it must be on the tag (same commit), or else go-releaser will fail with: "git tag <tag_name> was not made against commit <commit_hash>",
82+
# and one must consider using the snapshot mode instead (see below).
83+
- id: go-release-tag
84+
name: Run go release tag (if pushing v-tag or triggered manually)
85+
uses: goreleaser/goreleaser-action@v4
86+
if: (github.event.inputs.release == 'true' && github.event.inputs.snapshot != 'true') || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v'))
87+
with:
88+
version: latest
89+
args: release --clean
90+
env:
91+
GOVERSION: ${{ steps.go-setup.outputs.go-version }}
92+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93+
94+
# If manual run with options "release" and "snapshot": Build latest commit without publishing a release.
95+
- id: go-release-snapshot
96+
name: Run go release snapshot (if triggered manually)
6597
uses: goreleaser/goreleaser-action@v4
66-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
98+
if: github.event.inputs.release == 'true' && github.event.inputs.snapshot == 'true'
6799
with:
68100
version: latest
69-
args: release --rm-dist
101+
args: release --clean --snapshot
70102
env:
71103
GOVERSION: ${{ steps.go-setup.outputs.go-version }}
72104
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)