Download release assets to files before computing SHA256 #14
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: Release | ||
| on: | ||
| push: | ||
| tags: | ||
| - "v*" | ||
| permissions: | ||
| contents: write | ||
| id-token: write | ||
| jobs: | ||
| build: | ||
| strategy: | ||
| matrix: | ||
| include: | ||
| - target: x86_64-unknown-linux-gnu | ||
| os: ubuntu-latest | ||
| - target: aarch64-unknown-linux-gnu | ||
| os: ubuntu-latest | ||
| - target: x86_64-apple-darwin | ||
| os: macos-latest | ||
| - target: aarch64-apple-darwin | ||
| os: macos-latest | ||
| - target: x86_64-pc-windows-msvc | ||
| os: windows-latest | ||
| runs-on: ${{ matrix.os }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: dtolnay/rust-toolchain@stable | ||
| with: | ||
| targets: ${{ matrix.target }} | ||
| - name: Install cross-compilation tools | ||
| if: matrix.target == 'aarch64-unknown-linux-gnu' | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y gcc-aarch64-linux-gnu | ||
| echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV | ||
| - uses: Swatinem/rust-cache@v2 | ||
| - run: cargo build --release --target ${{ matrix.target }} | ||
| - name: Package (Unix) | ||
| if: runner.os != 'Windows' | ||
| shell: bash | ||
| run: | | ||
| cd target/${{ matrix.target }}/release | ||
| tar czf ../../../cx-${{ matrix.target }}.tar.gz cx | ||
| cd ../../.. | ||
| - name: Package (Windows) | ||
| if: runner.os == 'Windows' | ||
| shell: pwsh | ||
| run: | | ||
| Compress-Archive -Path "target/${{ matrix.target }}/release/cx.exe" -DestinationPath "cx-${{ matrix.target }}.zip" | ||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: cx-${{ matrix.target }} | ||
| path: cx-${{ matrix.target }}.* | ||
| release: | ||
| needs: build | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/download-artifact@v4 | ||
| with: | ||
| merge-multiple: true | ||
| - name: Create release | ||
| uses: softprops/action-gh-release@v2 | ||
| with: | ||
| generate_release_notes: true | ||
| files: | | ||
| cx-*.tar.gz | ||
| cx-*.zip | ||
| publish-crate: | ||
| needs: release | ||
| runs-on: ubuntu-latest | ||
| environment: crates-io | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: dtolnay/rust-toolchain@stable | ||
| - name: Generate OIDC token | ||
| id: oidc | ||
| run: | | ||
| token=$(curl -sS -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \ | ||
| "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=crates.io" | jq -r '.value') | ||
| echo "::add-mask::$token" | ||
| echo "token=$token" >> "$GITHUB_OUTPUT" | ||
| - run: cargo publish | ||
| env: | ||
| CARGO_REGISTRY_TOKEN: "oidc:${{ steps.oidc.outputs.token }}" | ||
| update-homebrew: | ||
| needs: release | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Get version and compute SHA256s | ||
| id: info | ||
| run: | | ||
| VERSION="${GITHUB_REF_NAME#v}" | ||
| BASE="https://github.com/ind-igo/cx/releases/download/${GITHUB_REF_NAME}" | ||
| for pair in \ | ||
| "arm:cx-aarch64-apple-darwin.tar.gz" \ | ||
| "x86:cx-x86_64-apple-darwin.tar.gz" \ | ||
| "linux:cx-x86_64-unknown-linux-gnu.tar.gz" \ | ||
| "linux_arm:cx-aarch64-unknown-linux-gnu.tar.gz"; do | ||
| key="${pair%%:*}" | ||
| file="${pair#*:}" | ||
| curl -sLf -o "/tmp/${file}" "${BASE}/${file}" | ||
| sha=$(sha256sum "/tmp/${file}" | cut -d' ' -f1) | ||
| echo "${key}_sha=$sha" >> "$GITHUB_OUTPUT" | ||
| done | ||
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | ||
| echo "arm_sha=$ARM_SHA" >> "$GITHUB_OUTPUT" | ||
| echo "x86_sha=$X86_SHA" >> "$GITHUB_OUTPUT" | ||
| echo "linux_sha=$LINUX_SHA" >> "$GITHUB_OUTPUT" | ||
| echo "linux_arm_sha=$LINUX_ARM_SHA" >> "$GITHUB_OUTPUT" | ||
| - name: Update Homebrew tap | ||
| env: | ||
| TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} | ||
| run: | | ||
| VERSION="${{ steps.info.outputs.version }}" | ||
| TAG="${GITHUB_REF_NAME}" | ||
| ARM_SHA="${{ steps.info.outputs.arm_sha }}" | ||
| X86_SHA="${{ steps.info.outputs.x86_sha }}" | ||
| LINUX_SHA="${{ steps.info.outputs.linux_sha }}" | ||
| LINUX_ARM_SHA="${{ steps.info.outputs.linux_arm_sha }}" | ||
| BASE="https://github.com/ind-igo/cx/releases/download/${TAG}" | ||
| git clone https://x-access-token:${TAP_TOKEN}@github.com/ind-igo/homebrew-cx.git | ||
| cd homebrew-cx | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| cat > Formula/cx.rb << FORMULA | ||
| class Cx < Formula | ||
| desc "Semantic code navigation for AI agents" | ||
| homepage "https://github.com/ind-igo/cx" | ||
| version "${VERSION}" | ||
| license "MIT" | ||
| on_macos do | ||
| if Hardware::CPU.arm? | ||
| url "${BASE}/cx-aarch64-apple-darwin.tar.gz" | ||
| sha256 "${ARM_SHA}" | ||
| else | ||
| url "${BASE}/cx-x86_64-apple-darwin.tar.gz" | ||
| sha256 "${X86_SHA}" | ||
| end | ||
| end | ||
| on_linux do | ||
| if Hardware::CPU.arm? | ||
| url "${BASE}/cx-aarch64-unknown-linux-gnu.tar.gz" | ||
| sha256 "${LINUX_ARM_SHA}" | ||
| else | ||
| url "${BASE}/cx-x86_64-unknown-linux-gnu.tar.gz" | ||
| sha256 "${LINUX_SHA}" | ||
| end | ||
| end | ||
| def install | ||
| bin.install "cx" | ||
| end | ||
| test do | ||
| assert_match version.to_s, shell_output("#{bin}/cx --version") | ||
| end | ||
| end | ||
| FORMULA | ||
| git add Formula/cx.rb | ||
| git diff --staged --quiet && exit 0 | ||
| git commit -m "cx ${VERSION}" | ||
| git push | ||