-
Notifications
You must be signed in to change notification settings - Fork 7
183 lines (155 loc) · 5.44 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
181
182
183
name: Rust
on:
push:
branches: [ master ]
tags:
- v*
pull_request:
branches: [ master ]
jobs:
fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install fmt with stable toolchain
id: toolchain
uses: dtolnay/rust-toolchain@stable
- run: rustup override set ${{steps.toolchain.outputs.name}}
- run: rustup component add rustfmt
- name: Run cargo fmt
run: cargo fmt --all -- --check
clippy:
name: Clipply
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install clippy with stable toolchain
id: toolchain
uses: dtolnay/rust-toolchain@stable
- run: rustup override set ${{steps.toolchain.outputs.name}}
- run: rustup component add clippy
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --locked --all-targets --all-features
min_version:
name: Minimum supported rust version
runs-on: ubuntu-20.04
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Extract min supported rust version
shell: bash
run: |
echo "MIN_SUPPORTED_RUST_VERSION=$(sed -n 's/^rust-version = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV
- name: Install rust toolchain (v${{ env.MIN_SUPPORTED_RUST_VERSION }})
id: toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.MIN_SUPPORTED_RUST_VERSION }}
- run: rustup override set ${{steps.toolchain.outputs.name}}
- run: rustup component add clippy
- name: Run clippy (on minimum supported rust version to prevent warnings we can't fix)
uses: actions-rs/cargo@v1
with:
command: clippy
args: --locked --all-targets --all-features
- name: Run tests
uses: actions-rs/cargo@v1
with:
command: test
args: --locked
- name: Run examples
run: |
cp target/debug/rash /usr/local/bin/rash
make test-examples
build:
strategy:
fail-fast: false
matrix:
job:
# cross minimum glibc version is 2.32
- { os: ubuntu-22.04, target: arm-unknown-linux-gnueabihf, use-cross: true }
- { os: ubuntu-22.04, target: aarch64-unknown-linux-gnu, use-cross: true }
- { os: ubuntu-22.04, target: x86_64-unknown-linux-musl, use-cross: true }
# use ubuntu 20.04 to keep minimum glibc version to 2.31
- { os: ubuntu-20.04, target: x86_64-unknown-linux-gnu}
- { os: macos-12, target: x86_64-apple-darwin}
name: (${{ matrix.job.os }}) ${{ matrix.job.target }}
runs-on: ${{ matrix.job.os }}
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Install prerequisites
shell: bash
run: |
case ${{ matrix.job.target }} in
arm-unknown-linux-*) sudo apt-get -y update ; sudo apt-get -y install gcc-arm-linux-gnueabihf ;;
aarch64-unknown-linux-gnu) sudo apt-get -y update ; sudo apt-get -y install gcc-aarch64-linux-gnu ;;
esac
- uses: Swatinem/rust-cache@v2
with:
# not reuse cache between different targets:
# https://github.com/cross-rs/cross/issues/39#issuecomment-270684223
key: ${{ matrix.job.target }}
- name: Install Rust toolchain
id: toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.job.target }}
- run: rustup override set ${{steps.toolchain.outputs.name}}
- name: Run tests
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.job.use-cross }}
command: test
args: --locked --target=${{ matrix.job.target }}
- name: Extract crate information
shell: bash
run: |
echo "PROJECT_NAME=rash" >> $GITHUB_ENV
echo "PROJECT_VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV
- name: Install UPX
uses: crazy-max/ghaction-upx@v3
with:
install-only: true
version: latest
if: matrix.job.os != 'macos-12'
- name: Make release
id: package
shell: bash
run: |
export CARGO_TARGET=${{ matrix.job.target }}
export CARGO_USE_CROSS=${{ matrix.job.use-cross }}
export PKG_BASE_NAME=${PROJECT_NAME}-${PROJECT_VERSION}-${CARGO_TARGET}
make release
echo "::set-output name=PKG_BASE_NAME::${PKG_BASE_NAME}"
- name: Publish crates
if: startsWith(github.ref, 'refs/tags/')
env:
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
shell: bash
run: |
cargo login "${CRATES_IO_TOKEN}"
make publish
- name: Get Changelog Entry
if: startsWith(github.ref, 'refs/tags/')
id: changelog_reader
uses: mindsers/[email protected]
with:
version: v${{ env.PROJECT_VERSION }}
path: ./CHANGELOG.md
- name: Publish
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
body: ${{ steps.changelog_reader.outputs.changes }}
prerelease: ${{ steps.changelog_reader.outputs.status == 'prereleased' }}
draft: ${{ steps.changelog_reader.outputs.status == 'unreleased' }}
files: |
${{ steps.package.outputs.PKG_BASE_NAME }}.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}