ci: add GitHub Actions workflow for test, build and docker verification #1
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] | |
| paths-ignore: | |
| - "**.md" | |
| - "docs/**" | |
| - "LICENSE" | |
| pull_request: | |
| branches: [main, master] | |
| paths-ignore: | |
| - "**.md" | |
| - "docs/**" | |
| - "LICENSE" | |
| permissions: | |
| contents: read | |
| jobs: | |
| # ---- Go test matrix ---- | |
| test: | |
| name: Test (Go ${{ matrix.go-version }}) | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| go-version: ["1.24", "1.25"] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ matrix.go-version }} | |
| cache: true | |
| - name: Vet | |
| run: go vet ./... | |
| - name: Test | |
| run: go test -race -coverprofile=coverage.out -covermode=atomic ./... | |
| - name: Coverage report | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: coverage-go-${{ matrix.go-version }} | |
| path: coverage.out | |
| # ---- Binary build check ---- | |
| build: | |
| name: Build (${{ matrix.os }}) | |
| runs-on: ${{ matrix.os }} | |
| needs: test | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest, windows-latest, macos-latest] | |
| include: | |
| - os: ubuntu-latest | |
| binary: warpshift-linux-amd64 | |
| - os: windows-latest | |
| binary: warpshift-windows-amd64.exe | |
| - os: macos-latest | |
| binary: warpshift-darwin-amd64 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: "1.24" | |
| cache: true | |
| - name: Build | |
| run: | | |
| go build -trimpath -ldflags="-s -w -X main.version=ci-${GITHUB_SHA::8}" -o "${{ matrix.binary }}" ./cmd/warpshift | |
| - name: Verify binary | |
| shell: bash | |
| run: | | |
| if [ ! -f "${{ matrix.binary }}" ]; then | |
| echo "Binary not found: ${{ matrix.binary }}" | |
| exit 1 | |
| fi | |
| echo "Built: $(ls -lh ${{ matrix.binary }})" | |
| - name: Upload binary | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.binary }} | |
| path: ${{ matrix.binary }} | |
| # ---- Docker image build verification ---- | |
| docker-build: | |
| name: Docker Build | |
| runs-on: ubuntu-latest | |
| needs: test | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: false | |
| load: false | |
| build-args: | | |
| VERSION=ci-${GITHUB_SHA::8} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |