-
Notifications
You must be signed in to change notification settings - Fork 1
170 lines (158 loc) · 5.19 KB
/
ci.yaml
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
name: CI
on:
- push
- pull_request
- workflow_dispatch
permissions:
contents: read
env:
CARGO_INCREMENTAL: 0
CARGO_TERM_COLOR: always
RUSTFLAGS: -C link-arg=-s
jobs:
format:
name: Check rust format
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- name: Setup rust
run: |
rustup toolchain install nightly --profile minimal --component rustfmt --no-self-update
- name: Run cargo fmt
run: cargo +nightly fmt --check
test:
name: ${{ matrix.cmd.name }} (Rust ${{ matrix.rust }}) ${{ matrix.features }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust:
- stable
features:
- --no-default-features
-
- -F cli
cmd:
- name: Test
run: cargo test --locked
- name: Clippy
run: cargo clippy --locked --tests
run2: -D warnings
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- name: Setup rust
run: |
rustup toolchain install ${{ matrix.rust }} --profile minimal --no-self-update
- name: Install build dependencies
run: sudo apt-get install -y libudev-dev libdbus-1-dev
- name: ${{ matrix.cmd.name }}
run: ${{ matrix.cmd.run }} ${{ matrix.features }} -- ${{ matrix.cmd.run2 }}
build:
name: Build for ${{ matrix.target.name }}
runs-on: ${{ matrix.target.runs-on }}
strategy:
fail-fast: false
matrix:
target:
- name: Linux (x86_64)
runs-on: ubuntu-latest
target: x86_64-unknown-linux-gnu
pre-build: |
sudo apt-get install -y libudev-dev libdbus-1-dev
- name: Windows (x86_64)
runs-on: windows-latest
target: x86_64-pc-windows-msvc
ext: .exe
- name: MacOS (x86_64)
runs-on: macos-latest
target: x86_64-apple-darwin
- name: MacOS (arm64)
runs-on: macos-latest
target: aarch64-apple-darwin
timeout-minutes: 45
# env:
# RUSTFLAGS: -C target-feature=+crt-static
steps:
- uses: actions/checkout@v4
- name: Setup rust
run: |
rustup toolchain install stable --target ${{ matrix.target.target }} --profile minimal --no-self-update
- name: Install build dependencies
run: ${{ matrix.target.pre-build }}
if: matrix.target.pre-build
- name: Build for ${{ matrix.target.name }}
run: cargo build --locked --release --target ${{ matrix.target.target }} --no-default-features -F cli
- name: Check file
run: |
file target/${{ matrix.target.target }}/release/badgemagic${{ matrix.target.ext }}
stat target/${{ matrix.target.target }}/release/badgemagic${{ matrix.target.ext }}
mv target/${{ matrix.target.target }}/release/badgemagic${{ matrix.target.ext }} badgemagic.${{ matrix.target.target }}${{ matrix.target.ext }}
- name: Run for ${{ matrix.target.name }}
run: ./badgemagic.${{ matrix.target.target }}${{ matrix.target.ext }} --help
- uses: actions/upload-artifact@v4
with:
name: badgemagic.${{ matrix.target.target }}${{ matrix.target.ext }}
path: badgemagic.${{ matrix.target.target }}${{ matrix.target.ext }}
if-no-files-found: error
ready:
name: All required checks passed
needs:
- format
- test
- build
runs-on: ubuntu-latest
steps:
- run: date
release:
name: Create release
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
permissions:
contents: write
needs:
- format
- test
- build
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/download-artifact@v4
with:
pattern: badgemagic.*
merge-multiple: true
- name: List artifacts
run: find -exec ls -ld {} +
- uses: actions/github-script@v7
id: upload-release-asset
with:
script: |
const fs = require('fs');
const { env } = process;
const { data: release } = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `commit-${env.GITHUB_SHA.slice(0, 7)}`,
target_commitish: env.GITHUB_SHA,
draft: true,
generate_release_notes: true,
});
console.log('release:', release.id);
const artifacts = fs.readdirSync('.');
console.log('artifacts:', artifacts);
for (const name of artifacts) {
const data = fs.readFileSync(name);
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.id,
name,
data,
});
}
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.id,
draft: false,
});