Skip to content

Commit 8a885c7

Browse files
committed
Enable CI workflow
Fixes #1
1 parent 97d5561 commit 8a885c7

File tree

1 file changed

+170
-0
lines changed

1 file changed

+170
-0
lines changed

.github/workflows/ci.yaml

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
name: CI
2+
3+
on:
4+
- push
5+
- pull_request
6+
- workflow_dispatch
7+
8+
permissions:
9+
contents: read
10+
11+
env:
12+
CARGO_INCREMENTAL: 0
13+
CARGO_TERM_COLOR: always
14+
RUSTFLAGS: -C link-arg=-s
15+
16+
jobs:
17+
format:
18+
name: Check rust format
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 45
21+
steps:
22+
- uses: actions/checkout@v4
23+
- name: Setup rust
24+
run: |
25+
rustup toolchain install nightly --profile minimal --component rustfmt --no-self-update
26+
- name: Run cargo fmt
27+
run: cargo +nightly fmt --check
28+
29+
test:
30+
name: ${{ matrix.cmd.name }} (Rust ${{ matrix.rust }}) ${{ matrix.features }}
31+
runs-on: ubuntu-latest
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
rust:
36+
- stable
37+
features:
38+
- --no-default-features
39+
-
40+
- -F cli
41+
cmd:
42+
- name: Test
43+
run: cargo test --locked
44+
- name: Clippy
45+
run: cargo clippy --locked --tests
46+
run2: -D warnings
47+
timeout-minutes: 45
48+
steps:
49+
- uses: actions/checkout@v4
50+
- name: Setup rust
51+
run: |
52+
rustup toolchain install ${{ matrix.rust }} --profile minimal --no-self-update
53+
- name: Install build dependencies
54+
run: sudo apt-get install -y libudev-dev
55+
- name: ${{ matrix.cmd.name }}
56+
run: ${{ matrix.cmd.run }} ${{ matrix.features }} -- ${{ matrix.cmd.run2 }}
57+
58+
build:
59+
name: Build for ${{ matrix.target.name }}
60+
runs-on: ${{ matrix.target.runs-on }}
61+
strategy:
62+
fail-fast: false
63+
matrix:
64+
target:
65+
- name: Linux (x86_64)
66+
runs-on: ubuntu-latest
67+
target: x86_64-unknown-linux-gnu
68+
pre-build: |
69+
sudo apt-get install -y libudev-dev
70+
- name: Windows (x86_64)
71+
runs-on: windows-latest
72+
target: x86_64-pc-windows-msvc
73+
ext: .exe
74+
- name: MacOS (x86_64)
75+
runs-on: macos-latest
76+
target: x86_64-apple-darwin
77+
- name: MacOS (arm64)
78+
runs-on: macos-latest
79+
target: aarch64-apple-darwin
80+
timeout-minutes: 45
81+
# env:
82+
# RUSTFLAGS: -C target-feature=+crt-static
83+
steps:
84+
- uses: actions/checkout@v4
85+
- name: Setup rust
86+
run: |
87+
rustup toolchain install stable --target ${{ matrix.target.target }} --profile minimal --no-self-update
88+
- name: Install build dependencies
89+
run: ${{ matrix.target.pre-build }}
90+
if: matrix.target.pre-build
91+
- name: Build for ${{ matrix.target.name }}
92+
run: cargo build --locked --release --target ${{ matrix.target.target }} --no-default-features -F cli
93+
- name: Check file
94+
run: |
95+
file target/${{ matrix.target.target }}/release/badgemagic${{ matrix.target.ext }}
96+
stat target/${{ matrix.target.target }}/release/badgemagic${{ matrix.target.ext }}
97+
mv target/${{ matrix.target.target }}/release/badgemagic${{ matrix.target.ext }} badgemagic.${{ matrix.target.target }}${{ matrix.target.ext }}
98+
- name: Run for ${{ matrix.target.name }}
99+
run: ./badgemagic.${{ matrix.target.target }}${{ matrix.target.ext }} --help
100+
- uses: actions/upload-artifact@v4
101+
with:
102+
name: badgemagic.${{ matrix.target.target }}${{ matrix.target.ext }}
103+
path: badgemagic.${{ matrix.target.target }}${{ matrix.target.ext }}
104+
if-no-files-found: error
105+
106+
ready:
107+
name: All required checks passed
108+
needs:
109+
- format
110+
- test
111+
- build
112+
runs-on: ubuntu-latest
113+
steps:
114+
- run: date
115+
116+
release:
117+
name: Create release
118+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
119+
permissions:
120+
contents: write
121+
needs:
122+
- format
123+
- test
124+
- build
125+
runs-on: ubuntu-latest
126+
timeout-minutes: 45
127+
steps:
128+
- uses: actions/download-artifact@v4
129+
with:
130+
pattern: badgemagic.*
131+
merge-multiple: true
132+
- name: List artifacts
133+
run: find -exec ls -ld {} +
134+
- uses: actions/github-script@v7
135+
id: upload-release-asset
136+
with:
137+
script: |
138+
const fs = require('fs');
139+
const { env } = process;
140+
141+
const { data: release } = await github.rest.repos.createRelease({
142+
owner: context.repo.owner,
143+
repo: context.repo.repo,
144+
tag_name: `commit-${env.GITHUB_SHA.slice(0, 7)}`,
145+
target_commitish: env.GITHUB_SHA,
146+
draft: true,
147+
generate_release_notes: true,
148+
});
149+
console.log('release:', release.id);
150+
151+
const artifacts = fs.readdirSync('.');
152+
console.log('artifacts:', artifacts);
153+
154+
for (const name of artifacts) {
155+
const data = fs.readFileSync(name);
156+
await github.rest.repos.uploadReleaseAsset({
157+
owner: context.repo.owner,
158+
repo: context.repo.repo,
159+
release_id: release.id,
160+
name,
161+
data,
162+
});
163+
}
164+
165+
await github.rest.repos.updateRelease({
166+
owner: context.repo.owner,
167+
repo: context.repo.repo,
168+
release_id: release.id,
169+
draft: false,
170+
});

0 commit comments

Comments
 (0)