-
Notifications
You must be signed in to change notification settings - Fork 1
159 lines (124 loc) · 4.45 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
name: Rust
on:
push:
branches: [ "*" ]
pull_request:
types: [opened, synchronize]
env:
RUSTFLAGS: -Dwarnings
CARGO_TERM_COLOR: always
jobs:
pre-job:
runs-on: ubuntu-22.04
outputs:
skip_tests: ${{ steps.check_tests.outputs.skip_tests }}
stable_version: ${{ steps.get_rust_version.outputs.stable_version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get stable Rust version
id: get_rust_version
run: |
STABLE_VERSION=$(rustc -Vv | grep "release:" | cut -d' ' -f2)
echo "stable_version=$STABLE_VERSION" >> $GITHUB_OUTPUT
- name: Check if tests have already run
id: check_tests
if: github.event_name == 'pull_request'
run: |
LAST_COMMIT_SHA=$(git rev-parse HEAD)
LAST_WORKFLOW_RUN=$(gh run list --limit 1 --branch ${{ github.head_ref }} --workflow ${{ github.workflow }} --json conclusion,headSha --jq '.[0]')
LAST_RUN_SHA=$(echo "$LAST_WORKFLOW_RUN" | jq -r '.headSha')
LAST_RUN_CONCLUSION=$(echo "$LAST_WORKFLOW_RUN" | jq -r '.conclusion')
if [[ "$LAST_COMMIT_SHA" == "$LAST_RUN_SHA" && "$LAST_RUN_CONCLUSION" == "success" ]]; then
echo "Tests have already run successfully on this commit"
echo "skip_tests=true" >> $GITHUB_OUTPUT
else
echo "skip_tests=false" >> $GITHUB_OUTPUT
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
rustfmt:
needs: pre-job
if: needs.pre-job.outputs.skip_tests != 'true'
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
components: rustfmt
- name: Check formatting
run: cargo fmt --all -- --check
clippy:
needs: [ pre-job, rustfmt ]
if: needs.pre-job.outputs.skip_tests != 'true'
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ macos-latest, windows-latest, ubuntu-latest ]
rust_version: [ stable, "1.79.0" ]
include:
- os: ubuntu-latest
install-deps: sudo apt install -y build-essential gcc
- os: windows-latest
install-deps: echo "No additional dependencies for Windows"
- os: macos-latest
install-deps: echo "No additional dependencies for macOS"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check if job should be skipped
id: check_skip
shell: pwsh
run: |
if (("${{ matrix.rust_version }}" -ne "stable") -and ("${{ matrix.rust_version }}" -eq "${{ needs.pre-job.outputs.stable_version }}")) {
echo "skip=true" >> $env:GITHUB_OUTPUT
} else {
echo "skip=false" >> $env:GITHUB_OUTPUT
}
- uses: actions-rust-lang/setup-rust-toolchain@v1
if: steps.check_skip.outputs.skip != 'true'
with:
toolchain: ${{ matrix.rust_version }}
components: clippy
- name: Run `cargo clippy` with no features
if: ${{ matrix.rust_version == 'stable' && steps.check_skip.outputs.skip != 'true' }}
run: cargo clippy --verbose --no-default-features -- -D warnings -D clippy::dbg_macro
- name: Run `cargo clippy` with all features
if: steps.check_skip.outputs.skip != 'true'
run: cargo clippy --verbose --all-features -- -D warnings -D clippy::dbg_macro
test:
needs: [ pre-job, rustfmt ]
if: needs.pre-job.outputs.skip_tests != 'true'
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ macos-latest, windows-latest, ubuntu-latest ]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Prepare Ubuntu environment
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
sudo apt update
sudo apt install -y libxcb-shape0-dev libxcb-xfixes0-dev
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: Run tests with all features
run: cargo test --all-features
check:
if: always()
needs:
- rustfmt
- clippy
- test
runs-on: ubuntu-latest
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
allowed-failures: rustfmt
jobs: ${{ toJSON(needs) }}