Skip to content

Commit 0b4e744

Browse files
authored
feat: 添加发布工作流和更新 Cargo.toml 配置以支持二进制包格式 (#30)
1 parent b34a16a commit 0b4e744

2 files changed

Lines changed: 104 additions & 2 deletions

File tree

.github/workflows/release.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Release
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Quality Check"]
6+
branches: [main]
7+
types: [completed]
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: write
12+
pull-requests: write
13+
14+
jobs:
15+
release-plz:
16+
if: ${{ github.repository_owner == 'drivercraft' && (github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success') }}
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Release with release-plz
23+
uses: release-plz/action@v0.5
24+
with:
25+
command: release
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
29+
30+
build-binaries:
31+
needs: release-plz
32+
if: ${{ needs.release-plz.result == 'success' }}
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Checkout code
36+
uses: actions/checkout@v4
37+
38+
- name: Install Rust toolchain
39+
uses: dtolnay/rust-toolchain@stable
40+
with:
41+
targets: x86_64-unknown-linux-gnu
42+
43+
- name: Install dependencies
44+
run: sudo apt-get update && sudo apt-get install -y libudev-dev
45+
46+
- name: Cache cargo
47+
uses: Swatinem/rust-cache@v2
48+
49+
- name: Compute version and tag
50+
id: meta
51+
run: |
52+
version=$(grep -m1 '^version' ostool/Cargo.toml | sed -E 's/version = "([^"]+)"/\1/')
53+
echo "version=$version" >> "$GITHUB_OUTPUT"
54+
echo "tag=ostool-v$version" >> "$GITHUB_OUTPUT"
55+
echo "target=x86_64-unknown-linux-gnu" >> "$GITHUB_OUTPUT"
56+
57+
- name: Check release exists
58+
id: release_check
59+
env:
60+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
run: |
62+
if gh release view "${{ steps.meta.outputs.tag }}" >/dev/null 2>&1; then
63+
echo "exists=true" >> "$GITHUB_OUTPUT"
64+
else
65+
echo "exists=false" >> "$GITHUB_OUTPUT"
66+
fi
67+
68+
- name: Build binaries
69+
if: steps.release_check.outputs.exists == 'true'
70+
run: |
71+
cargo build --release -p ostool --bin ostool --target ${{ steps.meta.outputs.target }}
72+
cargo build --release -p ostool --bin cargo-osrun --target ${{ steps.meta.outputs.target }}
73+
74+
- name: Package artifacts
75+
if: steps.release_check.outputs.exists == 'true'
76+
run: |
77+
version="${{ steps.meta.outputs.version }}"
78+
target="${{ steps.meta.outputs.target }}"
79+
dist="dist/ostool-${target}-v${version}"
80+
mkdir -p "$dist"
81+
cp "target/${target}/release/ostool" "$dist/"
82+
cp "target/${target}/release/cargo-osrun" "$dist/"
83+
tar -czf "ostool-${target}-v${version}.tar.gz" -C dist "ostool-${target}-v${version}"
84+
sha256sum "ostool-${target}-v${version}.tar.gz" > "ostool-${target}-v${version}.tar.gz.sha256"
85+
86+
- name: Upload release assets
87+
if: steps.release_check.outputs.exists == 'true'
88+
env:
89+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
90+
run: |
91+
version="${{ steps.meta.outputs.version }}"
92+
target="${{ steps.meta.outputs.target }}"
93+
tag="${{ steps.meta.outputs.tag }}"
94+
gh release upload "$tag" \
95+
"ostool-${target}-v${version}.tar.gz" \
96+
"ostool-${target}-v${version}.tar.gz.sha256" \
97+
--clobber

ostool/Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ readme = "../README.md"
1111
repository = "https://github.com/ZR233/ostool"
1212
version = "0.8.9"
1313

14+
[package.metadata.binstall]
15+
bin-dir = "{ name }-{ target }-v{ version }/{ bin }{ binary-ext }"
16+
pkg-fmt = "tgz"
17+
pkg-url = "{ repo }/releases/download/{ name }-v{ version }/{ name }-{ target }-v{ version }{ archive-suffix }"
18+
1419
[[bin]]
1520
name = "ostool"
1621
path = "src/main.rs"
@@ -24,14 +29,15 @@ ui-log = ["jkconfig/logging"]
2429

2530
[dependencies]
2631
anyhow = {workspace = true, features = ["backtrace"]}
27-
futures = "0.3"
2832
byte-unit = "5.1"
2933
cargo_metadata = "0.23"
3034
clap = {workspace = true, features = ["derive"]}
3135
colored = "3"
3236
crossterm = {workspace = true}
3337
cursive = {workspace = true, features = ["crossterm-backend"]}
3438
env_logger = {workspace = true}
39+
fitimage = {version = "0.1", path = "../fitimage"}
40+
futures = "0.3"
3541
indicatif = "0.18"
3642
jkconfig = {version = "0.1", path = "../jkconfig"}
3743
log = {workspace = true}
@@ -47,7 +53,6 @@ tftpd = "0.5"
4753
tokio = {workspace = true, features = ["full"]}
4854
toml = {workspace = true}
4955
uboot-shell = {version = "0.2", path = "../uboot-shell"}
50-
fitimage = {version = "0.1", path = "../fitimage"}
5156

5257
lzma-rs = "0.3"
5358
regex = "1"

0 commit comments

Comments
 (0)