feat(cli): redesign connection flags and free -d for --database #92
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/*' | |
| - 'release/*' | |
| tags: | |
| - 'v*' | |
| 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 version info | |
| GIT_COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") | |
| VERSION="dev-${GIT_COMMIT}" | |
| BUILD_TIME=$(date -u +'%Y-%m-%dT%H:%M:%SZ') | |
| MODULE="github.com/fbz-tec/pgxport" | |
| # ldflags for internal/version package | |
| LDFLAGS="-X ${MODULE}/internal/version.AppVersion=${VERSION} \ | |
| -X ${MODULE}/internal/version.GitCommit=${GIT_COMMIT} \ | |
| -X ${MODULE}/internal/version.BuildTime=${BUILD_TIME}" | |
| echo "Building with version: ${VERSION}" | |
| # Build Linux binary | |
| CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o build/pgxport | |
| # Build Windows binary | |
| GOOS=windows GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o build/pgxport.exe | |
| - name: 📤 Upload Linux artifact | |
| if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/') | |
| 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' || startsWith(github.ref, 'refs/heads/release/') | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: pgxport-windows-amd64 | |
| path: build/pgxport.exe | |
| retention-days: 3 | |
| - name: 🧹 Cleanup build directory | |
| if: always() | |
| 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/') | |
| permissions: | |
| contents: write | |
| 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 | |
| VERSION="${{ github.ref_name }}" | |
| BUILD_TIME=$(date -u +'%Y-%m-%dT%H:%M:%SZ') | |
| GIT_COMMIT=$(git rev-parse --short HEAD) | |
| MODULE="github.com/fbz-tec/pgxport" | |
| LDFLAGS="-s -w \ | |
| -X ${MODULE}/internal/version.AppVersion=${VERSION} \ | |
| -X ${MODULE}/internal/version.BuildTime=${BUILD_TIME} \ | |
| -X ${MODULE}/internal/version.GitCommit=${GIT_COMMIT}" | |
| echo "Building binaries for version ${VERSION}..." | |
| # Linux AMD64 | |
| CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o dist/pgxport-linux-amd64 | |
| # Linux ARM64 | |
| CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="${LDFLAGS}" -o dist/pgxport-linux-arm64 | |
| # macOS AMD64 (Intel) | |
| GOOS=darwin GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o dist/pgxport-darwin-amd64 | |
| # macOS ARM64 (Apple Silicon) | |
| GOOS=darwin GOARCH=arm64 go build -ldflags="${LDFLAGS}" -o dist/pgxport-darwin-arm64 | |
| # Windows AMD64 | |
| GOOS=windows GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o dist/pgxport-windows-amd64.exe | |
| # Windows ARM64 | |
| GOOS=windows GOARCH=arm64 go build -ldflags="${LDFLAGS}" -o dist/pgxport-windows-arm64.exe | |
| echo "✅ All binaries built successfully" | |
| - name: 📦 Create platform-specific archives with documentation | |
| run: | | |
| # Prepare files to include in all archives | |
| cp CHANGELOG.md dist/ 2>/dev/null || echo "⚠️ CHANGELOG.md not found" | |
| cp README.md dist/ 2>/dev/null || echo "⚠️ README.md not found" | |
| cp LICENSE dist/ 2>/dev/null || echo "⚠️ LICENSE not found" | |
| cd dist | |
| echo "📦 Creating platform-specific archives..." | |
| # Linux AMD64 - tar.gz | |
| tar -czf pgxport-linux-amd64.tar.gz pgxport-linux-amd64 CHANGELOG.md README.md LICENSE | |
| rm pgxport-linux-amd64 | |
| # Linux ARM64 - tar.gz | |
| tar -czf pgxport-linux-arm64.tar.gz pgxport-linux-arm64 CHANGELOG.md README.md LICENSE | |
| rm pgxport-linux-arm64 | |
| # macOS AMD64 - tar.gz | |
| tar -czf pgxport-darwin-amd64.tar.gz pgxport-darwin-amd64 CHANGELOG.md README.md LICENSE | |
| rm pgxport-darwin-amd64 | |
| # macOS ARM64 - tar.gz | |
| tar -czf pgxport-darwin-arm64.tar.gz pgxport-darwin-arm64 CHANGELOG.md README.md LICENSE | |
| rm pgxport-darwin-arm64 | |
| # Windows AMD64 - zip | |
| zip -j pgxport-windows-amd64.zip pgxport-windows-amd64.exe CHANGELOG.md README.md LICENSE | |
| rm pgxport-windows-amd64.exe | |
| # Windows ARM64 - zip | |
| zip -j pgxport-windows-arm64.zip pgxport-windows-arm64.exe CHANGELOG.md README.md LICENSE | |
| rm pgxport-windows-arm64.exe | |
| # Cleanup docs | |
| rm -f CHANGELOG.md README.md LICENSE | |
| echo "" | |
| echo "✅ Archives created:" | |
| ls -lh *.tar.gz *.zip | |
| - name: 🧮 Generate checksums | |
| run: | | |
| cd dist | |
| sha256sum *.tar.gz *.zip > checksums.txt | |
| echo "" | |
| echo "✅ Checksums generated:" | |
| cat checksums.txt | |
| - name: 🚀 Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| name: Release ${{ github.ref_name }} | |
| prerelease: ${{ contains(github.ref_name, '-rc') || contains(github.ref_name, '-beta') || contains(github.ref_name, '-alpha') }} | |
| body: | | |
| ## 📦 Downloads | |
| ### Binary Releases | |
| | Platform | Architecture | Download | | |
| |----------|-------------|----------| | |
| | Linux | x86_64 (AMD64) | `pgxport-linux-amd64.tar.gz` | | |
| | Linux | ARM64 | `pgxport-linux-arm64.tar.gz` | | |
| | macOS | Intel (AMD64) | `pgxport-darwin-amd64.tar.gz` | | |
| | macOS | Apple Silicon (ARM64) | `pgxport-darwin-arm64.tar.gz` | | |
| | Windows | x86_64 (AMD64) | `pgxport-windows-amd64.zip` | | |
| | Windows | ARM64 | `pgxport-windows-arm64.zip` | | |
| Each archive contains: binary + CHANGELOG + README + LICENSE | |
| ## 📚 Documentation | |
| - **Installation & Usage**: See [README.md](https://github.com/fbz-tec/pgxport#readme) | |
| - **What's New**: See [CHANGELOG.md](https://github.com/fbz-tec/pgxport/blob/${{ github.ref_name }}/CHANGELOG.md) | |
| - **Verify downloads**: Check `checksums.txt` (SHA256) | |
| files: | | |
| dist/*.tar.gz | |
| dist/*.zip | |
| dist/checksums.txt | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |