-
Notifications
You must be signed in to change notification settings - Fork 5
156 lines (136 loc) · 4.41 KB
/
build-binaries-gh_release.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# Build binaries for a given Git ref.
# Based on:
# - https://github.com/BurntSushi/ripgrep/blob/d922b7ac114c24d6800ae5f79d2967481f380c83/.github/workflows/release.yml
# - https://github.com/dafny-lang/dafny/blob/beab582113744ea72e2727d934f5a03d42c4ba17/.github/workflows/publish-release-reusable.yml
name: Build Binaries
on:
workflow_call:
inputs:
git_ref:
required: true
type: string
version:
required: true
type: string
is_prerelease:
required: true
type: boolean
jobs:
build-release:
name: build-release
runs-on: ${{ matrix.os }}
env:
# For some builds, we use cross to test on 32-bit and big-endian
# systems.
CARGO: cargo
# When CARGO is set to CROSS, this is set to `--target matrix.target`.
TARGET_FLAGS:
# When CARGO is set to CROSS, TARGET_DIR includes matrix.target.
TARGET_DIR: ./target
# Emit backtraces on panics.
RUST_BACKTRACE: 1
strategy:
fail-fast: false
matrix:
include:
- build: linux-x86
os: ubuntu-latest
rust: stable
target: x86_64-unknown-linux-gnu
- build: macos-apple-silicon
os: macos-latest
rust: stable
target: aarch64-apple-darwin
- build: macos-intel
os: macos-13 # newest available Github runner on Intel
rust: stable
target: x86_64-apple-darwin
- build: windows-msvc
os: windows-latest
rust: stable
target: x86_64-pc-windows-msvc
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.git_ref }}
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
- name: Install packages (Ubuntu)
if: contains(matrix.os, 'ubuntu')
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y cmake llvm-dev libclang-dev clang lld
- name: Install packages (MacOS)
if: contains(matrix.os, 'macos')
shell: bash
run: |
brew update
brew install cmake
- name: Install packages (Windows)
if: contains(matrix.os, 'windows')
shell: bash
run: |
choco install -y cmake llvm
- name: Set target variables
shell: bash
run: |
echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV
echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV
- name: Show command used for Cargo
shell: bash
run: |
echo "cargo command is: ${{ env.CARGO }}"
echo "target flag is: ${{ env.TARGET_FLAGS }}"
echo "target dir is: ${{ env.TARGET_DIR }}"
- name: Build release binary
shell: bash
run: |
${{ env.CARGO }} build --verbose --release ${{ env.TARGET_FLAGS }}
if [ "${{ matrix.os }}" = "windows-latest" ]; then
bin="target/${{ matrix.target }}/release/caesar.exe"
else
bin="target/${{ matrix.target }}/release/caesar"
fi
echo "BIN=$bin" >> $GITHUB_ENV
- name: Strip release binary (macos)
if: matrix.os == 'macos-latest'
shell: bash
run: strip "$BIN"
- name: Determine archive name
shell: bash
run: |
version="${{ inputs.version }}"
echo "ARCHIVE=caesar-$version-${{ matrix.target }}" >> $GITHUB_ENV
- name: Creating directory for archive
shell: bash
run: |
mkdir -p "$ARCHIVE"
cp "$BIN" "$ARCHIVE"/
cp README.md "$ARCHIVE"/
# cp {CHANGELOG.md,FAQ.md,GUIDE.md} "$ARCHIVE"/doc/
# cp {README.md,COPYING,UNLICENSE,LICENSE-MIT} "$ARCHIVE"/
- name: Build archive (Windows)
shell: bash
if: matrix.os == 'windows-latest'
run: |
7z a "$ARCHIVE.zip" "./$ARCHIVE/*"
echo "ASSET=$ARCHIVE.zip" >> $GITHUB_ENV
- name: Build archive (Unix)
shell: bash
if: matrix.os != 'windows-latest'
run: |
tar czf "$ARCHIVE.tar.gz" "$ARCHIVE"
echo "ASSET=$ARCHIVE.tar.gz" >> $GITHUB_ENV
- name: Upload Release Files
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ inputs.git_ref }}
# Also need to specify 'draft' again, so that the action finds the correct existing (draft) release
draft: ${{ !inputs.is_prerelease }}
files: |
${{ env.ASSET }}