-
Notifications
You must be signed in to change notification settings - Fork 31
Create workflow to automate future releases #133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| name: Release | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| version: | ||
| description: "Version to release, without the leading v (e.g. 2.3.0). Must match Version in secretcache/versionInfo.go." | ||
| required: true | ||
| type: string | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| jobs: | ||
| release: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For our release workflows we tie GitHub actions we use to a SHA hash. This is to prevent supply chain attacks. |
||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v6 | ||
| with: | ||
| go-version: "1.24" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might want to go with "stable". Or follow the other comment and reuse the build workflow. |
||
|
|
||
| - name: Check version matches versionInfo.go | ||
| run: | | ||
| input="${{ github.event.inputs.version }}" | ||
| if ! echo "$input" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then | ||
| echo "::error::Version '$input' is not strict semver (expected x.y.z)." | ||
| exit 1 | ||
| fi | ||
| repo=$(grep -oE 'Version = "[^"]+"' secretcache/versionInfo.go \ | ||
| | grep -oE '[0-9]+\.[0-9]+\.[0-9]+') | ||
| echo "Requested version: $input" | ||
| echo "versionInfo.go version: $repo" | ||
| if [ "$input" != "$repo" ]; then | ||
| echo "::error::Requested version ($input) does not match Version in secretcache/versionInfo.go ($repo)." | ||
| exit 1 | ||
| fi | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Consider adding a check to make sure the requested new version is correct with respect to the previously released version. e.g. v3.1.0 -> v3.1.1 is fine, but v3.1.0 -> v3.2.1 is not.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would the latter example you provided not be ok? |
||
| - name: Check tag does not already exist | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just attempt the push? It will fail if the tag already exists. |
||
| run: | | ||
| tag="v${{ github.event.inputs.version }}" | ||
| if git ls-remote --exit-code --tags origin "refs/tags/$tag" >/dev/null 2>&1; then | ||
| echo "::error::Tag $tag already exists. Releases are immutable; bump the version to release again." | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Build | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can reuse existing workflows using |
||
| run: go build -v ./... | ||
|
|
||
| - name: Test | ||
| run: go test -v ./secretcache | ||
|
|
||
| - name: Tag and create GitHub Release | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| tag="v${{ github.event.inputs.version }}" | ||
| gh release create "$tag" \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a matching git tag does not yet exist, one will automatically get created from the latest state of the default branch. Use --target to point to a different branch or commit for the automatic tag creation. Use --verify-tag to abort the release if the tag doesn't already exist. |
||
| --title "$tag" \ | ||
| --generate-notes | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gate this workflow on an environment so we can restrict this to running under a 2PR.