-
Notifications
You must be signed in to change notification settings - Fork 9
134 lines (120 loc) · 4.29 KB
/
release.yml
File metadata and controls
134 lines (120 loc) · 4.29 KB
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
name: Release
on:
workflow_run:
workflows: ["Quality Check"]
branches: [main]
types: [completed]
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
release-plz:
if: ${{ github.repository_owner == 'drivercraft' && (github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success') }}
runs-on: ubuntu-22.04
steps:
- &checkout
name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- &install-rust
name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- &setup-libudenv
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: libudev-dev
version: 1.0
- name: Release with release-plz
uses: release-plz/action@v0.5
with:
command: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
# Create a PR with the new versions and changelog, preparing the next release.
release-plz-pr:
name: Release-plz PR
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
concurrency:
group: release-plz-${{ github.ref }}
cancel-in-progress: false
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- *install-rust
- *setup-libudenv
- name: Run release-plz
uses: release-plz/action@v0.5
with:
command: release-pr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
build-binaries:
needs: release-plz
if: ${{ needs.release-plz.result == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-unknown-linux-gnu
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y libudev-dev
- name: Cache cargo
uses: Swatinem/rust-cache@v2
- name: Compute version and tag
id: meta
run: |
version=$(grep -m1 '^version' ostool/Cargo.toml | sed -E 's/version = "([^"]+)"/\1/')
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "tag=ostool-v$version" >> "$GITHUB_OUTPUT"
echo "target=x86_64-unknown-linux-gnu" >> "$GITHUB_OUTPUT"
- name: Check release exists
id: release_check
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if gh release view "${{ steps.meta.outputs.tag }}" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Build binaries
if: steps.release_check.outputs.exists == 'true'
run: |
cargo build --release -p ostool --bin ostool --target ${{ steps.meta.outputs.target }}
cargo build --release -p ostool --bin cargo-osrun --target ${{ steps.meta.outputs.target }}
- name: Package artifacts
if: steps.release_check.outputs.exists == 'true'
run: |
version="${{ steps.meta.outputs.version }}"
target="${{ steps.meta.outputs.target }}"
dist="dist/ostool-${target}-v${version}"
mkdir -p "$dist"
cp "target/${target}/release/ostool" "$dist/"
cp "target/${target}/release/cargo-osrun" "$dist/"
tar -czf "ostool-${target}-v${version}.tar.gz" -C dist "ostool-${target}-v${version}"
sha256sum "ostool-${target}-v${version}.tar.gz" > "ostool-${target}-v${version}.tar.gz.sha256"
- name: Upload release assets
if: steps.release_check.outputs.exists == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
version="${{ steps.meta.outputs.version }}"
target="${{ steps.meta.outputs.target }}"
tag="${{ steps.meta.outputs.tag }}"
gh release upload "$tag" \
"ostool-${target}-v${version}.tar.gz" \
"ostool-${target}-v${version}.tar.gz.sha256" \
--clobber