Skip to content

Commit 68c156b

Browse files
authored
GitHub Actions to build and release (carlossless#4)
* test workflow * install musl tools * remove musl builds * yml adjustment * generate release notes * action version update * allow writting
1 parent f440d72 commit 68c156b

File tree

2 files changed

+128
-12
lines changed

2 files changed

+128
-12
lines changed

.github/workflows/push.yml

Lines changed: 122 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,129 @@
1-
on: [push]
1+
name: Test & Build
22

3-
name: CI
3+
on: [push, pull_request]
4+
5+
env:
6+
CARGO_TERM_COLOR: always
7+
8+
defaults:
9+
run:
10+
# necessary for windows
11+
shell: bash
412

513
jobs:
6-
build_and_test:
7-
name: Rust project
14+
test:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
- name: Cargo cache
19+
uses: actions/cache@v3
20+
with:
21+
path: |
22+
~/.cargo/registry
23+
./target
24+
key: test-cargo-registry
25+
- name: List
26+
run: find ./
27+
- name: Run tests
28+
run: cargo test --verbose
29+
30+
build:
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
include:
35+
- TARGET: x86_64-unknown-linux-gnu
36+
OS: ubuntu-latest
37+
- TARGET: aarch64-unknown-linux-gnu
38+
OS: ubuntu-latest
39+
- TARGET: armv7-unknown-linux-gnueabihf
40+
OS: ubuntu-latest
41+
- TARGET: arm-unknown-linux-gnueabihf
42+
OS: ubuntu-latest
43+
- TARGET: x86_64-apple-darwin
44+
OS: macos-latest
45+
- TARGET: x86_64-pc-windows-msvc
46+
OS: windows-latest
47+
needs: test
48+
runs-on: ${{ matrix.OS }}
49+
env:
50+
NAME: sinowealth-kb-tool
51+
TARGET: ${{ matrix.TARGET }}
52+
OS: ${{ matrix.OS }}
53+
steps:
54+
- uses: actions/checkout@v3
55+
- name: Cargo cache
56+
uses: actions/cache@v3
57+
with:
58+
path: |
59+
~/.cargo/registry
60+
./target
61+
key: build-cargo-registry-${{matrix.TARGET}}
62+
- name: List
63+
run: find ./
64+
- name: Install and configure dependencies
65+
run: |
66+
# dependencies are only needed on ubuntu as that's the only place where
67+
# we make cross-compilation
68+
if [[ $OS =~ ^ubuntu.*$ ]]; then
69+
sudo apt-get install -qq crossbuild-essential-arm64 crossbuild-essential-armhf
70+
fi
71+
72+
# some additional configuration for cross-compilation on linux
73+
cat >>~/.cargo/config <<EOF
74+
[target.aarch64-unknown-linux-gnu]
75+
linker = "aarch64-linux-gnu-gcc"
76+
[target.armv7-unknown-linux-gnueabihf]
77+
linker = "arm-linux-gnueabihf-gcc"
78+
[target.arm-unknown-linux-gnueabihf]
79+
linker = "arm-linux-gnueabihf-gcc"
80+
EOF
81+
- name: Install rust target
82+
run: rustup target add $TARGET
83+
- name: Run build
84+
run: cargo build --release --verbose --target $TARGET
85+
- name: List target
86+
run: find ./target
87+
- name: Compress
88+
run: |
89+
mkdir -p ./artifacts
90+
# windows is the only OS using a different convention for executable file name
91+
if [[ $OS =~ ^windows.*$ ]]; then
92+
EXEC=$NAME.exe
93+
else
94+
EXEC=$NAME
95+
fi
96+
if [[ $GITHUB_REF_TYPE =~ ^tag$ ]]; then
97+
TAG=$GITHUB_REF_NAME
98+
else
99+
TAG=$GITHUB_SHA
100+
fi
101+
mv ./target/$TARGET/release/$EXEC ./$EXEC
102+
tar -czf ./artifacts/$NAME-$TARGET-$TAG.tar.gz $EXEC
103+
- name: Archive artifact
104+
uses: actions/upload-artifact@v3
105+
with:
106+
name: result
107+
path: |
108+
./artifacts
109+
110+
deploy:
111+
if: startsWith(github.ref, 'refs/tags/v')
112+
needs: build
8113
runs-on: ubuntu-latest
114+
permissions:
115+
contents: write
9116
steps:
10-
- uses: actions/checkout@v2
11-
- name: Install libudev
12-
run: sudo apt-get install -y libudev-dev
13-
- uses: actions-rs/toolchain@v1
117+
- name: Download artifacts
118+
uses: actions/download-artifact@v3
14119
with:
15-
toolchain: stable
16-
- uses: actions-rs/cargo@v1
120+
name: result
121+
path: ./artifacts
122+
- name: List
123+
run: find ./artifacts
124+
- name: Release
125+
uses: softprops/action-gh-release@v1
17126
with:
18-
command: build
19-
args: --release --all-features
127+
draft: true
128+
generate_release_notes: true
129+
files: ./artifacts/*.tar.gz

src/part.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub const PART_RE_K70_BYK800: Part = Part {
3434

3535
pub static PARTS: phf::Map<&'static str, Part> = phf_map! {
3636
"nuphy-air60" => PART_NUPHY_AIR60,
37+
"nuphy-halo65" => PART_NUPHY_AIR60, // same as nuphy-air60
3738
"xinmeng-k916" => PART_XINMENG_K916,
3839
"re-k70-byk800" => PART_RE_K70_BYK800,
3940
};
@@ -43,3 +44,8 @@ impl Part {
4344
return self.flash_size / self.page_size;
4445
}
4546
}
47+
48+
#[test]
49+
fn test_num_pages() {
50+
assert_eq!(PART_NUPHY_AIR60.num_pages(), 30)
51+
}

0 commit comments

Comments
 (0)