Release v1.0.2: Automated release pipeline #1
Workflow file for this run
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*' | |
| permissions: | |
| contents: write | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.23' | |
| - name: Cache Go modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-1.23-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go-1.23- | |
| - name: Download dependencies | |
| run: go mod download | |
| - name: Verify dependencies | |
| run: go mod verify | |
| - name: Run go vet | |
| run: go vet ./... | |
| - name: Install staticcheck | |
| run: go install honnef.co/go/tools/cmd/staticcheck@latest | |
| - name: Run staticcheck | |
| run: staticcheck ./... | |
| - name: Run tests | |
| run: CGO_ENABLED=0 go test -v -coverprofile=coverage.out -covermode=atomic ./... | |
| - name: Check coverage gates | |
| run: | | |
| coverage=$(go tool cover -func=coverage.out | tail -1 | awk '{print $3}' | sed 's/%//') | |
| echo "Code coverage: ${coverage}%" | |
| if (( $(echo "$coverage < 18" | bc -l) )); then | |
| echo "::error::Coverage ${coverage}% is below 18% threshold" | |
| exit 1 | |
| fi | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.23' | |
| - name: golangci-lint | |
| uses: golangci/golangci-lint-action@v6 | |
| with: | |
| version: latest | |
| args: --timeout=5m | |
| build-and-release: | |
| runs-on: ubuntu-latest | |
| needs: [test, lint] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.23' | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Install minification dependencies | |
| run: npm install | |
| - name: Minify web assets | |
| run: ./scripts/minify.sh | |
| - name: Get version from tag | |
| id: version | |
| run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
| - name: Build for multiple platforms | |
| env: | |
| VERSION: ${{ steps.version.outputs.VERSION }} | |
| run: | | |
| # Create dist directory | |
| mkdir -p dist | |
| # Linux AMD64 | |
| echo "Building for Linux AMD64..." | |
| CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.Version=${VERSION}" -o dist/postgresql-archiver-${VERSION}-linux-amd64 | |
| # Linux ARM64 | |
| echo "Building for Linux ARM64..." | |
| CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w -X main.Version=${VERSION}" -o dist/postgresql-archiver-${VERSION}-linux-arm64 | |
| # macOS AMD64 (Intel) | |
| echo "Building for macOS AMD64..." | |
| CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -X main.Version=${VERSION}" -o dist/postgresql-archiver-${VERSION}-darwin-amd64 | |
| # macOS ARM64 (Apple Silicon) | |
| echo "Building for macOS ARM64..." | |
| CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "-s -w -X main.Version=${VERSION}" -o dist/postgresql-archiver-${VERSION}-darwin-arm64 | |
| # Windows AMD64 | |
| echo "Building for Windows AMD64..." | |
| CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -X main.Version=${VERSION}" -o dist/postgresql-archiver-${VERSION}-windows-amd64.exe | |
| - name: Create checksums | |
| working-directory: dist | |
| run: | | |
| sha256sum * > checksums.txt | |
| cat checksums.txt | |
| - name: Extract changelog entry | |
| id: changelog | |
| run: | | |
| VERSION="${{ steps.version.outputs.VERSION }}" | |
| VERSION_NO_V="${VERSION#v}" | |
| # Extract the changelog entry for this version | |
| awk "/^## \[${VERSION_NO_V}\]/,/^## \[/" CHANGELOG.md | \ | |
| sed '/^## \[/d' | \ | |
| sed -e :a -e '/^\s*$/d;N;ba' > /tmp/changelog_entry.txt | |
| # If changelog is empty, use a default message | |
| if [ ! -s /tmp/changelog_entry.txt ]; then | |
| echo "See [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/main/CHANGELOG.md) for details." > /tmp/changelog_entry.txt | |
| fi | |
| cat /tmp/changelog_entry.txt | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| name: Release ${{ steps.version.outputs.VERSION }} | |
| body_path: /tmp/changelog_entry.txt | |
| draft: false | |
| prerelease: false | |
| files: | | |
| dist/postgresql-archiver-* | |
| dist/checksums.txt | |
| fail_on_unmatched_files: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Upload artifacts for debugging | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: release-artifacts-${{ steps.version.outputs.VERSION }} | |
| path: dist/ | |
| retention-days: 30 |