-
-
Notifications
You must be signed in to change notification settings - Fork 13
225 lines (195 loc) · 8.34 KB
/
build.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
on: [push, pull_request]
name: Test, build and package
env:
PROJECT_NAME: cyme
INTERMEDIATES_DIR: intermediates
jobs:
build:
name: Build and test for ${{ matrix.job.os }} (${{ matrix.job.target }})
runs-on: ${{ matrix.job.os }}
strategy:
fail-fast: false
matrix:
job:
# - { os: ubuntu-latest, target: aarch64-unknown-linux-gnu, use-cross: true }
- { os: ubuntu-latest, target: x86_64-pc-windows-gnu, use-cross: true }
- { os: ubuntu-latest, target: x86_64-unknown-linux-gnu, use-cross: false }
- { os: macos-latest, target: universal-apple-darwin, use-cross: false }
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
- name: Install prerequisites
shell: bash
run: |
case ${{ matrix.job.target }} in
*-linux-*)
sudo apt-get -y update;
sudo apt-get -y install libudev-dev;
sudo apt-get -y install libusb-1.0-0-dev;
cargo install cargo-deb
;;
universal-apple-*)
brew install libusb
rustup target add x86_64-apple-darwin
rustup target add aarch64-apple-darwin
;;
*)
;;
esac
- name: Set cargo cmd
shell: bash
run: echo "CARGO_CMD=cargo" >> "$GITHUB_ENV"
- name: Rustup add target
if: matrix.job.use-cross == false && !startsWith(matrix.job.target, 'universal-apple')
shell: bash
run: rustup target add ${{ matrix.job.target }}
- name: Set cargo cmd to cross
shell: bash
if: matrix.job.use-cross == true
run: echo "CARGO_CMD=cross" >> "$GITHUB_ENV"
- name: Install cross
shell: bash
if: matrix.job.use-cross == true
run: cargo install cross
- name: Test
id: test
shell: bash
if: matrix.job.use-cross == false
run: cargo test
- name: Build release
id: build
shell: bash
run: |
case ${{ matrix.job.target }} in
universal-apple-*)
cargo build --locked --release --all-features --target=aarch64-apple-darwin
cargo build --locked --release --all-features --target=x86_64-apple-darwin
mkdir -p target/universal-apple-darwin/release
# merge into universal
lipo -create -output target/universal-apple-darwin/release/cyme target/aarch64-apple-darwin/release/cyme target/x86_64-apple-darwin/release/cyme
;;
*)
${{ env.CARGO_CMD }} build --locked --release --all-features --target=${{ matrix.job.target }}
;;
esac
- name: Prepare and extract crate information
id: prepare
shell: bash
run: |
echo "PROJECT_VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> "$GITHUB_ENV"
echo "PROJECT_MAINTAINER=$(sed -n 's/^authors = \["\(.*\)"\]/\1/p' Cargo.toml)" >> "$GITHUB_ENV"
echo "PROJECT_HOMEPAGE=$(sed -n 's/^homepage = "\(.*\)"/\1/p' Cargo.toml)" >> "$GITHUB_ENV"
# Figure out suffix of binary
EXE_SUFFIX=""
case ${{ matrix.job.target }} in
*-pc-windows-*) EXE_SUFFIX=".exe" ;;
esac;
# Setup paths
BIN_DIR="${{ env.INTERMEDIATES_DIR }}/release-bin"
mkdir -p "${BIN_DIR}"
BIN_NAME="${{ env.PROJECT_NAME }}${EXE_SUFFIX}"
BIN_PATH="${BIN_DIR}/${BIN_NAME}"
# Copy the release build binary to the result location
cp "target/${{ matrix.job.target }}/release/${BIN_NAME}" "${BIN_DIR}"
echo "BIN_PATH=${BIN_PATH}" >> "$GITHUB_OUTPUT"
echo "BIN_NAME=${BIN_NAME}" >> "$GITHUB_OUTPUT"
- name: Generate bin outputs
id: generate
shell: bash
if: matrix.job.use-cross == false
run: |
"${{ steps.prepare.outputs.BIN_PATH }}" --gen
- name: Create tarball
id: package
shell: bash
run: |
PKG_SUFFIX=".tar.gz" ; case ${{ matrix.job.target }} in *-pc-windows-*) PKG_SUFFIX=".zip" ;; esac;
PKG_BASENAME=${PROJECT_NAME}-v${PROJECT_VERSION}-${{ matrix.job.target }}
PKG_NAME=${PKG_BASENAME}${PKG_SUFFIX}
echo "PKG_NAME=${PKG_NAME}" >> "$GITHUB_OUTPUT"
PKG_STAGING="${{ env.INTERMEDIATES_DIR }}/package"
ARCHIVE_DIR="${PKG_STAGING}/${PKG_BASENAME}/"
mkdir -p "${ARCHIVE_DIR}"
# Binary
cp "${{ steps.prepare.outputs.BIN_PATH }}" "$ARCHIVE_DIR"
# README and LICENSE
cp "README.md" "LICENSE" "$ARCHIVE_DIR"
# Man page
cp 'doc/${{ env.PROJECT_NAME }}.1' "$ARCHIVE_DIR"
# Autocompletion files
mkdir -p autocomplete
cp 'doc/${{ env.PROJECT_NAME }}.fish' 'doc/${{ env.PROJECT_NAME }}.bash' 'doc/_${{ env.PROJECT_NAME }}' 'doc/_${{ env.PROJECT_NAME }}.ps1' autocomplete
cp -r autocomplete "${ARCHIVE_DIR}"
# base compressed package
pushd "${PKG_STAGING}/" >/dev/null
case ${{ matrix.job.target }} in
*-pc-windows-*) 7z -y a "${PKG_NAME}" "${PKG_BASENAME}"/* | tail -2 ;;
*) tar czf "${PKG_NAME}" "${PKG_BASENAME}"/* ;;
esac;
popd >/dev/null
# Let subsequent steps know where to find the compressed package
echo "PKG_PATH=${PKG_STAGING}/${PKG_NAME}" >> "$GITHUB_OUTPUT"
- name: Create Debian package
id: debian-package
shell: bash
if: startsWith(matrix.job.os, 'ubuntu') && !contains(matrix.job.target, 'windows')
run: |
DPKG_STAGING="${{ env.INTERMEDIATES_DIR }}/debian-package"
DPKG_DIR="${DPKG_STAGING}/dpkg"
case ${{ matrix.job.target }} in
aarch64-*-linux-*) DPKG_ARCH=arm64 ;;
arm-*-linux-*hf) DPKG_ARCH=armhf ;;
i686-*-linux-*) DPKG_ARCH=i686 ;;
x86_64-*-linux-*) DPKG_ARCH=amd64 ;;
*) DPKG_ARCH=notset ;;
esac;
DPKG_NAME="${PROJECT_NAME}-v${PROJECT_VERSION}-1-${DPKG_ARCH}.deb"
echo "DPKG_NAME=${DPKG_NAME}" >> $GITHUB_OUTPUT
mkdir -p "${DPKG_DIR}"
DPKG_PATH="${DPKG_STAGING}/${DPKG_NAME}"
echo "DPKG_PATH=${DPKG_PATH}" >> $GITHUB_OUTPUT
cargo deb --target=${{ matrix.job.target }} --output "${DPKG_PATH}" --no-build --no-strip
- name: Upload package artifact
uses: actions/upload-artifact@master
with:
name: ${{ steps.package.outputs.PKG_NAME }}
path: ${{ steps.package.outputs.PKG_PATH }}
- name: Upload dpkg artifact
uses: actions/upload-artifact@master
if: steps.debian-package.outputs.DPKG_NAME
with:
name: ${{ steps.debian-package.outputs.DPKG_NAME }}
path: ${{ steps.debian-package.outputs.DPKG_PATH }}
- name: Check for release
id: is-release
shell: bash
run: |
unset IS_RELEASE ; if [[ $GITHUB_REF =~ ^refs/tags/v[0-9].* ]]; then IS_RELEASE='true' ; fi
echo "IS_RELEASE=${IS_RELEASE}" >> "$GITHUB_OUTPUT"
- name: Publish archives and packages
uses: softprops/action-gh-release@v1
if: steps.is-release.outputs.IS_RELEASE
with:
files: |
${{ steps.package.outputs.PKG_PATH }}
${{ steps.debian-package.outputs.DPKG_PATH }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Wait package uploaded
if: steps.is-release.outputs.IS_RELEASE && startsWith(matrix.job.target, 'universal-apple')
run: sleep 5 # sleep to ensure package is uploaded before homebrew
- name: Bump Homebrew formula
uses: mislav/bump-homebrew-formula-action@v2
if: steps.is-release.outputs.IS_RELEASE && startsWith(matrix.job.target, 'universal-apple')
with:
formula-name: cyme
formula-path: Formula/cyme.rb
homebrew-tap: tuna-f1sh/homebrew-taps
download-url: https://github.com/tuna-f1sh/cyme/releases/download/v${{ env.PROJECT_VERSION}}/${{ steps.package.outputs.PKG_NAME }}
commit-message: |
{{formulaName}} {{version}}
Created by https://github.com/mislav/bump-homebrew-formula-action
env:
COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }}