-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (82 loc) · 3.56 KB
/
Copy pathauto-fix-precommit.yml
File metadata and controls
92 lines (82 loc) · 3.56 KB
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
# Auto-fix pre-commit issues for Copilot Agent PRs
#
# This workflow automatically runs pre-commit hooks and commits any auto-fixes
# for branches created by the Copilot Coding Agent. This ensures that PRs
# created by the agent pass pre-commit CI checks without manual intervention.
#
# Hook coverage: This workflow runs the same `pre-commit run --all-files`
# pipeline as `precommit-ci.yml`, so it runs every active hook in
# `.pre-commit-config.yaml` (auto-fixing where the hook supports it) —
# including JSON (check-json), YAML (check-yaml, yamllint), GitHub Actions
# workflows (actionlint), Markdown (markdownlint-cli2), schema validation, and
# general hygiene hooks. Note that hooks like yamllint and actionlint are
# validators that do not auto-fix; this workflow runs them but does not
# enforce their results (the `pre-commit` exit code is
# intentionally ignored via `|| true` so that auto-fixed files can still be
# committed). Validator failures are enforced by the `Pre-commit` job in
# `precommit-ci.yml`, which runs the same hooks without `|| true`.
#
# Design considerations:
# - Only triggers on push to copilot/** branches to avoid interfering with human work
# - Uses actor check (github.actor == 'copilot-swe-agent[bot]') to only run when
# the Copilot bot pushes code, preventing the workflow from running on its own
# commits (which would cause an infinite loop)
# - Uses workflow concurrency to prevent race conditions when multiple pushes
# occur in quick succession
# - Only commits if there are actual changes to avoid empty commits
# - Uses github-actions[bot] identity for commits to clearly identify automated fixes
#
# OPTIONAL: This workflow is optional. If you prefer to manually commit pre-commit
# fixes, you can safely delete this file. The standard CI workflow will still run
# and report any issues that need to be fixed.
name: Auto-fix pre-commit (Copilot branches)
on:
push:
branches:
- "copilot/**"
# Prevent multiple runs from racing with each other
concurrency:
group: auto-fix-precommit-${{ github.ref }}
cancel-in-progress: false
jobs:
auto-fix:
runs-on: ubuntu-latest
# Only run if the pusher is the Copilot bot (GitHub App)
# This prevents the workflow from running on its own commits
if: github.actor == 'copilot-swe-agent[bot]'
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
ref: ${{ github.ref }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.x"
- name: Install pre-commit
run: pip install pre-commit
- name: Run pre-commit hooks (auto-fix)
run: |
# Run pre-commit; exit code is ignored since we check for changes separately
# Exit code 0 = all passed
# Exit code 1 = hooks failed but may have fixed files
pre-commit run --all-files || true
- name: Check for changes
id: changes
run: |
if [[ -n "$(git status --porcelain)" ]]; then
echo "has_changes=true" >> "$GITHUB_OUTPUT"
else
echo "has_changes=false" >> "$GITHUB_OUTPUT"
fi
- name: Commit and push fixes
if: steps.changes.outputs.has_changes == 'true'
run: |
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "chore: Apply pre-commit auto-fixes [automated]"
git push