-
Notifications
You must be signed in to change notification settings - Fork 1.9k
97 lines (81 loc) · 3.13 KB
/
build-cli.yaml
File metadata and controls
97 lines (81 loc) · 3.13 KB
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
name: Build CLI
on:
workflow_call:
inputs:
dry_run:
description: "If true, use 'dry-run' as the version string instead of the tag"
required: true
type: boolean
dist:
description: "Directory name for distribution artifacts (e.g. dist-v1.2.3 or dist-dry-run)"
required: true
type: string
jobs:
build-cli:
name: Build binaries${{ inputs.dry_run && ' (dry-run)' || '' }} (${{matrix.os}})
runs-on: ${{ matrix.os }}
permissions:
contents: read
id-token: write
attestations: write
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:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # v1
with:
toolchain: stable
target: ${{ matrix.target }}
- name: Install dependencies (Linux)
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y libudev-dev
# FIXME: The global system LLVM on GitHub is very outdated, and LTO causes link errors
- name: Build release binary (macOS)
if: runner.os == 'macOS'
env:
CARGO_PROFILE_RELEASE_LTO: "off"
RUSTFLAGS: -C embed-bitcode=no
run: cargo build --package anchor-cli --release --locked --target ${{ matrix.target }}
- name: Build release binary
if: runner.os != 'macOS'
run: cargo build --package anchor-cli --release --locked --target ${{ matrix.target }}
- name: Prepare
id: prepare
shell: bash
run: |
if [[ "${{ inputs.dry_run }}" == "true" ]]; then
version="dry-run"
else
version=$(echo $GITHUB_REF_NAME | cut -dv -f2)
fi
ext=""
[[ "${{ matrix.os }}" == windows-latest ]] && ext=".exe"
mkdir ${{ inputs.dist }}
mv "target/${{ matrix.target }}/release/anchor$ext" ${{ inputs.dist }}/anchor-$version-${{ matrix.target }}$ext
echo "version=$version" >> $GITHUB_OUTPUT
- name: Attest build provenance
# `id-token: write` is not granted for PRs from forks
if: ${{ github.event.pull_request.head.repo.fork != true }}
uses: actions/attest-build-provenance@96278af6caaf10aea03fd8d33a09a777ca52d62f # v3.2.0
with:
subject-path: ${{ inputs.dist }}/anchor-${{ steps.prepare.outputs.version }}-${{ matrix.target }}*
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: anchor-${{ steps.prepare.outputs.version }}-${{ matrix.target }}
path: ${{ inputs.dist }}
overwrite: true
retention-days: 1