Skip to content

Commit f95d238

Browse files
authored
Merge pull request #14 from mapswipe/feat/update-pre-commit
feat(ci): add check for generated python code
2 parents fe613a3 + f883a5f commit f95d238

File tree

1 file changed

+58
-4
lines changed

1 file changed

+58
-4
lines changed

.github/workflows/ci.yml

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,74 @@ jobs:
1010

1111
steps:
1212
- uses: actions/checkout@main
13+
1314
- uses: astral-sh/setup-uv@v5
1415
with:
1516
enable-cache: true
1617

17-
- name: Setup uv python environment
18+
- name: Setup python environment
1819
working-directory: ./functions/generated/pyfirebase
1920
run: uv venv
2021

21-
- name: uv lock check
22+
- name: Check if uv lockfile is up-to-date
2223
working-directory: ./functions/generated/pyfirebase
2324
run: uv lock --locked --offline
2425

25-
- name: uv sync
26+
- name: Install python dependencies
2627
working-directory: ./functions/generated/pyfirebase
2728
run: uv sync --all-extras
2829

29-
- uses: pre-commit/[email protected]
30+
- name: Install pre-commit and run
31+
uses: pre-commit/[email protected]
32+
with:
33+
extra_args: --all-files --hook-stage manual --show-diff-on-failure
34+
35+
- name: Setup node environment
36+
uses: actions/setup-node@v4
37+
with:
38+
node-version: 22
39+
cache: 'yarn'
40+
cache-dependency-path: ./functions/yarn.lock
41+
42+
- name: Install JS dependencies
43+
working-directory: ./functions
44+
run: yarn install --frozen-lockfile
45+
46+
- name: Generate python definition files
47+
working-directory: ./functions
48+
run: yarn generate:py
49+
50+
- name: Run pre-commit for generated python definition files
51+
run: |
52+
# NOTE: We do not want to terminate when pre-commit fails
53+
set +e
54+
# NOTE: Run pre-commit multiple times because some hooks auto-fix
55+
# files and require re-runs to fully clean the codebase.
56+
max_attempts=5
57+
attempt=1
58+
while [ $attempt -le $max_attempts ]; do
59+
echo "ℹ️ Pre-commit attempt $attempt..."
60+
pre-commit run --all-files
61+
STATUS=$?
62+
63+
if [[ $STATUS -eq 0 ]]; then
64+
echo "✅ Pre-commit passed after $attempt attempts."
65+
exit 0
66+
fi
67+
68+
attempt=$((attempt + 1))
69+
done
70+
71+
echo "❌ Pre-commit did not converge after $max_attempts attempts."
72+
git status
73+
git --no-pager diff
74+
exit 1
75+
76+
- name: Check if generated definition files are up to date.
77+
run: |
78+
if ! git diff --quiet ./functions/generated/; then
79+
echo "❌ Generated definition files are not up-to-date. Run 'yarn generate:py' to update the generated definitionfiles."
80+
git status
81+
git --no-pager diff
82+
exit 1
83+
fi

0 commit comments

Comments
 (0)