ci: Upload binaries to releases #21
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: Release | |
on: | |
push: | |
tags: | |
- "v[0-9]+.[0-9]+.[0-9]+" | |
# TODO: Remove | |
branches: | |
- ci-upload-binaries-to-releases | |
pull_request: | |
branches: | |
- master | |
paths: | |
- VERSION | |
env: | |
is_tag: startsWith(github.ref, 'refs/tags/') | |
# dist: dist-${{ github.ref_name }} | |
dist: dist-v0.0.0 | |
jobs: | |
build: | |
name: Build | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
target: | |
- aarch64-apple-darwin | |
- x86_64-unknown-linux-gnu | |
- x86_64-apple-darwin | |
- x86_64-pc-windows-msvc | |
include: | |
- target: aarch64-apple-darwin | |
os: macos-latest | |
- target: x86_64-unknown-linux-gnu | |
os: ubuntu-latest | |
- target: x86_64-apple-darwin | |
os: macos-latest | |
- target: x86_64-pc-windows-msvc | |
os: windows-latest | |
steps: | |
- name: Checkout sources | |
uses: actions/checkout@v4 | |
- name: Install stable toolchain | |
uses: dtolnay/rust-toolchain@master | |
with: | |
toolchain: stable | |
target: ${{ matrix.target }} | |
- name: Build release binary | |
run: cargo build --package anchor-cli --release --locked --target ${{ matrix.target }} | |
- name: Prepare | |
if: env.is_tag | |
id: prepare | |
shell: bash | |
run: | | |
mkdir -p $dist | |
ext="" | |
[[ "${{ matrix.os }}" == windows-latest ]] && ext=".exe" | |
cp "target/${{ matrix.target }}/release/anchor$ext" $dist/ | |
echo "version=$(echo $GITHUB_REF_NAME | cut -dv -f2)" >> $GITHUB_OUTPUT | |
- uses: actions/upload-artifact@v4 | |
if: env.is_tag | |
with: | |
name: anchor-${{ steps.prepare.outputs.version }}-${{ matrix.target }} | |
path: ${{ env.dist }} | |
retention-days: 1 | |
upload: | |
name: Upload binaries to release | |
# if: startsWith(github.ref, 'refs/tags/') # `env.is_tag` doesn't work for some reason | |
# needs: [build] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/download-artifact@v4 | |
with: | |
path: ${{ env.dist }} | |
- name: Upload | |
shell: bash | |
run: GH_TOKEN=${{ secrets.GITHUB_TOKEN }} gh release upload "$GITHUB_REF_NAME" $dist/* --clobber |