Skip to content

Commit 26d779f

Browse files
authored
chore: refactor pre-commit config and build workflow (#563)
1 parent 3491eb4 commit 26d779f

File tree

2 files changed

+24
-212
lines changed

2 files changed

+24
-212
lines changed

template/.github/workflows/build.yml.j2

Lines changed: 1 addition & 212 deletions
Original file line numberDiff line numberDiff line change
@@ -97,223 +97,12 @@ jobs:
9797
echo "skip_helm=true" >> "$GITHUB_OUTPUT"
9898
fi
9999

100-
run_cargodeny:
101-
name: Run Cargo Deny
102-
runs-on: ubuntu-latest
103-
strategy:
104-
matrix:
105-
checks:
106-
- advisories
107-
- bans licenses sources
108-
109-
# Prevent sudden announcement of a new advisory from failing ci:
110-
continue-on-error: ${{ matrix.checks == 'advisories' }}
111-
112-
steps:
113-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
114-
with:
115-
persist-credentials: false
116-
submodules: recursive
117-
- uses: EmbarkStudios/cargo-deny-action@f2ba7abc2abebaf185c833c3961145a3c275caad # v2.0.13
118-
with:
119-
command: check ${{ matrix.checks }}
120-
121-
run_rustfmt:
122-
name: Run Rustfmt
123-
runs-on: ubuntu-latest
124-
steps:
125-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
126-
with:
127-
persist-credentials: false
128-
submodules: recursive
129-
- uses: dtolnay/rust-toolchain@6d653acede28d24f02e3cd41383119e8b1b35921
130-
with:
131-
toolchain: ${{ env.RUST_NIGHTLY_TOOLCHAIN_VERSION }}
132-
components: rustfmt
133-
- env:
134-
RUST_TOOLCHAIN_VERSION: ${{ env.RUST_NIGHTLY_TOOLCHAIN_VERSION }}
135-
run: cargo "+$RUST_TOOLCHAIN_VERSION" fmt --all -- --check
136-
137-
run_clippy:
138-
name: Run Clippy
139-
runs-on: ubuntu-latest
140-
steps:
141-
- name: Install host dependencies
142-
uses: awalsh128/cache-apt-pkgs-action@acb598e5ddbc6f68a970c5da0688d2f3a9f04d05 # v1.6.0
143-
with:
144-
packages: protobuf-compiler krb5-user libkrb5-dev libclang-dev liblzma-dev libssl-dev pkg-config apt-transport-https
145-
version: ubuntu-latest
146-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
147-
with:
148-
persist-credentials: false
149-
submodules: recursive
150-
- uses: dtolnay/rust-toolchain@6d653acede28d24f02e3cd41383119e8b1b35921
151-
with:
152-
toolchain: ${{ env.RUST_TOOLCHAIN_VERSION }}
153-
components: clippy
154-
- uses: Swatinem/rust-cache@f13886b937689c021905a6b90929199931d60db1 # v2.8.1
155-
with:
156-
key: clippy
157-
cache-all-crates: "true"
158-
# TODO (@Techassi): Remove this step (unmaintained action, kinda useless step anyway)
159-
- name: Run clippy action to produce annotations
160-
uses: giraffate/clippy-action@13b9d32482f25d29ead141b79e7e04e7900281e0 # v1.0.1
161-
env:
162-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
163-
if: env.GITHUB_TOKEN != null
164-
with:
165-
clippy_flags: --all-targets -- -D warnings
166-
reporter: 'github-pr-review'
167-
github_token: ${{ secrets.GITHUB_TOKEN }}
168-
# TODO (@Techassi): Remove, done by pre-commit
169-
- name: Run clippy manually without annotations
170-
env:
171-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
172-
if: env.GITHUB_TOKEN == null
173-
run: cargo clippy --color never -q --all-targets -- -D warnings
174-
175-
# TODO (@Techassi): Can be done by pre-commit
176-
run_rustdoc:
177-
name: Run RustDoc
178-
runs-on: ubuntu-latest
179-
steps:
180-
- name: Install host dependencies
181-
uses: awalsh128/cache-apt-pkgs-action@acb598e5ddbc6f68a970c5da0688d2f3a9f04d05 # v1.6.0
182-
with:
183-
packages: protobuf-compiler krb5-user libkrb5-dev libclang-dev liblzma-dev libssl-dev pkg-config apt-transport-https
184-
version: ubuntu-latest
185-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
186-
with:
187-
submodules: recursive
188-
- uses: dtolnay/rust-toolchain@6d653acede28d24f02e3cd41383119e8b1b35921
189-
with:
190-
toolchain: ${{ env.RUST_TOOLCHAIN_VERSION }}
191-
components: rustfmt
192-
- uses: Swatinem/rust-cache@f13886b937689c021905a6b90929199931d60db1 # v2.8.1
193-
with:
194-
key: doc
195-
cache-all-crates: "true"
196-
- run: cargo doc --document-private-items
197-
198-
# TODO (@Techassi): Remove, done by pre-commit
199-
run_tests:
200-
name: Run Cargo Tests
201-
runs-on: ubuntu-latest
202-
steps:
203-
- name: Install host dependencies
204-
uses: awalsh128/cache-apt-pkgs-action@acb598e5ddbc6f68a970c5da0688d2f3a9f04d05 # v1.6.0
205-
with:
206-
packages: protobuf-compiler krb5-user libkrb5-dev libclang-dev liblzma-dev libssl-dev pkg-config apt-transport-https
207-
version: ubuntu-latest
208-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
209-
with:
210-
persist-credentials: false
211-
submodules: recursive
212-
- uses: dtolnay/rust-toolchain@6d653acede28d24f02e3cd41383119e8b1b35921
213-
with:
214-
toolchain: ${{ env.RUST_TOOLCHAIN_VERSION }}
215-
- uses: Swatinem/rust-cache@f13886b937689c021905a6b90929199931d60db1 # v2.8.1
216-
with:
217-
key: test
218-
cache-all-crates: "true"
219-
- run: cargo test
220-
221-
222-
# Similar to check_charts, this tries to render the README, and see if there are unintended changes.
223-
# This will save us from merging changes to the wrong file (instead of the templated source), and from
224-
# forgetting to render out modifications to the README.
225-
check_readme:
226-
name: Check if committed README is the one we would render from the available parts
227-
runs-on: ubuntu-latest
228-
steps:
229-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
230-
with:
231-
persist-credentials: false
232-
submodules: recursive
233-
- uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
234-
with:
235-
python-version: ${{ env.PYTHON_VERSION }}
236-
- name: Install jinja2-cli
237-
run: pip install jinja2-cli==0.8.2
238-
- name: Regenerate charts
239-
run: make render-readme
240-
- name: Check if committed README were up to date
241-
run: git diff --exit-code
242-
- name: Git Diff showed uncommitted changes
243-
if: ${{ failure() }}
244-
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
245-
with:
246-
script: |
247-
core.setFailed('Committed README are not up to date, please make sure to apply them to the templated partials, and re-commit!')
248-
249-
# This job cleans up the CRDs and Helm charts, followed by rebuilding them
250-
# It then runs a `git diff` and fails the entire workflow, if any difference is encountered.
251-
#
252-
# Since CRD files are generated during the 'cargo build' process we need to run this once after
253-
# removing the CRD files to ensure that the checked in versions match what the code expects.
254-
#
255-
# The reason for this step is, that developers are expected to check in up-to-date versions of charts
256-
# as we'd otherwise have to build these in CI and commit them back to the PR, which
257-
# creates all kinds of problems.
258-
# This failsafe simply aborts anything that has not had charts rebuilt before pushing.
259-
check_charts:
260-
name: Check if committed Helm charts are up to date
261-
runs-on: ubuntu-latest
262-
steps:
263-
- name: Install host dependencies
264-
uses: awalsh128/cache-apt-pkgs-action@acb598e5ddbc6f68a970c5da0688d2f3a9f04d05 # v1.6.0
265-
with:
266-
packages: protobuf-compiler krb5-user libkrb5-dev libclang-dev liblzma-dev libssl-dev pkg-config apt-transport-https
267-
version: ubuntu-latest
268-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
269-
with:
270-
persist-credentials: false
271-
submodules: recursive
272-
- name: Set up Helm
273-
uses: azure/setup-helm@1a275c3b69536ee54be43f2070a358922e12c8d4 # v4.3.1
274-
with:
275-
version: v3.16.1
276-
- name: Set up cargo
277-
uses: dtolnay/rust-toolchain@6d653acede28d24f02e3cd41383119e8b1b35921
278-
with:
279-
toolchain: ${{ env.RUST_TOOLCHAIN_VERSION }}
280-
- uses: Swatinem/rust-cache@f13886b937689c021905a6b90929199931d60db1 # v2.8.1
281-
with:
282-
key: charts
283-
cache-all-crates: "true"
284-
- name: Regenerate charts
285-
run: make regenerate-charts
286-
- name: Check if committed charts were up to date
287-
run: git diff --exit-code
288-
- name: Git Diff showed uncommitted changes
289-
if: ${{ failure() }}
290-
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
291-
with:
292-
script: |
293-
core.setFailed('Committed charts were not up to date, please regenerate and re-commit!')
294-
295-
tests_passed:
296-
name: All tests passed
297-
needs:
298-
- run_udeps
299-
- run_cargodeny
300-
- run_clippy
301-
- run_rustfmt
302-
- run_rustdoc
303-
- run_tests
304-
- check_charts
305-
- check_readme
306-
runs-on: ubuntu-latest
307-
steps:
308-
- name: log
309-
run: echo All tests have passed!
310-
311100
# TODO (@Techassi): Most of these publishing and signing tasks can be done by our own actions.
312101
# Make use of them just like we do in docker-images.
313102
package_and_publish:
314103
name: Package Charts, Build Docker Image and publish them - ${{ matrix.runner }}
315104
needs:
316-
- tests_passed
105+
- run_udeps
317106
- check_helm_publish
318107
strategy:
319108
matrix:

template/.pre-commit-config.yaml.j2

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ repos:
1414
args: ["--allow-missing-credentials"]
1515
- id: detect-private-key
1616

17+
- repo: https://github.com/EmbarkStudios/cargo-deny
18+
# Failing to compile cargo-deny with version >0.18.3, needs rust 1.88.0
19+
rev: baa02b0a0c54e0578aae6bb7c7181ad00dc290af # 0.18.3
20+
hooks:
21+
- id: cargo-deny
22+
args: ["--all-features", "check", "advisories", "bans", "licenses", "sources"]
23+
1724
- repo: https://github.com/adrienverge/yamllint
1825
rev: 79a6b2b1392eaf49cdd32ac4f14be1a809bbd8f7 # 1.37.1
1926
hooks:
@@ -72,6 +79,22 @@ repos:
7279
pass_filenames: false
7380
files: Cargo\.lock
7481

82+
- id: check-readme
83+
name: check-readme
84+
language: system
85+
entry: make render-readme
86+
stages: [pre-commit, pre-merge-commit]
87+
pass_filenames: false
88+
files: .readme
89+
90+
- id: cargo-doc
91+
name: cargo-doc
92+
language: system
93+
entry: cargo doc --document-private-items
94+
stages: [pre-commit, pre-merge-commit]
95+
pass_filenames: false
96+
files: \.rs$|Cargo\.(toml|lock)
97+
7598
- id: cargo-test
7699
name: cargo-test
77100
language: system

0 commit comments

Comments
 (0)