-
Notifications
You must be signed in to change notification settings - Fork 2
221 lines (189 loc) · 5.95 KB
/
release.yml
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
name: Release
on:
push:
tags:
- 'v*'
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
RUSTUP_MAX_RETRIES: 10
RUST_BACKTRACE: short
PKG_CONFIG_ALLOW_CROSS: 1
jobs:
# First run the same checks as in CI
check:
name: Check
uses: ./.github/workflows/ci.yml
build-deb:
name: Build Debian Package
needs: check
runs-on: ubuntu-latest
strategy:
matrix:
target:
- armv7-unknown-linux-gnueabihf
- aarch64-unknown-linux-gnu
- x86_64-unknown-linux-gnu
include:
- target: armv7-unknown-linux-gnueabihf
arch: armhf
- target: aarch64-unknown-linux-gnu
arch: arm64
- target: x86_64-unknown-linux-gnu
arch: amd64
steps:
- uses: actions/checkout@v4
- name: Install common dependencies
run: |
sudo apt-get update
sudo apt-get install -y pkg-config
- name: Install target specific dependencies
if: matrix.target == 'x86_64-unknown-linux-gnu'
run: |
sudo apt-get install -y libudev-dev
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross
uses: taiki-e/install-action@cross
- name: Cache cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-${{ matrix.target }}-
- name: Cache cross
uses: actions/cache@v3
if: matrix.target != 'x86_64-unknown-linux-gnu'
with:
path: ~/.cargo/.cross
key: ${{ runner.os }}-cross-${{ matrix.target }}-${{ hashFiles('Cross.toml') }}
restore-keys: |
${{ runner.os }}-cross-${{ matrix.target }}-
- name: Install cargo-deb
run: cargo install cargo-deb
- name: Build
run: |
if [ "${{ matrix.target }}" = "x86_64-unknown-linux-gnu" ]; then
cargo build --release --target ${{ matrix.target }}
else
cross build --release --target ${{ matrix.target }}
fi
- name: Build deb package
run: cargo deb --target ${{ matrix.target }}
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: deb-${{ matrix.arch }}
path: target/${{ matrix.target }}/debian/*.deb
build-arch:
name: Build Arch Package
needs: check
runs-on: ubuntu-latest
strategy:
matrix:
target:
- x86_64-unknown-linux-gnu
- aarch64-unknown-linux-gnu
- armv7-unknown-linux-gnueabihf
include:
- target: x86_64-unknown-linux-gnu
arch: x86_64
- target: aarch64-unknown-linux-gnu
arch: aarch64
- target: armv7-unknown-linux-gnueabihf
arch: armv7h
container:
image: archlinux:base-devel
options: --privileged
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
# Update system
pacman -Syu --noconfirm
# Install common dependencies
pacman -S --noconfirm \
git \
rustup \
cargo \
pkg-config \
libudev \
systemd
- name: Setup Rust
run: |
rustup default stable
rustup target add ${{ matrix.target }}
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross
uses: taiki-e/install-action@cross
- name: Cache cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-arch-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-arch-cargo-${{ matrix.target }}-
- name: Cache cross
uses: actions/cache@v3
if: matrix.target != 'x86_64-unknown-linux-gnu'
with:
path: ~/.cargo/.cross
key: ${{ runner.os }}-arch-cross-${{ matrix.target }}-${{ hashFiles('Cross.arch.toml') }}
restore-keys: |
${{ runner.os }}-arch-cross-${{ matrix.target }}-
- name: Build
env:
CROSS_CONFIG: Cross.arch.toml
run: |
if [ "${{ matrix.target }}" = "x86_64-unknown-linux-gnu" ]; then
cargo build --release --target ${{ matrix.target }}
else
cross build --release --target ${{ matrix.target }}
fi
- name: Prepare PKGBUILD
run: |
VERSION=$(grep -m1 'version =' Cargo.toml | cut -d '"' -f2)
sed -i "s/pkgver=.*/pkgver=$VERSION/" dist/arch/PKGBUILD
cp -r . "/tmp/modbus-relay"
cd /tmp
tar czf "modbus-relay.tar.gz" "modbus-relay"
- name: Build package
run: |
cd /tmp
mkdir -p pkg
cd pkg
mv ../modbus-relay.tar.gz .
cp /tmp/modbus-relay/dist/arch/PKGBUILD .
CARCH=${{ matrix.arch }} makepkg -s --noconfirm
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: pkg-${{ matrix.arch }}
path: /tmp/pkg/*.pkg.tar.zst
create-release:
name: Create Release
needs: [build-deb, build-arch]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: deb-*/*.deb pkg-*/*.pkg.tar.zst
generate_release_notes: true