Merge pull request #82 from sudo-bmitch/pr-update-20241009 #172
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Go | |
on: | |
push: | |
branches: | |
- 'main' | |
- 'feature/**' | |
tags: | |
- 'v*.*.*' | |
pull_request: | |
branches: [ main ] | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
gover: ["1.21", "1.22", "1.23"] | |
env: | |
RELEASE_GO_VER: "1.23" | |
steps: | |
- name: "Set up Go ${{ matrix.gover }}" | |
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2 | |
with: | |
go-version: "${{ matrix.gover }}" | |
check-latest: true | |
id: go | |
- name: Check out code | |
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 | |
- name: Get dependencies | |
run: | | |
go get -v -t -d ./... | |
- name: Verify go fmt | |
run: test -z "$(go fmt ./...)" | |
- name: Verify go vet | |
run: test -z "$(go vet ./...)" | |
- name: Test | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_RO_TOKEN }} | |
run: make test | |
- name: Linting | |
if: matrix.gover == env.RELEASE_GO_VER | |
run: make lint | |
- name: Build artifacts | |
if: startsWith( github.ref, 'refs/tags/v' ) || github.ref == 'refs/heads/main' | |
run: make artifacts | |
- name: Gather release details | |
if: startsWith( github.ref, 'refs/tags/v' ) && github.repository_owner == 'sudo-bmitch' && matrix.gover == env.RELEASE_GO_VER | |
id: release_details | |
run: | | |
VERSION=${GITHUB_REF#refs/tags/} | |
VALID_RELEASE=false | |
if [ -f "release.md" ] && grep -q "Release $VERSION" release.md; then | |
VALID_RELEASE=true | |
fi | |
RELEASE_NOTES=$(cat release.md || echo release notes unavailable) | |
# escape % and linefeeds | |
RELEASE_NOTES="${RELEASE_NOTES//'%'/'%25'}" | |
RELEASE_NOTES="${RELEASE_NOTES//$'\n'/'%0A'}" | |
RELEASE_NOTES="${RELEASE_NOTES//$'\r'/'%0D'}" | |
echo "valid=${VALID_RELEASE}" >>$GITHUB_OUTPUT | |
echo "version=${VERSION}" >>$GITHUB_OUTPUT | |
echo "release_notes=${RELEASE_NOTES}" >>$GITHUB_OUTPUT | |
- name: Create release | |
if: steps.release_details.outputs.valid == 'true' && matrix.gover == env.RELEASE_GO_VER | |
id: release_create | |
uses: softprops/action-gh-release@c062e08bd532815e2082a85e87e3ef29c3e6d191 # v2.0.8 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.release_details.outputs.version }} | |
body: ${{ steps.release_details.outputs.release_notes }} | |
draft: false | |
prerelease: false | |
files: | | |
./artifacts/version-bump-darwin-amd64 | |
./artifacts/version-bump-linux-amd64 | |
./artifacts/version-bump-linux-arm64 | |
./artifacts/version-bump-linux-ppc64le | |
./artifacts/version-bump-linux-s390x | |
./artifacts/version-bump-windows-amd64.exe | |
- name: Save artifacts | |
if: github.ref == 'refs/heads/main' && matrix.gover == env.RELEASE_GO_VER | |
uses: actions/upload-artifact@84480863f228bb9747b473957fcc9e309aa96097 # v4.4.2 | |
with: | |
name: binaries | |
path: ./artifacts/ | |
retention-days: 7 |