forked from skraus-dev/cherryrgb-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
245 lines (234 loc) · 7.94 KB
/
ci.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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
name: New CI
on:
push:
branches:
'master'
tags:
'[0-9]+\.[0-9]+\.[0-9]+'
pull_request:
branches:
- 'master'
paths-ignore:
- 'LICENSE'
- '**/*.md'
- '.github/**/*'
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
DEBIAN_FRONTEND: noninteractive
INSTDEPS: "apt-get update && apt-get install -y libclang-dev clang"
RUSTFLAGS: "-C link-arg=-s"
CACHE_PREFIX: "${{ vars.CACHE_PREFIX }}"
jobs:
test:
name: Test Suite
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install build dependencies
run: sudo sh -c "${{ env.INSTDEPS }}"
- run: cargo test --all-features --workspace
rustfmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Check formatting
run: cargo fmt --all -- --check
clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install build dependencies
run: sudo sh -c "${{ env.INSTDEPS }}"
- name: Clippy check
run: cargo clippy --all-targets --all-features --workspace -- -D warnings
docs:
name: Docs
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install build dependencies
run: sudo sh -c "${{ env.INSTDEPS }}"
- name: Check documentation
env:
RUSTDOCFLAGS: -D warnings
run: cargo doc --no-deps --document-private-items --all-features --workspace
publish-dry-run:
name: Publish dry run
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Publish dry-run
run: cargo publish -p cherryrgb --dry-run
check-cargo-lock:
if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }}
name: Check Cargo.lock
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- run: cargo fetch --locked
clean:
if: ${{ github.event_name != 'pull_request' }} # If this is a pull request, stop here
name: Clean before matrix build
needs: [test, clippy, rustfmt, docs, publish-dry-run]
runs-on: ubuntu-latest
steps:
- name: Clean target
run: rm -rf target
build:
needs: [clean]
strategy:
matrix:
# Name of the tar archives: <assetprefix>-<tag>-<assetname>.tar.gz
assetprefix: [cherryrgb-rs]
job:
- os: ubuntu-latest
assetname: linux-x86_64
target: x86_64-unknown-linux-gnu
buildopts: "--all --features uhid"
installdeps: true
native: true
- os: macos-latest
assetname: macos-x86_64
target: x86_64-apple-darwin
buildopts: ""
installdeps: false
native: true
- os: windows-latest
assetname: windows-x86_64
target: x86_64-pc-windows-msvc
buildopts: ""
installdeps: false
native: true
- os: ubuntu-latest
assetname: linux-arm64
target: aarch64-unknown-linux-gnu
buildopts: "--all --features uhid"
native: false
imagetag: edge
- os: ubuntu-latest
assetname: linux-i686
target: i686-unknown-linux-gnu
buildopts: "--all --features uhid"
native: false
imagetag: edge
- os: ubuntu-latest
assetname: linux-ppc64le
target: powerpc64le-unknown-linux-gnu
buildopts: "--all --features uhid"
native: false
imagetag: edge
runs-on: ${{ matrix.job.os }}
name: Build for ${{ matrix.job.target }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Initialize CARGO_HOME
shell: bash
# The following must be set from within a shell, because HOME is not preset in a github runner context.
# See also https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
run: echo "CARGO_HOME=${HOME}/.cargo-${{ matrix.job.target }}" >> "$GITHUB_ENV"
- name: Install native build dependencies
if: ${{ matrix.job.installdeps && matrix.job.native }}
run: sudo sh -c "${{ env.INSTDEPS }}"
- name: Retrieve target cache
uses: actions/cache@v3
with:
path: |
target
${{ env.CARGO_HOME }}/bin/
${{ env.CARGO_HOME }}/registry/index/
${{ env.CARGO_HOME }}/registry/cache/
${{ env.CARGO_HOME }}/git/db/
key: ${{ env.CACHE_PREFIX }}${{ matrix.job.target }}-${{ hashFiles('Cargo.lock') }}
restore-keys: |
${{ env.CACHE_PREFIX }}${{ matrix.job.target }}
enableCrossOsArchive: true
- name: Build native
if: ${{ matrix.job.native }}
run: |
cargo build --release --target ${{ matrix.job.target }} ${{ matrix.job.buildopts }}
- name: Install cross-rs
id: install_cross
if: ${{ ! matrix.job.native }}
run: test -f ${{ env.CARGO_HOME }}/bin/cross && echo "::notice::cross provided from cache, skipping install" || cargo install cross
- name: Configure cross
id: configure_cross
if: ${{ ! matrix.job.native }}
run: |
cat > Cross.toml << EOM
[target.${{ matrix.job.target }}]
image = "ghcr.io/cross-rs/${{ matrix.job.target }}:${{ matrix.job.imagetag }}"
pre-build = ["${{ env.INSTDEPS }}"]
EOM
- name: Build with cross
id: build_foreign
if: ${{ ! matrix.job.native }}
run: |
${{ env.CARGO_HOME }}/bin/cross build --release --target ${{ matrix.job.target }} ${{ matrix.job.buildopts }}
- name: Update target cache
uses: actions/cache@v3
with:
path: |
target
${{ env.CARGO_HOME }}/bin/
${{ env.CARGO_HOME }}/registry/index/
${{ env.CARGO_HOME }}/registry/cache/
${{ env.CARGO_HOME }}/git/db/
key: ${{ env.CACHE_PREFIX }}${{ matrix.job.target }}-${{ hashFiles('Cargo.lock') }}
restore-keys: |
${{ env.CACHE_PREFIX }}${{ matrix.job.target }}
enableCrossOsArchive: true
- name: Generate cmdline help/docs/completions
run: cargo xtask all
- name: Collect artifacts
shell: bash
run: |
mkdir -p artifacts/bin
case "${{ matrix.job.target }}" in
*linux*)
for bin in cli ncli service; do
path=target/${{ matrix.job.target }}/release/cherryrgb_${bin}
test -f ${path} && cp -av ${path} artifacts/bin/ || true
done
miscfiles="*.md LICENSE service/etc udev docs examples target/generated/*"
;;
*windows*)
cp -av target/${{ matrix.job.target }}/release/cherryrgb_cli.exe artifacts/bin/
miscfiles="*.md LICENSE docs examples target/generated/*"
;;
*)
cp -av target/${{ matrix.job.target }}/release/cherryrgb_cli artifacts/bin/
miscfiles="*.md LICENSE docs examples target/generated/*"
;;
esac
cp -av ${miscfiles} artifacts/
afname="${{ matrix.assetprefix }}-${{ github.ref_name }}-${{ matrix.job.assetname }}"
mv artifacts "${afname}"
tar cvzf "${afname}.tar.gz" "${afname}"
echo "${GITHUB_REF}" > github-ref
echo "${GITHUB_SHA}" > commithash
- name: Save artifacts
uses: actions/upload-artifact@v3
with:
name: cherryrgb-rs
path: |
github-ref
commithash
${{ matrix.assetprefix }}-${{ github.ref_name }}-${{ matrix.job.assetname }}.tar.gz
deploy:
if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }}
needs: [build, check-cargo-lock]
name: Call
uses: ./.github/workflows/cd.yml
secrets: inherit
with:
artifact-id: cherryrgb-rs