Update GitHub Actions workflow to use actions/upload-artifact@v4 for … #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: Test and Build | |
| on: | |
| push: | |
| branches: [ main, master ] | |
| pull_request: | |
| branches: [ main, master ] | |
| jobs: | |
| test: | |
| name: Test | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| go-version: [1.21, 1.22, '1.23'] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Go ${{ matrix.go-version }} | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: ${{ matrix.go-version }} | |
| - name: Download dependencies | |
| run: go mod download | |
| - name: Verify dependencies | |
| run: go mod verify | |
| - name: Run tests | |
| run: go test -v -race -coverprofile=coverage.out ./... | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| file: ./coverage.out | |
| flags: unittests | |
| name: codecov-umbrella | |
| fail_ci_if_error: false | |
| build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| needs: test | |
| strategy: | |
| matrix: | |
| go-version: [1.21] | |
| os: [ubuntu-latest, windows-latest, macos-latest] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Go ${{ matrix.go-version }} | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: ${{ matrix.go-version }} | |
| - name: Download dependencies | |
| run: go mod download | |
| - name: Build package | |
| run: go build -v ./... | |
| - name: Build example | |
| run: go build -v -o example-bin ./example | |
| - name: Test build artifacts | |
| run: | | |
| if [ "$RUNNER_OS" = "Windows" ]; then | |
| go build -o capture-go.exe . | |
| ./capture-go.exe --help 2>/dev/null || echo "Build successful" | |
| else | |
| go build -o capture-go . | |
| ./capture-go --help 2>/dev/null || echo "Build successful" | |
| fi | |
| build-cross-platform: | |
| name: Cross-platform Build | |
| runs-on: ubuntu-latest | |
| needs: test | |
| if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: '1.21' | |
| - name: Download dependencies | |
| run: go mod download | |
| - name: Build for multiple platforms | |
| run: | | |
| mkdir -p dist | |
| GOOS=linux GOARCH=amd64 go build -o dist/capture-go-linux-amd64 . | |
| GOOS=linux GOARCH=arm64 go build -o dist/capture-go-linux-arm64 . | |
| GOOS=darwin GOARCH=amd64 go build -o dist/capture-go-darwin-amd64 . | |
| GOOS=darwin GOARCH=arm64 go build -o dist/capture-go-darwin-arm64 . | |
| GOOS=windows GOARCH=amd64 go build -o dist/capture-go-windows-amd64.exe . | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: capture-go-binaries | |
| path: dist/ | |
| retention-days: 30 |