-
Notifications
You must be signed in to change notification settings - Fork 0
129 lines (115 loc) · 5.46 KB
/
anchor-cli.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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: ~/.cargo/bin/anchor-${{ steps.set_version.outputs.version_or_rev }}-${{ github.event.inputs.target }}
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
mv ~/.cargo/bin/anchor ~/.cargo/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: ~/.cargo/bin/anchor-${{ steps.set_version.outputs.version_or_rev }}-${{ github.event.inputs.target }}
key: ${{ runner.os }}-anchor-${{ steps.set_version.outputs.version_or_rev }}-${{ github.event.inputs.target }}-${{ github.event.inputs.rust_version }}
- name: Check existing release
id: check_release
run: |
release_id=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/tags/anchor-${{ steps.set_version.outputs.version_or_rev }}" \
| jq -r '.id')
if [ "$release_id" != "null" ]; then
echo "release_exists=true" >> $GITHUB_OUTPUT
echo "release_id=$release_id" >> $GITHUB_OUTPUT
else
echo "release_exists=false" >> $GITHUB_OUTPUT
fi
- name: Create Release
if: steps.check_release.outputs.release_exists == 'false'
id: create_release
uses: softprops/action-gh-release@v1
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 binaries for different targets."
draft: false
prerelease: false
- name: Upload binary to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.check_release.outputs.release_exists == 'true' && format('https://uploads.github.com/repos/{0}/releases/{1}/assets{{?name,label}}', github.repository, steps.check_release.outputs.release_id) || steps.create_release.outputs.upload_url }}
asset_path: ~/.cargo/bin/anchor-${{ steps.set_version.outputs.version_or_rev }}-${{ github.event.inputs.target }}
asset_name: anchor-${{ steps.set_version.outputs.version_or_rev }}-${{ github.event.inputs.target }}
asset_content_type: application/octet-stream
- name: Get Release URL
run: |
echo "Release URL: https://github.com/${{ github.repository }}/releases/tag/anchor-${{ steps.set_version.outputs.version_or_rev }}"
echo "Binary name: anchor-${{ steps.set_version.outputs.version_or_rev }}-${{ github.event.inputs.target }}"