|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*.*.*" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + packages: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + build-cli: |
| 14 | + name: Build CLI (${{ matrix.target }}) |
| 15 | + runs-on: ${{ matrix.os }} |
| 16 | + strategy: |
| 17 | + fail-fast: false |
| 18 | + matrix: |
| 19 | + include: |
| 20 | + - os: ubuntu-latest |
| 21 | + target: x86_64-unknown-linux-gnu |
| 22 | + cross: false |
| 23 | + - os: ubuntu-latest |
| 24 | + target: aarch64-unknown-linux-gnu |
| 25 | + cross: true |
| 26 | + - os: macos-15-intel |
| 27 | + target: x86_64-apple-darwin |
| 28 | + cross: false |
| 29 | + - os: macos-14 |
| 30 | + target: aarch64-apple-darwin |
| 31 | + cross: false |
| 32 | + |
| 33 | + steps: |
| 34 | + - name: Checkout |
| 35 | + uses: actions/checkout@v6 |
| 36 | + |
| 37 | + - name: Check crate version matches tag |
| 38 | + shell: bash |
| 39 | + run: | |
| 40 | + set -euo pipefail |
| 41 | + crate_version="$(awk -F'"' '/^version = / { print $2; exit }' codex-blackbox-cli/Cargo.toml)" |
| 42 | + test "v${crate_version}" = "$GITHUB_REF_NAME" |
| 43 | +
|
| 44 | + - name: Install Rust |
| 45 | + uses: dtolnay/rust-toolchain@stable |
| 46 | + with: |
| 47 | + targets: ${{ matrix.target }} |
| 48 | + |
| 49 | + - name: Install cross |
| 50 | + if: matrix.cross |
| 51 | + run: cargo install cross --locked |
| 52 | + |
| 53 | + - name: Build |
| 54 | + shell: bash |
| 55 | + run: | |
| 56 | + set -euo pipefail |
| 57 | + if [[ "${{ matrix.cross }}" == "true" ]]; then |
| 58 | + cross build --release -p codex-blackbox-cli --target "${{ matrix.target }}" |
| 59 | + else |
| 60 | + cargo build --release -p codex-blackbox-cli --target "${{ matrix.target }}" |
| 61 | + fi |
| 62 | +
|
| 63 | + - name: Package |
| 64 | + shell: bash |
| 65 | + run: | |
| 66 | + set -euo pipefail |
| 67 | + target="${{ matrix.target }}" |
| 68 | + archive="codex-blackbox-${target}.tar.gz" |
| 69 | + staging="dist/${target}" |
| 70 | + mkdir -p "$staging" |
| 71 | + cp "target/${target}/release/codex-blackbox" "$staging/codex-blackbox" |
| 72 | + cp README.md LICENSE "$staging/" |
| 73 | + tar -czf "dist/${archive}" -C "$staging" codex-blackbox README.md LICENSE |
| 74 | + if command -v sha256sum >/dev/null 2>&1; then |
| 75 | + sha256sum "dist/${archive}" > "dist/${archive}.sha256" |
| 76 | + else |
| 77 | + shasum -a 256 "dist/${archive}" > "dist/${archive}.sha256" |
| 78 | + fi |
| 79 | +
|
| 80 | + - name: Upload artifact |
| 81 | + uses: actions/upload-artifact@v7 |
| 82 | + with: |
| 83 | + name: codex-blackbox-${{ matrix.target }} |
| 84 | + path: | |
| 85 | + dist/codex-blackbox-${{ matrix.target }}.tar.gz |
| 86 | + dist/codex-blackbox-${{ matrix.target }}.tar.gz.sha256 |
| 87 | +
|
| 88 | + docker-image: |
| 89 | + name: Build and push codex-blackbox-core image (${{ matrix.arch }}) |
| 90 | + runs-on: ${{ matrix.runner }} |
| 91 | + strategy: |
| 92 | + fail-fast: false |
| 93 | + max-parallel: 1 |
| 94 | + matrix: |
| 95 | + include: |
| 96 | + - arch: amd64 |
| 97 | + platform: linux/amd64 |
| 98 | + runner: ubuntu-latest |
| 99 | + - arch: arm64 |
| 100 | + platform: linux/arm64 |
| 101 | + runner: ubuntu-24.04-arm |
| 102 | + |
| 103 | + steps: |
| 104 | + - name: Checkout |
| 105 | + uses: actions/checkout@v6 |
| 106 | + |
| 107 | + - name: Check crate version matches tag |
| 108 | + shell: bash |
| 109 | + run: | |
| 110 | + set -euo pipefail |
| 111 | + crate_version="$(awk -F'"' '/^version = / { print $2; exit }' codex-blackbox-cli/Cargo.toml)" |
| 112 | + test "v${crate_version}" = "$GITHUB_REF_NAME" |
| 113 | +
|
| 114 | + - name: Set image tags |
| 115 | + id: tags |
| 116 | + shell: bash |
| 117 | + run: | |
| 118 | + set -euo pipefail |
| 119 | + tag="${GITHUB_REF_NAME}" |
| 120 | + version="${tag#v}" |
| 121 | + image="ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/codex-blackbox-core" |
| 122 | + { |
| 123 | + echo "image=${image}" |
| 124 | + echo "tag=${tag}" |
| 125 | + echo "version=${version}" |
| 126 | + } >> "$GITHUB_OUTPUT" |
| 127 | +
|
| 128 | + - name: Set up Docker Buildx |
| 129 | + uses: docker/setup-buildx-action@v4 |
| 130 | + |
| 131 | + - name: Login to GHCR |
| 132 | + uses: docker/login-action@v4 |
| 133 | + with: |
| 134 | + registry: ghcr.io |
| 135 | + username: ${{ github.actor }} |
| 136 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 137 | + |
| 138 | + - name: Build and push |
| 139 | + uses: docker/build-push-action@v7 |
| 140 | + with: |
| 141 | + context: . |
| 142 | + file: ./codex-blackbox-core/Dockerfile |
| 143 | + platforms: ${{ matrix.platform }} |
| 144 | + push: true |
| 145 | + cache-from: type=gha,scope=codex-blackbox-core-${{ matrix.arch }} |
| 146 | + cache-to: type=gha,mode=max,scope=codex-blackbox-core-${{ matrix.arch }} |
| 147 | + tags: | |
| 148 | + ${{ steps.tags.outputs.image }}:${{ steps.tags.outputs.tag }}-${{ matrix.arch }} |
| 149 | + ${{ steps.tags.outputs.image }}:${{ steps.tags.outputs.version }}-${{ matrix.arch }} |
| 150 | +
|
| 151 | + docker-manifest: |
| 152 | + name: Publish codex-blackbox-core image manifest |
| 153 | + runs-on: ubuntu-latest |
| 154 | + needs: |
| 155 | + - docker-image |
| 156 | + |
| 157 | + steps: |
| 158 | + - name: Set image tags |
| 159 | + id: tags |
| 160 | + shell: bash |
| 161 | + run: | |
| 162 | + set -euo pipefail |
| 163 | + tag="${GITHUB_REF_NAME}" |
| 164 | + version="${tag#v}" |
| 165 | + image="ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/codex-blackbox-core" |
| 166 | + { |
| 167 | + echo "image=${image}" |
| 168 | + echo "tag=${tag}" |
| 169 | + echo "version=${version}" |
| 170 | + } >> "$GITHUB_OUTPUT" |
| 171 | +
|
| 172 | + - name: Set up Docker Buildx |
| 173 | + uses: docker/setup-buildx-action@v4 |
| 174 | + |
| 175 | + - name: Login to GHCR |
| 176 | + uses: docker/login-action@v4 |
| 177 | + with: |
| 178 | + registry: ghcr.io |
| 179 | + username: ${{ github.actor }} |
| 180 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 181 | + |
| 182 | + - name: Publish manifest |
| 183 | + shell: bash |
| 184 | + run: | |
| 185 | + set -euo pipefail |
| 186 | + image="${{ steps.tags.outputs.image }}" |
| 187 | + tag="${{ steps.tags.outputs.tag }}" |
| 188 | + version="${{ steps.tags.outputs.version }}" |
| 189 | + docker buildx imagetools create \ |
| 190 | + -t "${image}:${tag}" \ |
| 191 | + -t "${image}:${version}" \ |
| 192 | + -t "${image}:latest" \ |
| 193 | + "${image}:${tag}-amd64" \ |
| 194 | + "${image}:${tag}-arm64" |
| 195 | +
|
| 196 | + release: |
| 197 | + name: Publish GitHub release |
| 198 | + runs-on: ubuntu-latest |
| 199 | + needs: |
| 200 | + - build-cli |
| 201 | + env: |
| 202 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 203 | + |
| 204 | + steps: |
| 205 | + - name: Checkout |
| 206 | + uses: actions/checkout@v6 |
| 207 | + |
| 208 | + - name: Download CLI artifacts |
| 209 | + uses: actions/download-artifact@v8 |
| 210 | + with: |
| 211 | + path: dist |
| 212 | + pattern: codex-blackbox-* |
| 213 | + merge-multiple: true |
| 214 | + |
| 215 | + - name: Create release |
| 216 | + shell: bash |
| 217 | + run: | |
| 218 | + set -euo pipefail |
| 219 | + assets=( |
| 220 | + dist/codex-blackbox-*.tar.gz |
| 221 | + dist/codex-blackbox-*.tar.gz.sha256 |
| 222 | + install.sh |
| 223 | + ) |
| 224 | + notes="Install with: curl -fsSL https://raw.githubusercontent.com/softcane/codex-blackbox/main/install.sh | sh" |
| 225 | + if gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1; then |
| 226 | + gh release upload "$GITHUB_REF_NAME" "${assets[@]}" --clobber |
| 227 | + gh release edit "$GITHUB_REF_NAME" --title "$GITHUB_REF_NAME" --notes "$notes" |
| 228 | + else |
| 229 | + gh release create "$GITHUB_REF_NAME" "${assets[@]}" --title "$GITHUB_REF_NAME" --notes "$notes" |
| 230 | + fi |
0 commit comments