|
8 | 8 | paths: |
9 | 9 | - 'pkg/**' |
10 | 10 | - '.github/workflows/**' |
| 11 | + tags: |
| 12 | + - 'v*' |
11 | 13 | workflow_dispatch: |
12 | 14 |
|
13 | 15 | # Only runs on push to main — not on PRs. |
14 | 16 | # The pkg/ submodule lives in a private repo (entlein/bob) and requires |
15 | 17 | # PRIVATE_REPO_PAT to clone. This secret must never be exposed to fork PRs. |
16 | 18 |
|
| 19 | +permissions: |
| 20 | + contents: write |
| 21 | + |
17 | 22 | jobs: |
18 | 23 | build: |
19 | | - name: Build & vet |
| 24 | + name: Build (${{ matrix.goos }}/${{ matrix.goarch }}) |
20 | 25 | runs-on: ubuntu-latest |
| 26 | + strategy: |
| 27 | + matrix: |
| 28 | + include: |
| 29 | + - goos: linux |
| 30 | + goarch: amd64 |
| 31 | + - goos: linux |
| 32 | + goarch: arm64 |
21 | 33 | steps: |
22 | 34 | - name: Checkout repo and private submodules |
23 | 35 | uses: actions/checkout@v4 |
@@ -47,11 +59,113 @@ jobs: |
47 | 59 | working-directory: pkg |
48 | 60 | run: go vet ./... |
49 | 61 |
|
| 62 | + - name: Determine version |
| 63 | + id: version |
| 64 | + run: | |
| 65 | + if [[ "${{ github.ref }}" == refs/tags/v* ]]; then |
| 66 | + echo "version=${GITHUB_REF#refs/tags/v}" >> "$GITHUB_OUTPUT" |
| 67 | + echo "tag=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT" |
| 68 | + else |
| 69 | + SHORT_SHA=$(git rev-parse --short HEAD) |
| 70 | + echo "version=0.1.0-dev+${SHORT_SHA}" >> "$GITHUB_OUTPUT" |
| 71 | + echo "tag=latest" >> "$GITHUB_OUTPUT" |
| 72 | + fi |
| 73 | +
|
50 | 74 | - name: Build bobctl |
51 | 75 | working-directory: pkg |
52 | | - run: go build -o ../bin/bobctl ./main.go |
| 76 | + env: |
| 77 | + CGO_ENABLED: '0' |
| 78 | + GOOS: ${{ matrix.goos }} |
| 79 | + GOARCH: ${{ matrix.goarch }} |
| 80 | + run: | |
| 81 | + go build -trimpath \ |
| 82 | + -ldflags="-s -w -X main.version=${{ steps.version.outputs.version }}" \ |
| 83 | + -o ../bin/bobctl-${{ matrix.goos }}-${{ matrix.goarch }} \ |
| 84 | + ./main.go |
| 85 | +
|
| 86 | + - name: Verify binary (native only) |
| 87 | + if: matrix.goarch == 'amd64' |
| 88 | + run: | |
| 89 | + bin/bobctl-${{ matrix.goos }}-${{ matrix.goarch }} --help |
| 90 | + bin/bobctl-${{ matrix.goos }}-${{ matrix.goarch }} autotune --help |
| 91 | +
|
| 92 | + - name: Upload artifact |
| 93 | + uses: actions/upload-artifact@v4 |
| 94 | + with: |
| 95 | + name: bobctl-${{ matrix.goos }}-${{ matrix.goarch }} |
| 96 | + path: bin/bobctl-${{ matrix.goos }}-${{ matrix.goarch }} |
| 97 | + |
| 98 | + release: |
| 99 | + name: Publish release |
| 100 | + needs: build |
| 101 | + runs-on: ubuntu-latest |
| 102 | + steps: |
| 103 | + - name: Download all artifacts |
| 104 | + uses: actions/download-artifact@v4 |
| 105 | + with: |
| 106 | + path: artifacts |
| 107 | + |
| 108 | + - name: Prepare release assets |
| 109 | + run: | |
| 110 | + mkdir -p release |
| 111 | + for dir in artifacts/bobctl-*; do |
| 112 | + name=$(basename "$dir") |
| 113 | + cp "$dir/$name" "release/$name" |
| 114 | + chmod +x "release/$name" |
| 115 | + done |
| 116 | + ls -lh release/ |
53 | 117 |
|
54 | | - - name: Verify help output |
| 118 | + - name: Determine release tag |
| 119 | + id: tag |
55 | 120 | run: | |
56 | | - bin/bobctl --help |
57 | | - bin/bobctl autotune --help |
| 121 | + if [[ "${{ github.ref }}" == refs/tags/v* ]]; then |
| 122 | + echo "tag=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT" |
| 123 | + echo "prerelease=false" >> "$GITHUB_OUTPUT" |
| 124 | + echo "title=bobctl ${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT" |
| 125 | + else |
| 126 | + echo "tag=latest" >> "$GITHUB_OUTPUT" |
| 127 | + echo "prerelease=true" >> "$GITHUB_OUTPUT" |
| 128 | + echo "title=bobctl latest ($(date -u +%Y-%m-%d))" >> "$GITHUB_OUTPUT" |
| 129 | + fi |
| 130 | +
|
| 131 | + - name: Delete existing latest release |
| 132 | + if: steps.tag.outputs.tag == 'latest' |
| 133 | + env: |
| 134 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 135 | + run: | |
| 136 | + gh release delete latest --repo "${{ github.repository }}" --yes 2>/dev/null || true |
| 137 | + git push --delete origin latest 2>/dev/null || true |
| 138 | +
|
| 139 | + - name: Create release |
| 140 | + env: |
| 141 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 142 | + run: | |
| 143 | + gh release create "${{ steps.tag.outputs.tag }}" \ |
| 144 | + --repo "${{ github.repository }}" \ |
| 145 | + --title "${{ steps.tag.outputs.title }}" \ |
| 146 | + --prerelease=${{ steps.tag.outputs.prerelease }} \ |
| 147 | + --notes "$(cat <<'EOF' |
| 148 | + ## Download |
| 149 | +
|
| 150 | + | Platform | Architecture | Binary | |
| 151 | + |----------|-------------|--------| |
| 152 | + | Linux | amd64 | `bobctl-linux-amd64` | |
| 153 | + | Linux | arm64 | `bobctl-linux-arm64` | |
| 154 | +
|
| 155 | + ### Quick install |
| 156 | +
|
| 157 | + ```bash |
| 158 | + # Linux amd64 |
| 159 | + curl -fsSL -o bobctl \ |
| 160 | + https://github.com/${{ github.repository }}/releases/download/${{ steps.tag.outputs.tag }}/bobctl-linux-amd64 |
| 161 | + chmod +x bobctl |
| 162 | +
|
| 163 | + # Linux arm64 |
| 164 | + curl -fsSL -o bobctl \ |
| 165 | + https://github.com/${{ github.repository }}/releases/download/${{ steps.tag.outputs.tag }}/bobctl-linux-arm64 |
| 166 | + chmod +x bobctl |
| 167 | + ``` |
| 168 | + EOF |
| 169 | + )" \ |
| 170 | + --target "${{ github.sha }}" \ |
| 171 | + release/bobctl-* |
0 commit comments