Build Anchor CLI #12
This file contains 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: Build Anchor CLI | |
on: | |
workflow_dispatch: | |
inputs: | |
rust_version: | |
description: 'Rust version' | |
required: false | |
default: 'stable' | |
rev: | |
description: 'Anchor revision to build' | |
required: false | |
anchor_version: | |
description: 'Anchor version to build' | |
required: false | |
default: '0.30.1' | |
target: | |
description: 'Build target' | |
required: false | |
default: 'x86_64-unknown-linux-musl' | |
type: choice | |
options: | |
- x86_64-unknown-linux-musl | |
- aarch64-unknown-linux-musl | |
env: | |
CARGO_NET_GIT_FETCH_WITH_CLI: true | |
SCCACHE_BUCKET: gh-runner-cache-rust | |
SCCACHE_REGION: eu-central-1 | |
AWS_ACCESS_KEY_ID: ${{ secrets.RUST_S3_AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.RUST_S3_AWS_SECRET_ACCESS_KEY }} | |
SCCACHE_GHA_ENABLED: "true" | |
RUSTC_WRAPPER: "sccache" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install system dependencies | |
uses: awalsh128/cache-apt-pkgs-action@latest | |
with: | |
packages: pkg-config build-essential libudev-dev musl-tools | |
version: 1.0 | |
- name: Set version or rev | |
id: set_version | |
run: | | |
if [ -n "${{ github.event.inputs.rev }}" ]; then | |
echo "version_or_rev=${{ github.event.inputs.rev }}" >> $GITHUB_OUTPUT | |
else | |
echo "version_or_rev=${{ github.event.inputs.anchor_version }}" >> $GITHUB_OUTPUT | |
fi | |
- name: Install Rust | |
uses: dtolnay/rust-toolchain@master | |
with: | |
toolchain: ${{ github.event.inputs.rust_version }} | |
targets: ${{ github.event.inputs.target }} | |
- name: Run sccache-cache | |
uses: mozilla-actions/[email protected] | |
- name: Restore cached Anchor CLI binary | |
id: cache-anchor-restore | |
uses: actions/cache/restore@v4 | |
with: | |
path: ${{ github.workspace }}/anchor-cli-bin | |
key: ${{ runner.os }}-anchor-${{ steps.set_version.outputs.version_or_rev }}-${{ github.event.inputs.target }}-${{ github.event.inputs.rust_version }} | |
- name: Build Anchor CLI | |
if: steps.cache-anchor-restore.outputs.cache-hit != 'true' | |
run: | | |
if [ -n "${{ github.event.inputs.rev }}" ]; then | |
RUSTFLAGS='-C target-feature=+crt-static' cargo install --git https://github.com/coral-xyz/anchor --rev ${{ github.event.inputs.rev }} --target ${{ github.event.inputs.target }} anchor-cli --locked | |
else | |
VERSION="${{ github.event.inputs.anchor_version }}" | |
RUSTFLAGS='-C target-feature=+crt-static' cargo install --git https://github.com/coral-xyz/anchor --tag v${VERSION} --target ${{ github.event.inputs.target }} anchor-cli --locked | |
fi | |
mkdir -p ${{ github.workspace }}/anchor-cli-bin | |
mv ~/.cargo/bin/anchor ${{ github.workspace }}/anchor-cli-bin/anchor-${{ steps.set_version.outputs.version_or_rev }}-${{ github.event.inputs.target }} | |
- name: Save Anchor CLI binary cache | |
if: steps.cache-anchor-restore.outputs.cache-hit != 'true' | |
uses: actions/cache/save@v4 | |
with: | |
path: ${{ github.workspace }}/anchor-cli-bin | |
key: ${{ runner.os }}-anchor-${{ steps.set_version.outputs.version_or_rev }}-${{ github.event.inputs.target }}-${{ github.event.inputs.rust_version }} | |
- name: Prepare binary for release | |
run: | | |
cp ${{ github.workspace }}/anchor-cli-bin/anchor-${{ steps.set_version.outputs.version_or_rev }}-${{ github.event.inputs.target }} ${{ github.workspace }}/anchor-cli-bin/anchor-${{ github.event.inputs.target }} | |
- name: Debug - List files | |
run: | | |
ls -la ${{ github.workspace }}/anchor-cli-bin | |
- name: Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
tag_name: anchor-${{ steps.set_version.outputs.version_or_rev }} | |
name: Anchor CLI ${{ steps.set_version.outputs.version_or_rev }} | |
body: "This release contains Anchor CLI binary for ${{ github.event.inputs.target }} target." | |
files: ${{ github.workspace }}/anchor-cli-bin/anchor-${{ github.event.inputs.target }} | |
draft: false | |
prerelease: false | |
- name: Get Release URL | |
run: | | |
echo "Release URL: ${{ steps.release.outputs.url }}" | |
echo "Binary name: anchor-${{ github.event.inputs.target }}" | |
echo "Download URL: ${{ steps.release.outputs.url }}/download/anchor-${{ steps.set_version.outputs.version_or_rev }}/anchor-${{ github.event.inputs.target }}" |