Skip to content

Commit d5a0367

Browse files
committed
add build
1 parent 8f0d1ef commit d5a0367

1 file changed

Lines changed: 255 additions & 0 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
name: Build
2+
3+
# from https://github.com/sharkdp/fd
4+
5+
env:
6+
CICD_INTERMEDIATES_DIR: "_cicd-intermediates"
7+
MSRV_FEATURES: "--all-features"
8+
9+
on:
10+
workflow_dispatch:
11+
push:
12+
13+
permissions:
14+
contents: write
15+
16+
jobs:
17+
crate_metadata:
18+
name: Extract crate metadata
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Extract crate information
23+
id: crate_metadata
24+
run: |
25+
cargo metadata --no-deps --format-version 1 | jq -r '"name=" + .packages[0].name' | tee -a $GITHUB_OUTPUT
26+
cargo metadata --no-deps --format-version 1 | jq -r '"version=" + .packages[0].version' | tee -a $GITHUB_OUTPUT
27+
cargo metadata --no-deps --format-version 1 | jq -r '"maintainer=" + .packages[0].authors[0]' | tee -a $GITHUB_OUTPUT
28+
cargo metadata --no-deps --format-version 1 | jq -r '"homepage=" + .packages[0].homepage' | tee -a $GITHUB_OUTPUT
29+
cargo metadata --no-deps --format-version 1 | jq -r '"msrv=" + .packages[0].rust_version' | tee -a $GITHUB_OUTPUT
30+
outputs:
31+
name: ${{ steps.crate_metadata.outputs.name }}
32+
version: ${{ steps.crate_metadata.outputs.version }}
33+
maintainer: ${{ steps.crate_metadata.outputs.maintainer }}
34+
homepage: ${{ steps.crate_metadata.outputs.homepage }}
35+
msrv: ${{ steps.crate_metadata.outputs.msrv }}
36+
37+
ensure_cargo_fmt:
38+
name: Ensure 'cargo fmt' has been run
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: dtolnay/rust-toolchain@stable
42+
with:
43+
components: rustfmt
44+
- uses: actions/checkout@v4
45+
- run: cargo fmt -- --check
46+
47+
lint_check:
48+
name: Ensure 'cargo clippy' has no warnings
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: dtolnay/rust-toolchain@stable
52+
with:
53+
components: clippy
54+
- uses: actions/checkout@v4
55+
- run: cargo clippy --all-targets --all-features -- -A warnings
56+
57+
min_version:
58+
name: Minimum supported rust version
59+
runs-on: ubuntu-latest
60+
needs: crate_metadata
61+
steps:
62+
- name: Checkout source code
63+
uses: actions/checkout@v4
64+
65+
- name: Install rust toolchain (v${{ needs.crate_metadata.outputs.msrv }})
66+
uses: dtolnay/rust-toolchain@master
67+
with:
68+
toolchain: ${{ needs.crate_metadata.outputs.msrv }}
69+
components: clippy
70+
- name: Run clippy (on minimum supported rust version to prevent warnings we can't fix)
71+
run: cargo clippy --locked --all-targets ${{ env.MSRV_FEATURES }}
72+
- name: Run tests
73+
run: cargo test --locked ${{ env.MSRV_FEATURES }}
74+
75+
build:
76+
name: ${{ matrix.job.target }} (${{ matrix.job.os }})
77+
runs-on: ${{ matrix.job.os }}
78+
needs: crate_metadata
79+
strategy:
80+
fail-fast: false
81+
matrix:
82+
job:
83+
- {
84+
target: aarch64-unknown-linux-gnu,
85+
os: ubuntu-24.04,
86+
use-cross: true,
87+
}
88+
- {
89+
target: aarch64-unknown-linux-musl,
90+
os: ubuntu-24.04,
91+
use-cross: true,
92+
}
93+
- {
94+
target: arm-unknown-linux-gnueabihf,
95+
os: ubuntu-24.04,
96+
use-cross: true,
97+
}
98+
- {
99+
target: arm-unknown-linux-musleabihf,
100+
os: ubuntu-24.04,
101+
use-cross: true,
102+
}
103+
- {
104+
target: i686-unknown-linux-gnu,
105+
os: ubuntu-24.04,
106+
use-cross: true,
107+
}
108+
- {
109+
target: i686-unknown-linux-musl,
110+
os: ubuntu-24.04,
111+
use-cross: true,
112+
}
113+
- {
114+
target: x86_64-unknown-linux-gnu,
115+
os: ubuntu-24.04,
116+
use-cross: true,
117+
}
118+
- {
119+
target: x86_64-unknown-linux-musl,
120+
os: ubuntu-24.04,
121+
use-cross: true,
122+
}
123+
- { target: x86_64-apple-darwin, os: macos-13 }
124+
- { target: aarch64-apple-darwin, os: macos-14 }
125+
- { target: i686-pc-windows-msvc, os: windows-2022 }
126+
- { target: x86_64-pc-windows-gnu, os: windows-2022 }
127+
- { target: x86_64-pc-windows-msvc, os: windows-2022 }
128+
env:
129+
BUILD_CMD: cargo
130+
steps:
131+
- name: Checkout source code
132+
uses: actions/checkout@v4
133+
134+
- name: Install prerequisites
135+
shell: bash
136+
run: |
137+
case ${{ matrix.job.target }} in
138+
arm-unknown-linux-*) sudo apt-get -y update ; sudo apt-get -y install gcc-arm-linux-gnueabihf ;;
139+
aarch64-unknown-linux-gnu) sudo apt-get -y update ; sudo apt-get -y install gcc-aarch64-linux-gnu ;;
140+
esac
141+
142+
- name: Install Rust toolchain
143+
uses: dtolnay/rust-toolchain@stable
144+
with:
145+
targets: ${{ matrix.job.target }}
146+
toolchain: "stable"
147+
148+
- name: Install cross
149+
if: matrix.job.use-cross
150+
uses: taiki-e/install-action@v2
151+
with:
152+
tool: cross
153+
154+
- name: Overwrite build command env variable
155+
if: matrix.job.use-cross
156+
shell: bash
157+
run: echo "BUILD_CMD=cross" >> $GITHUB_ENV
158+
159+
- name: Show version information (Rust, cargo, GCC)
160+
shell: bash
161+
run: |
162+
gcc --version || true
163+
rustup -V
164+
rustup toolchain list
165+
rustup default
166+
rustup target add ${{ matrix.job.target }}
167+
cargo -V
168+
rustc -V
169+
170+
- name: Build
171+
shell: bash
172+
run: $BUILD_CMD build --locked --release --target=${{ matrix.job.target }}
173+
174+
- name: Set binary name & path
175+
id: bin
176+
shell: bash
177+
run: |
178+
# Figure out suffix of binary
179+
EXE_suffix=""
180+
case ${{ matrix.job.target }} in
181+
*-pc-windows-*) EXE_suffix=".exe" ;;
182+
esac;
183+
184+
# Setup paths
185+
BIN_NAME="${{ needs.crate_metadata.outputs.name }}${EXE_suffix}"
186+
BIN_PATH="target/${{ matrix.job.target }}/release/${BIN_NAME}"
187+
188+
# Let subsequent steps know where to find the binary
189+
echo "BIN_PATH=${BIN_PATH}" >> $GITHUB_OUTPUT
190+
echo "BIN_NAME=${BIN_NAME}" >> $GITHUB_OUTPUT
191+
192+
- name: Create tarball
193+
id: package
194+
shell: bash
195+
run: |
196+
PKG_suffix=".tar.gz" ; case ${{ matrix.job.target }} in *-pc-windows-*) PKG_suffix=".zip" ;; esac;
197+
PKG_BASENAME=${{ needs.crate_metadata.outputs.name }}-v${{ needs.crate_metadata.outputs.version }}-${{ matrix.job.target }}
198+
PKG_NAME=${PKG_BASENAME}${PKG_suffix}
199+
echo "PKG_NAME=${PKG_NAME}" >> $GITHUB_OUTPUT
200+
201+
PKG_STAGING="${{ env.CICD_INTERMEDIATES_DIR }}/package"
202+
ARCHIVE_DIR="${PKG_STAGING}/${PKG_BASENAME}/"
203+
mkdir -p "${ARCHIVE_DIR}"
204+
205+
# Binary
206+
cp "${{ steps.bin.outputs.BIN_PATH }}" "$ARCHIVE_DIR"
207+
208+
# README, LICENSE and CHANGELOG files
209+
cp "README.md" "LICENSE" "CHANGELOG.md" "$ARCHIVE_DIR"
210+
211+
# Man page
212+
#cp 'doc/${{ needs.crate_metadata.outputs.name }}.1' "$ARCHIVE_DIR"
213+
214+
# Autocompletion files
215+
#cp -r autocomplete "${ARCHIVE_DIR}"
216+
217+
# base compressed package
218+
pushd "${PKG_STAGING}/" >/dev/null
219+
case ${{ matrix.job.target }} in
220+
*-pc-windows-*) 7z -y a "${PKG_NAME}" "${PKG_BASENAME}"/* | tail -2 ;;
221+
*) tar czf "${PKG_NAME}" "${PKG_BASENAME}"/* ;;
222+
esac;
223+
popd >/dev/null
224+
225+
# Let subsequent steps know where to find the compressed package
226+
echo "PKG_PATH=${PKG_STAGING}/${PKG_NAME}" >> $GITHUB_OUTPUT
227+
228+
# - name: Create Debian package
229+
# id: debian-package
230+
# shell: bash
231+
# if: startsWith(matrix.job.os, 'ubuntu')
232+
# run: bash scripts/create-deb.sh
233+
# env:
234+
# TARGET: ${{ matrix.job.target }}
235+
# DPKG_VERSION: ${{ needs.crate_metadata.version }}
236+
# BIN_PATH: ${{ steps.bin.outputs.BIN_PATH }}
237+
238+
- name: "Artifact upload: tarball"
239+
uses: actions/upload-artifact@master
240+
with:
241+
name: ${{ steps.package.outputs.PKG_NAME }}
242+
path: ${{ steps.package.outputs.PKG_PATH }}
243+
244+
# - name: "Artifact upload: Debian package"
245+
# uses: actions/upload-artifact@master
246+
# if: steps.debian-package.outputs.DPKG_NAME
247+
# with:
248+
# name: ${{ steps.debian-package.outputs.DPKG_NAME }}
249+
# path: ${{ steps.debian-package.outputs.DPKG_PATH }}
250+
251+
- name: Publish archives and packages
252+
uses: softprops/action-gh-release@v2
253+
with:
254+
files: |
255+
${{ steps.package.outputs.PKG_PATH }}

0 commit comments

Comments
 (0)