fix tests #30
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: CI - Build, Test & Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - 'feature/*' | |
| - 'fix/*' | |
| tags: | |
| - 'v*.*.*' # Trigger release workflow when pushing a version tag (e.g., v1.0.0) | |
| pull_request: | |
| branches: [main] | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| name: 🧪 Build & Test | |
| runs-on: ubuntu-latest | |
| services: | |
| postgres: | |
| image: postgres:16-alpine | |
| env: | |
| POSTGRES_USER: pgxport | |
| POSTGRES_PASSWORD: pgxport | |
| POSTGRES_DB: testdb | |
| ports: | |
| - 5432:5432 | |
| options: >- | |
| --health-cmd="pg_isready -U pgxport -d testdb" | |
| --health-interval=10s | |
| --health-timeout=5s | |
| --health-retries=5 | |
| env: | |
| DB_TEST_URL: postgres://pgxport:pgxport@localhost:5432/testdb?sslmode=disable | |
| steps: | |
| - name: 📥 Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: 🧰 Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| cache: true | |
| - name: 🔍 Verify Go version | |
| run: go version | |
| - name: 📦 Download dependencies | |
| run: go mod download | |
| - name: 📊 Run tests with coverage | |
| run: | | |
| echo "Waiting for PostgreSQL to be ready..." | |
| for i in {1..10}; do | |
| if pg_isready -h localhost -p 5432 -U pgxport -d testdb; then | |
| echo "PostgreSQL is ready!" | |
| break | |
| fi | |
| echo "PostgreSQL not ready yet... retrying in 3s" | |
| sleep 3 | |
| done | |
| go test -v -coverprofile=coverage.out ./... | |
| go tool cover -func=coverage.out | |
| - name: 🏗️ Build binaries | |
| run: | | |
| set -e | |
| mkdir -p build | |
| # Compute short commit hash | |
| GIT_COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") | |
| VERSION="dev-${GIT_COMMIT}" | |
| # Build Linux binary | |
| GOOS=linux GOARCH=amd64 go build -ldflags="-X main.Version=${VERSION} \ | |
| -X main.GitCommit=${GIT_COMMIT} \ | |
| -X main.BuildTime=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \ | |
| -o build/pgxport | |
| # Build Windows binary | |
| GOOS=windows GOARCH=amd64 go build -ldflags="-X main.Version=${VERSION} \ | |
| -X main.GitCommit=${GIT_COMMIT} \ | |
| -X main.BuildTime=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \ | |
| -o build/pgxport.exe | |
| - name: 📤 Upload Linux artifact | |
| if: github.ref == 'refs/heads/main' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: pgxport-linux-amd64 | |
| path: build/pgxport | |
| retention-days: 3 | |
| - name: 📤 Upload Windows artifact | |
| if: github.ref == 'refs/heads/main' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: pgxport-windows-amd64 | |
| path: build/pgxport.exe | |
| retention-days: 3 | |
| - name: 🧹 Cleanup build directory | |
| if: always() # Ensures cleanup runs even if previous step fails | |
| run: | | |
| echo "🧹 Cleaning up build artifacts..." | |
| rm -rf build | |
| echo "✅ Cleanup done." | |
| release: | |
| name: 🚀 Publish GitHub Release | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: startsWith(github.ref, 'refs/tags/') | |
| steps: | |
| - name: 📥 Checkout code | |
| uses: actions/checkout@v4 | |
| - name: 🧰 Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| - name: 🏗️ Build release binaries | |
| run: | | |
| mkdir dist | |
| GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X main.Version=${{ github.ref_name }}" -o dist/pgxport-linux-amd64 | |
| GOOS=windows GOARCH=amd64 go build -ldflags="-s -w -X main.Version=${{ github.ref_name }}" -o dist/pgxport-windows-amd64.exe | |
| GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w -X main.Version=${{ github.ref_name }}" -o dist/pgxport-macos-amd64 | |
| - name: 🧮 Generate checksums | |
| run: | | |
| cd dist | |
| for file in *; do | |
| sha256sum "$file" > "$file.sha256" | |
| done | |
| - name: 🚀 Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| name: Release ${{ github.ref_name }} | |
| files: dist/* | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |