-
Notifications
You must be signed in to change notification settings - Fork 0
180 lines (157 loc) · 5.84 KB
/
rust.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
name: Rust
on: [push]
env:
CICD_INTERMEDIATES_DIR: "_cicd-intermediates"
MSRV_FEATURES: "--all-features"
CARGO_TERM_COLOR: always
jobs:
crate_metadata:
name: Extract crate metadata
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Extract crate information
id: crate_metadata
run: |
echo "name=ssologinlite" | tee -a $GITHUB_OUTPUT
cargo metadata --no-deps --format-version 1 | jq -r '"version=" + .packages[0].version' | tee -a $GITHUB_OUTPUT
cargo metadata --no-deps --format-version 1 | jq -r '"maintainer=" + .packages[0].authors[0]' | tee -a $GITHUB_OUTPUT
cargo metadata --no-deps --format-version 1 | jq -r '"homepage=" + .packages[0].homepage' | tee -a $GITHUB_OUTPUT
cargo metadata --no-deps --format-version 1 | jq -r '"msrv=" + .packages[0].rust_version' | tee -a $GITHUB_OUTPUT
outputs:
name: ${{ steps.crate_metadata.outputs.name }}
version: ${{ steps.crate_metadata.outputs.version }}
maintainer: ${{ steps.crate_metadata.outputs.maintainer }}
homepage: ${{ steps.crate_metadata.outputs.homepage }}
msrv: ${{ steps.crate_metadata.outputs.msrv }}
ensure_cargo_fmt:
name: Ensure 'cargo fmt' has been run
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- uses: actions/checkout@v4
- run: cargo fmt -- --check
# lint_check:
# name: Ensure 'cargo clippy' has no warnings
# runs-on: ubuntu-22.04
# steps:
# - uses: dtolnay/rust-toolchain@stable
# with:
# components: clippy
# - uses: actions/checkout@v4
# - run: cargo clippy --all-targets --all-features -- -Dwarnings
min_version:
name: Minimum supported rust version
runs-on: ubuntu-20.04
needs: crate_metadata
steps:
- uses: actions/checkout@v4
- name: Install rust toolchain (v${{ needs.crate_metadata.outputs.msrv }})
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ needs.crate_metadata.outputs.msrv }}
components: clippy
- name: Run clippy (on minimum supported rust version to prevent warnings we can't fix)
run: cargo clippy --locked --all-targets ${{ env.MSRV_FEATURES }}
- name: Run tests
run: cargo test --locked ${{ env.MSRV_FEATURES }}
release:
needs: crate_metadata
strategy:
fail-fast: false
matrix:
job:
- { target: aarch64-unknown-linux-gnu , os: ubuntu-22.04, use-cross: true , use-target: true}
- { target: arm-unknown-linux-gnueabihf , os: ubuntu-22.04, use-cross: true , use-target: true}
- { target: i686-unknown-linux-gnu , os: ubuntu-22.04, use-cross: true , use-target: true}
- { target: x86_64-apple-darwin , os: macos-12, use-cross: false , use-target: false}
- { target: aarch64-apple-darwin , os: macos-14, use-cross: false , use-target: false}
- { target: x86_64-unknown-linux-gnu , os: ubuntu-22.04, use-cross: true , use-target: true}
env:
BUILD_CMD: cargo
TARGET_OPTS : ""
TARGET_DIR: "target/release/"
name: Releasing
if: ${{ github.ref_type == 'tag' }}
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.job.target }}
toolchain: "${{ contains(matrix.job.target, 'windows-') && '1.77.2' || 'stable' }}"
- name: Install cross
if: matrix.job.use-cross
uses: taiki-e/install-action@v2
with:
tool: cross
- name: Overwrite build command env variable
if: matrix.job.use-cross
shell: bash
run: echo "BUILD_CMD=cross" >> $GITHUB_ENV
- name: Set Target
if: matrix.job.use-target
shell: bash
run: |
echo "TARGET_OPTS=--target=${{ matrix.job.target }}" >> $GITHUB_ENV
echo "TARGET_DIR=target/${{ matrix.job.target }}/release" >> $GITHUB_ENV
- name: Show version information (Rust, cargo, GCC)
shell: bash
run: |
gcc --version || true
rustup -V
rustup toolchain list
rustup default
cargo -V
rustc -V
- name: Build
shell: bash
run: |
case ${{ matrix.job.target }} in
*-pc-windows-gnu)
sudo apt install mingw-w64;;
esac;
$BUILD_CMD build --locked --release $TARGET_OPTS
- name: Set binary, compressed binary name & path
id: package
shell: bash
run: |
# Figure out suffix of binary
EXE_suffix=""
case ${{ matrix.job.target }} in
*-pc-windows-*) EXE_suffix=".exe"
sudo apt install mingw-w64;;
esac;
# Setup paths
BIN_NAME="${{ needs.crate_metadata.outputs.name }}${EXE_suffix}"
BIN_PATH="${TARGET_DIR}/${BIN_NAME}"
ZIP_NAME="${BIN_NAME}-${{ matrix.job.target }}.zip"
PKG_STAGING="${{ env.CICD_INTERMEDIATES_DIR }}/package"
PKG_NAME="${PKG_STAGING}/${ZIP_NAME}"
mkdir -p "${PKG_STAGING}"
find -name "${BIN_NAME}" -type f
find -name "${BIN_NAME}" -type f -exec ls -l {} \;
cp ${BIN_PATH} ${PKG_STAGING}
# Zip binary
pushd "${PKG_STAGING}"
zip ${ZIP_NAME} ${BIN_NAME}
rm ${BIN_NAME}
popd > /dev/null
# Let subsequent steps know where to find the binary
echo "BIN_PATH=${BIN_PATH}" >> $GITHUB_OUTPUT
echo "BIN_NAME=${BIN_NAME}" >> $GITHUB_OUTPUT
echo "PKG_NAME=${PKG_NAME}" >> $GITHUB_OUTPUT
echo "${PKG_NAME}"
ls -l "${PKG_NAME}"
stat "${PKG_NAME}"
- name: Release
uses: softprops/action-gh-release@v2
with:
files: |
${{ steps.package.outputs.PKG_NAME }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}