Skip to content

Commit

Permalink
Check for template drift
Browse files Browse the repository at this point in the history
  • Loading branch information
richchurcher committed Sep 18, 2024
1 parent ea00a71 commit e765a7b
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/ci-generate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: CI

on: push
# pull_request:
# branches:
# - main

jobs:
drift-check:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Install Bevy CLI
run: |
cargo install --git https://github.com/thebevyflock/bevy_cli
- 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: this would be slightly improved by having the ability to generate from local
# templates, as cargo-generate can.
bevy new foo -t "$REPO" -b "$BRANCH"
env:
REPO: ${{ github.repository }}
BRANCH: ${{ github.ref_name }}

- name: Check for drift between templates and generated files
run: |
for check_file in $(find . -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" || true
echo "::error file=$generated_file::Template drift detected."
fi
done
- name: Remove check files
run: |
find . -type f -name "*.check" -delete

0 comments on commit e765a7b

Please sign in to comment.