Release #2
This file contains hidden or 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: Release | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| inputs: | |
| bump: | |
| description: "Semantic version bump" | |
| required: true | |
| default: patch | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| concurrency: | |
| group: release-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: write | |
| jobs: | |
| verify: | |
| name: Verify before release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: Root tests | |
| run: go test ./... | |
| - name: Root race tests | |
| run: go test -race ./... | |
| - name: Download validation module dependencies | |
| working-directory: validation/playground | |
| env: | |
| GOWORK: off | |
| run: go mod download | |
| - name: Validation submodule tests | |
| working-directory: validation/playground | |
| env: | |
| GOWORK: off | |
| run: go test ./... | |
| - name: Download REST API example dependencies | |
| working-directory: examples/restapi | |
| env: | |
| GOWORK: off | |
| run: go mod download | |
| - name: REST API example tests | |
| working-directory: examples/restapi | |
| env: | |
| GOWORK: off | |
| run: go test ./... | |
| tag-release: | |
| name: Create release tag | |
| runs-on: ubuntu-latest | |
| needs: verify | |
| if: github.event_name == 'workflow_dispatch' | |
| outputs: | |
| tag_name: ${{ steps.tag.outputs.tag_name }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Configure git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| - name: Create and push tag | |
| id: tag | |
| env: | |
| BUMP: ${{ inputs.bump }} | |
| run: | | |
| set -euo pipefail | |
| latest_tag="$(git tag --list 'v[0-9]*.[0-9]*.[0-9]*' --sort=-version:refname | head -n 1)" | |
| if [ -z "$latest_tag" ]; then | |
| latest_tag="v0.0.0" | |
| fi | |
| version="${latest_tag#v}" | |
| IFS='.' read -r major minor patch <<< "$version" | |
| if ! [[ "$major" =~ ^[0-9]+$ && "$minor" =~ ^[0-9]+$ && "$patch" =~ ^[0-9]+$ ]]; then | |
| echo "could not parse semver from '$latest_tag'" >&2 | |
| exit 1 | |
| fi | |
| case "$BUMP" in | |
| major) | |
| major=$((major + 1)) | |
| minor=0 | |
| patch=0 | |
| ;; | |
| minor) | |
| minor=$((minor + 1)) | |
| patch=0 | |
| ;; | |
| patch) | |
| patch=$((patch + 1)) | |
| ;; | |
| *) | |
| echo "unsupported bump: $BUMP" >&2 | |
| exit 1 | |
| ;; | |
| esac | |
| tag_name="v${major}.${minor}.${patch}" | |
| if git rev-parse -q --verify "refs/tags/$tag_name" >/dev/null; then | |
| echo "tag $tag_name already exists locally" >&2 | |
| exit 1 | |
| fi | |
| if git ls-remote --exit-code --tags origin "refs/tags/$tag_name" >/dev/null 2>&1; then | |
| echo "tag $tag_name already exists on origin" >&2 | |
| exit 1 | |
| fi | |
| git tag "$tag_name" | |
| git push origin "$tag_name" | |
| echo "tag_name=$tag_name" >> "$GITHUB_OUTPUT" | |
| github-release: | |
| name: Publish GitHub release | |
| runs-on: ubuntu-latest | |
| needs: | |
| - verify | |
| - tag-release | |
| if: | | |
| !failure() && !cancelled() | |
| && needs.verify.result == 'success' | |
| && (needs.tag-release.result == 'success' || needs.tag-release.result == 'skipped') | |
| && (startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch') | |
| steps: | |
| - name: Create GitHub release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ github.event_name == 'workflow_dispatch' && needs.tag-release.outputs.tag_name || github.ref_name }} | |
| generate_release_notes: true |