-
-
Notifications
You must be signed in to change notification settings - Fork 3
163 lines (140 loc) · 4.46 KB
/
ci.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
name: CI
on:
pull_request:
push:
branches:
- main
env:
RUST_BACKTRACE: 1
CARGO_TERM_COLOR: always
jobs:
ci-everything:
name: All CI stages
runs-on: ubuntu-latest
needs:
- lint
- rust-tests
if: ${{ success() || failure() }} # Run this job even if a dependency has failed.
steps:
- name: Job outcomes
run: |
echo "lint: ${{ needs.lint.result }}"
echo "rust-tests: ${{ needs.rust-tests.result }}"
# Fail this required job if any of its dependent jobs have failed.
#
# Do not attempt to consolidate these steps into one step, it won't work.
# Multi-line `if` clauses are not evaluated properly: see the intermediate commits in
# https://github.com/obi1kenobi/cargo-semver-checks/pull/405
- if: ${{ needs.lint.result != 'success' }}
run: exit 1
- if: ${{ needs.rust-tests.result != 'success' }}
run: exit 1
lint:
name: Check lint and rustfmt
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install rust + caching
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: rustfmt, clippy
rustflags: ""
- name: cargo clippy
run: cargo clippy --workspace --all-features --all-targets -- -D warnings -Dclippy::print_stdout -Dclippy::print_stderr -Dclippy::dbg_macro --allow deprecated
- name: cargo fmt
run: cargo fmt -- --check
- name: cargo doc
env:
RUSTDOCFLAGS: -D warnings
run: cargo doc --workspace --all-features --no-deps --document-private-items
rust-tests:
name: Run tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install rust + caching
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
rustflags: ""
# Compile all features all at once
- name: compile all features
run: cargo test --no-run --all-features
# Test features individually
- name: test rustdoc v26
run: cargo test --no-default-features --features v26
- name: test rustdoc v27
run: cargo test --no-default-features --features v27
# Test all features at once; keep this last for caching purposes.
- name: test all features
run: cargo test --all-features
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
needs:
- should-publish
- ci-everything
- pre-publish-checks
if: needs.should-publish.outputs.is_new_version == 'yes' && github.ref == 'refs/heads/main'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: true
- name: Install rust + caching
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
rustflags: ""
- name: Tag the version
run: |
set -euxo pipefail
export CURRENT_VERSION="$(./scripts/get_current_version.sh trustfall_rustdoc)"
git tag "v$CURRENT_VERSION"
git push origin "v$CURRENT_VERSION"
- name: Publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish
should-publish:
name: Check if version changed
runs-on: ubuntu-latest
outputs:
is_new_version: ${{ steps.check.outputs.is_new_version }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- id: check
run: |
set +e
./scripts/is_version_already_uploaded.sh trustfall_rustdoc
export EXIT_CODE="$?"
set -e
if [[ "$EXIT_CODE" == "7" ]]; then
echo "is_new_version=no" >> $GITHUB_OUTPUT
elif [[ "$EXIT_CODE" == "0" ]]; then
echo "is_new_version=yes" >> $GITHUB_OUTPUT
else
# Unexpected outcome, indicates a bug.
exit "$EXIT_CODE"
fi
pre-publish-checks:
name: Check for semver compliance
runs-on: ubuntu-latest
needs:
- ci-everything
- should-publish
if: needs.should-publish.outputs.is_new_version == 'yes'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Check semver
uses: obi1kenobi/cargo-semver-checks-action@v2