-
Notifications
You must be signed in to change notification settings - Fork 0
159 lines (137 loc) · 5.02 KB
/
build.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
name: build
on:
workflow_dispatch:
push:
branches:
- trunk
tags:
- "v*"
pull_request:
branches:
- trunk
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true
jobs:
crate_metadata:
name: Extract crate metadata
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Extract crate information
id: crate_metadata
run: |
cargo metadata --no-deps --format-version 1 | jq -r '"name=" + .packages[0].name' | tee -a $GITHUB_OUTPUT
cargo metadata --no-deps --format-version 1 | jq -r '"version=" + .packages[0].version' | tee -a $GITHUB_OUTPUT
outputs:
name: ${{ steps.crate_metadata.outputs.name }}
version: ${{ steps.crate_metadata.outputs.version }}
format_check:
name: Check formatting
runs-on: ubuntu-latest
steps:
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- uses: actions/checkout@v4
- run: cargo fmt -- --check
lint_check:
name: Check clippy warnings
runs-on: ubuntu-latest
steps:
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: actions/checkout@v4
- run: cargo clippy --all-targets --all-features -- -Dwarnings
build:
name: ${{ matrix.job.target }}
runs-on: ${{ matrix.job.os }}
needs: crate_metadata
strategy:
fail-fast: false
matrix:
job:
- { target: i686-pc-windows-msvc, os: windows-latest }
- { target: x86_64-pc-windows-msvc, os: windows-latest }
- { target: aarch64-apple-darwin, os: macos-latest }
- { target: x86_64-unknown-linux-gnu, os: ubuntu-latest }
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.job.target }}
toolchain: nightly
components: rust-src
- name: Build
shell: bash
run: cargo build --locked --profile=release-lto --target=${{ matrix.job.target }}
- name: Run tests
shell: bash
run: cargo test --locked --target=${{ matrix.job.target }}
- name: Set up package directory
id: package_dir
shell: bash
run: |
EXE_SUFFIX=""
PKG_SUFFIX=".tar.gz"
case "${{ matrix.job.target }}" in
*-pc-windows-*)
EXE_SUFFIX=".exe"
PKG_SUFFIX=".zip"
;;
esac
BIN_NAME=${{ needs.crate_metadata.outputs.name }}${EXE_SUFFIX}
BIN_PATH=target/${{ matrix.job.target }}/release-lto/${BIN_NAME}
PKG_BASENAME=${{ needs.crate_metadata.outputs.name }}-v${{ needs.crate_metadata.outputs.version }}-${{ matrix.job.target }}
PKG_NAME=${PKG_BASENAME}${PKG_SUFFIX}
PKG_BASEDIR=packages
PKG_DIR=${PKG_BASEDIR}/${PKG_BASENAME}
mkdir -p "${PKG_DIR}"
echo "bin_path=${BIN_PATH}" >> $GITHUB_OUTPUT
echo "pkg_basename=${PKG_BASENAME}" >> $GITHUB_OUTPUT
echo "pkg_name=${PKG_NAME}" >> $GITHUB_OUTPUT
echo "pkg_basedir=${PKG_BASEDIR}" >> $GITHUB_OUTPUT
echo "pkg_dir=${PKG_DIR}" >> $GITHUB_OUTPUT
- name: Collect dependency information
shell: bash
run: |
python3 -m venv myenv
case "${{ matrix.job.target }}" in
*-pc-windows-*) source myenv/Scripts/activate ;;
*) source myenv/bin/activate ;;
esac
python3 -m pip install license-expression
cargo metadata --format-version=1 \
| python3 scripts/collect-dependencies.py \
-p ${{ needs.crate_metadata.outputs.name }} \
-o ${{ steps.package_dir.outputs.pkg_dir }}/DEPENDENCIES.md
- name: Create release package
id: package
shell: bash
run: |
BIN_PATH="${{ steps.package_dir.outputs.bin_path }}"
PKG_BASENAME="${{ steps.package_dir.outputs.pkg_basename }}"
PKG_NAME="${{ steps.package_dir.outputs.pkg_name }}"
PKG_BASEDIR="${{ steps.package_dir.outputs.pkg_basedir }}"
PKG_DIR="${{ steps.package_dir.outputs.pkg_dir }}"
cp "${BIN_PATH}" "README.md" "LICENSE" "${PKG_DIR}"
pushd "${PKG_BASEDIR}/" >/dev/null
case "${{ matrix.job.target }}" in
*-pc-windows-*) 7z -y a "${PKG_NAME}" "${PKG_BASENAME}/*" | tail -2 ;;
*) tar -czf "${PKG_NAME}" "${PKG_BASENAME}"/* ;;
esac
popd >/dev/null
echo "pkg_path=${PKG_BASEDIR}/${PKG_NAME}" >> $GITHUB_OUTPUT
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.package_dir.outputs.pkg_name }}
path: ${{ steps.package.outputs.pkg_path }}
- name: Create release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/v')
with:
files: ${{ steps.package.outputs.pkg_path }}