-
Notifications
You must be signed in to change notification settings - Fork 1
60 lines (50 loc) · 1.85 KB
/
ci-generate.yaml
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
name: CI
on: push
# pull_request:
# branches:
# - main
jobs:
drift-check:
runs-on: ubuntu-latest
env:
REPO: ${{ github.event.repository.name }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Cache
uses: Leafwing-Studios/cargo-cache@v2
with:
sweep-cache: true
- name: Install cargo-generate
run: |
cargo install cargo-generate
- name: Retain a copy of every generated file
run: |
for template_file in $(find . -type f -name "*.template"); do
generated_file="${template_file%.template}"
if [ -f "$generated_file" ]; then
# Keep a copy to diff with the output of the next step
cp "$generated_file" "${generated_file}.check"
fi
done
- name: Generate from templates
run: |
# Note: we use cargo-generate itself here as our wrapping of the cargo-generate library
# does not allow us to do useful things like --allow-commands and use local templates.
cargo generate --path . --name "$REPO" --allow-commands
- name: Check for drift between templates and generated files
run: |
for check_file in $(find "$REPO" -type f -name "*.check"); do
generated_file="${check_file%.check}"
if ! diff "$check_file" "$generated_file" > /dev/null; then
echo "File $generated_file has drift from $generated_file.template:"
diff "$check_file" "$generated_file"
echo "::error file=$generated_file::Template drift detected."
fi
done
- name: Remove check files
run: |
find . -type f -name "*.check" -delete
rm -rf "$REPO"