publish #3
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: publish | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| bump: | |
| description: SemVer increment when version is omitted | |
| required: true | |
| default: patch | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| version: | |
| description: Explicit version (without v), e.g. 1.2.3 | |
| required: false | |
| type: string | |
| permissions: | |
| contents: write | |
| concurrency: | |
| group: publish-${{ github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| prepare-version: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| tag: ${{ steps.compute.outputs.tag }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Compute next tag | |
| id: compute | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| git fetch --tags --force | |
| explicit="${{ inputs.version }}" | |
| bump="${{ inputs.bump }}" | |
| if [[ -n "$explicit" ]]; then | |
| if [[ ! "$explicit" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "Invalid version '$explicit'. Expected format: 1.2.3" | |
| exit 1 | |
| fi | |
| next="$explicit" | |
| else | |
| latest="$(git tag -l 'v*' --sort=-v:refname | head -n 1)" | |
| if [[ -z "$latest" ]]; then | |
| latest="v0.0.0" | |
| fi | |
| current="${latest#v}" | |
| IFS='.' read -r major minor patch <<< "$current" | |
| case "$bump" in | |
| major) | |
| major=$((major + 1)) | |
| minor=0 | |
| patch=0 | |
| ;; | |
| minor) | |
| minor=$((minor + 1)) | |
| patch=0 | |
| ;; | |
| patch) | |
| patch=$((patch + 1)) | |
| ;; | |
| *) | |
| echo "Unsupported bump type '$bump'" | |
| exit 1 | |
| ;; | |
| esac | |
| next="${major}.${minor}.${patch}" | |
| fi | |
| tag="v${next}" | |
| if git rev-parse "$tag" >/dev/null 2>&1; then | |
| echo "Tag '$tag' already exists" | |
| exit 1 | |
| fi | |
| if git ls-remote --exit-code --tags origin "refs/tags/${tag}" >/dev/null 2>&1; then | |
| echo "Tag '$tag' already exists on remote" | |
| exit 1 | |
| fi | |
| echo "tag=${tag}" >> "$GITHUB_OUTPUT" | |
| release: | |
| runs-on: ubuntu-latest | |
| needs: prepare-version | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| - name: Build release binaries | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| mkdir -p dist | |
| targets=( | |
| "darwin amd64" | |
| "darwin arm64" | |
| "linux amd64" | |
| "linux arm64" | |
| ) | |
| for target in "${targets[@]}"; do | |
| read -r goos goarch <<< "$target" | |
| bin="devwrap_${goos}_${goarch}" | |
| GOOS="$goos" GOARCH="$goarch" CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o "dist/${bin}" ./cmd/devwrap | |
| tar -czf "dist/${bin}.tar.gz" -C dist "$bin" | |
| rm "dist/${bin}" | |
| done | |
| ( | |
| cd dist | |
| shasum -a 256 *.tar.gz > checksums.txt | |
| ) | |
| - name: Create and push tag | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| tag="${{ needs.prepare-version.outputs.tag }}" | |
| git tag "$tag" | |
| git push origin "$tag" | |
| - name: Create GitHub release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ needs.prepare-version.outputs.tag }} | |
| name: ${{ needs.prepare-version.outputs.tag }} | |
| generate_release_notes: true | |
| files: | | |
| dist/*.tar.gz | |
| dist/checksums.txt |