Update ci.yml #13
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 | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - master | |
| tags: | |
| - '*' # also run on any tag push (e.g. v1.0.0) | |
| pull_request: | |
| branches: | |
| - main | |
| - master | |
| jobs: | |
| test: | |
| name: Run Go tests | |
| runs-on: ubuntu-latest | |
| services: | |
| postgres: | |
| image: postgres:15 | |
| env: | |
| POSTGRES_USER: postgres | |
| POSTGRES_PASSWORD: postgres | |
| POSTGRES_DB: postgres | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| ports: | |
| - 5432:5432 | |
| env: | |
| POSTGRES_HOST: localhost | |
| POSTGRES_PORT: 5432 | |
| POSTGRES_USER: postgres | |
| PGPASSWORD: postgres | |
| PGROLLBACK_CONFIG: config/pgrollback.yaml | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.23' | |
| cache: true | |
| - name: Print Go version | |
| run: go version | |
| - name: Install systray dependency (Linux) | |
| run: sudo apt-get update -y && sudo apt-get install -y libayatana-appindicator3-dev | |
| - name: Create config file for CI | |
| run: | | |
| mkdir -p config | |
| cat > config/pgrollback.yaml << 'EOF' | |
| postgres: | |
| host: localhost | |
| port: 5432 | |
| database: postgres | |
| user: postgres | |
| password: postgres | |
| session_timeout: 900s | |
| proxy: | |
| listen_host: localhost | |
| listen_port: 5433 | |
| timeout: 60s | |
| keepalive_interval: 300s | |
| logging: | |
| level: info | |
| file: "" | |
| test: | |
| schema: public | |
| context_timeout: 10s | |
| query_timeout: 5s | |
| ping_timeout: 3s | |
| EOF | |
| - name: Run unit tests | |
| run: go test ./... | |
| build-windows: | |
| name: Build pgrollback (Windows) | |
| runs-on: windows-latest | |
| needs: test | |
| if: startsWith(github.ref, 'refs/tags/') # only build when the commit is a tag | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.23' | |
| cache: true | |
| - name: Build pgrollback | |
| run: go build -o bin/pgrollback.exe ./cmd/pgrollback | |
| - name: Upload binary artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: pgrollback-windows-amd64 | |
| path: bin/pgrollback.exe | |
| build-windows-cross: | |
| name: Build pgrollback (Windows cross-compile on Linux) | |
| runs-on: ubuntu-latest | |
| needs: test | |
| if: startsWith(github.ref, 'refs/tags/') | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install mingw-w64 (Windows cross-compiler) | |
| run: sudo apt-get update -y && sudo apt-get install -y gcc-mingw-w64 | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.23' | |
| cache: true | |
| - name: Install systray dependency (Linux) | |
| run: sudo apt-get update -y && sudo apt-get install -y libayatana-appindicator3-dev | |
| - name: Build pgrollback.exe (cross, CGO) | |
| env: | |
| CGO_ENABLED: 1 | |
| GOOS: windows | |
| GOARCH: amd64 | |
| CC: x86_64-w64-mingw32-gcc | |
| run: | | |
| mkdir -p bin | |
| go build -o bin/pgrollback.exe ./cmd/pgrollback | |
| - name: Upload binary artifact (cross) | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: pgrollback-windows-amd64-cross | |
| path: bin/pgrollback.exe | |
| build: | |
| name: Build pgrollback binary | |
| runs-on: ubuntu-latest | |
| needs: test | |
| if: startsWith(github.ref, 'refs/tags/') # only build when the commit is a tag | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.23' | |
| cache: true | |
| - name: Install systray dependency (Linux) | |
| run: sudo apt-get update -y && sudo apt-get install -y libayatana-appindicator3-dev | |
| - name: Build pgrollback | |
| run: go build -o bin/pgrollback ./cmd/pgrollback | |
| - name: Upload binary artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: pgrollback-linux-amd64 | |
| path: bin/pgrollback | |
| release: | |
| name: Create Release and upload binaries | |
| runs-on: ubuntu-latest | |
| needs: [build, build-windows] | |
| if: startsWith(github.ref, 'refs/tags/') | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Download Linux binary | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: pgrollback-linux-amd64 | |
| - name: Download Windows binary | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: pgrollback-windows-amd64 | |
| - name: Rename binaries with tag and OS | |
| run: | | |
| TAG="${GITHUB_REF#refs/tags/}" | |
| mkdir -p release | |
| # Artifact may be at root or under bin/ depending on upload-artifact behavior | |
| mv "bin/pgrollback" "release/pgrollback-${TAG}-linux-amd64" | |
| mv "bin/pgrollback.exe" "release/pgrollback-${TAG}-windows-amd64.exe" | |
| ls -la release/ | |
| - name: Create Release and upload assets | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: release/* | |
| generate_release_notes: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |