|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + tags: ['v*'] |
| 7 | + pull_request: |
| 8 | + branches: [main] |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + packages: write |
| 13 | + attestations: write |
| 14 | + id-token: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + test: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v7 |
| 21 | + - uses: actions/setup-go@v6 |
| 22 | + with: |
| 23 | + go-version: '1.26' |
| 24 | + - run: go test -race -coverprofile=coverage.out ./... |
| 25 | + - run: go vet ./... |
| 26 | + |
| 27 | + # Build inside the official golang:1.26 image (GitHub mounts the runner's |
| 28 | + # Node into the container, so JS actions like checkout/upload-artifact work). |
| 29 | + build: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + container: golang:1.26 |
| 32 | + needs: [test] |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v7 |
| 35 | + - id: date |
| 36 | + run: echo "date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$GITHUB_OUTPUT" |
| 37 | + - name: Build (inject version metadata) |
| 38 | + env: |
| 39 | + VERSION: ${{ github.ref_name }} |
| 40 | + COMMIT: ${{ github.sha }} |
| 41 | + DATE: ${{ steps.date.outputs.date }} |
| 42 | + CGO_ENABLED: "0" |
| 43 | + run: | |
| 44 | + go build -trimpath \ |
| 45 | + -ldflags="-s -w -X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}" \ |
| 46 | + -o diskcli ./cmd/diskcli |
| 47 | +
|
| 48 | + # Cross-compile release binaries for every OS/CPU combo on tag pushes. |
| 49 | + release: |
| 50 | + if: startsWith(github.ref, 'refs/tags/v') |
| 51 | + needs: [test] |
| 52 | + runs-on: ubuntu-latest |
| 53 | + container: golang:1.26 |
| 54 | + strategy: |
| 55 | + fail-fast: false |
| 56 | + matrix: |
| 57 | + include: |
| 58 | + - { goos: linux, goarch: amd64 } |
| 59 | + - { goos: linux, goarch: arm64 } |
| 60 | + - { goos: linux, goarch: arm } |
| 61 | + - { goos: darwin, goarch: amd64 } |
| 62 | + - { goos: darwin, goarch: arm64 } |
| 63 | + - { goos: windows, goarch: amd64 } |
| 64 | + - { goos: windows, goarch: arm64 } |
| 65 | + steps: |
| 66 | + - uses: actions/checkout@v7 |
| 67 | + - id: date |
| 68 | + run: echo "date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$GITHUB_OUTPUT" |
| 69 | + - name: Build ${{ matrix.goos }}/${{ matrix.goarch }} |
| 70 | + env: |
| 71 | + GOOS: ${{ matrix.goos }} |
| 72 | + GOARCH: ${{ matrix.goarch }} |
| 73 | + VERSION: ${{ github.ref_name }} |
| 74 | + COMMIT: ${{ github.sha }} |
| 75 | + DATE: ${{ steps.date.outputs.date }} |
| 76 | + CGO_ENABLED: "0" |
| 77 | + run: | |
| 78 | + EXT="" |
| 79 | + if [ "${{ matrix.goos }}" = "windows" ]; then EXT=".exe"; fi |
| 80 | + go build -trimpath \ |
| 81 | + -ldflags="-s -w -X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}" \ |
| 82 | + -o "dist/diskcli-${GOOS}-${GOARCH}${EXT}" ./cmd/diskcli |
| 83 | + - uses: actions/upload-artifact@v7 |
| 84 | + with: |
| 85 | + name: diskcli-${{ matrix.goos }}-${{ matrix.goarch }} |
| 86 | + path: dist/diskcli-${{ matrix.goos }}-${{ matrix.goarch }}* |
| 87 | + if-no-files-found: error |
| 88 | + |
| 89 | + # Collect all binaries, generate sha256 checksums, and publish the release. |
| 90 | + publish: |
| 91 | + if: startsWith(github.ref, 'refs/tags/v') |
| 92 | + needs: [release] |
| 93 | + runs-on: ubuntu-latest |
| 94 | + steps: |
| 95 | + - uses: actions/download-artifact@v8 |
| 96 | + with: |
| 97 | + path: dist |
| 98 | + merge-multiple: true |
| 99 | + - name: Generate checksums |
| 100 | + working-directory: dist |
| 101 | + run: sha256sum * > checksums.txt |
| 102 | + - uses: softprops/action-gh-release@v3 |
| 103 | + with: |
| 104 | + files: dist/* |
| 105 | + generate_release_notes: true |
| 106 | + |
| 107 | + docker: |
| 108 | + if: startsWith(github.ref, 'refs/tags/v') |
| 109 | + needs: [build] |
| 110 | + runs-on: ubuntu-latest |
| 111 | + steps: |
| 112 | + - uses: actions/checkout@v7 |
| 113 | + - uses: docker/setup-qemu-action@v4 |
| 114 | + - uses: docker/setup-buildx-action@v4 |
| 115 | + - uses: docker/login-action@v4 |
| 116 | + with: |
| 117 | + registry: ghcr.io |
| 118 | + username: ${{ github.actor }} |
| 119 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 120 | + - uses: docker/metadata-action@v6 |
| 121 | + id: meta |
| 122 | + with: |
| 123 | + images: ghcr.io/${{ github.repository }} |
| 124 | + tags: | |
| 125 | + type=semver,pattern={{version}} |
| 126 | + type=semver,pattern={{major}}.{{minor}} |
| 127 | + type=sha,prefix= |
| 128 | + - uses: docker/build-push-action@v7 |
| 129 | + with: |
| 130 | + context: . |
| 131 | + platforms: linux/amd64,linux/arm64 |
| 132 | + push: true |
| 133 | + tags: ${{ steps.meta.outputs.tags }} |
| 134 | + labels: ${{ steps.meta.outputs.labels }} |
0 commit comments