Skip to content

Commit 5dfeeaf

Browse files
authored
Refactor GitHub Actions workflow for editorconfig sync
1 parent 933ea42 commit 5dfeeaf

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

‎.github/workflows/sync-editorconfig-on-push.yml‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
name: Sync .editorconfig from canonical (PR-only)
22

33
on:
4-
# "Git-triggered polling": run on pushes in this repo
54
push:
65
branches-ignore:
7-
- "chore/sync-editorconfig" # bot branch created by this workflow
8-
# Fail early on PRs if branch is out-of-sync
6+
- "chore/sync-editorconfig" # bot PR branch
97
pull_request:
108
workflow_dispatch:
9+
# Optional polling safety net (recommended for dormant repos):
10+
# schedule:
11+
# - cron: "17 * * * *" # hourly at :17
1112

1213
permissions:
1314
contents: write
@@ -17,12 +18,12 @@ env:
1718
CANONICAL_RAW_URL: https://raw.githubusercontent.com/BionicCode/bioniccode-code-style/main/.editorconfig
1819
SYNC_BRANCH: chore/sync-editorconfig
1920

21+
# Concurrency scoped per PR or per ref (prevents cross-branch cancellations)
2022
concurrency:
21-
group: editorconfig-sync
23+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
2224
cancel-in-progress: true
2325

2426
jobs:
25-
# 1) PR guard: make out-of-sync immediately visible to developers
2627
verify-on-pr:
2728
if: github.event_name == 'pull_request'
2829
runs-on: ubuntu-latest
@@ -37,17 +38,13 @@ jobs:
3738
set -euo pipefail
3839
curl -fsSL "${CANONICAL_RAW_URL}" -o canonical.editorconfig
3940
40-
- name: Ensure exactly one tracked .editorconfig (optional strictness)
41+
- name: Ensure exactly one tracked .editorconfig (strict)
4142
run: |
4243
set -euo pipefail
4344
count=$(git ls-files '**/.editorconfig' | wc -l | tr -d ' ')
44-
if [ "$count" -eq 0 ]; then
45-
echo "::error::.editorconfig is missing in this repo."
46-
exit 1
47-
fi
48-
if [ "$count" -gt 1 ]; then
49-
echo "::error::Multiple .editorconfig files found. Keep only the repo-root .editorconfig to avoid overrides."
50-
git ls-files '**/.editorconfig'
45+
if [ "$count" -ne 1 ]; then
46+
echo "::error::Expected exactly one tracked .editorconfig (repo root). Found: $count"
47+
git ls-files '**/.editorconfig' || true
5148
exit 1
5249
fi
5350
@@ -57,13 +54,16 @@ jobs:
5754
if cmp -s .editorconfig canonical.editorconfig; then
5855
echo ".editorconfig is in sync with canonical."
5956
else
60-
echo "::error::.editorconfig is OUT OF SYNC with canonical. Merge the sync PR (or rerun the sync workflow)."
57+
echo "::error::.editorconfig is OUT OF SYNC with canonical. Merge the sync PR created by this workflow."
6158
exit 1
6259
fi
6360
64-
# 2) PR creator/updater: always proposes canonical via one rolling PR
6561
open-or-update-sync-pr:
66-
if: github.event_name != 'pull_request' && github.actor != 'github-actions[bot]'
62+
# PR-only syncing: create/update a PR on default-branch pushes, or manual runs
63+
if: >
64+
github.event_name != 'pull_request' &&
65+
(github.event_name != 'push' || github.ref == format('refs/heads/{0}', github.event.repository.default_branch)) &&
66+
github.actor != 'github-actions[bot]'
6767
runs-on: ubuntu-latest
6868
steps:
6969
- name: Checkout default branch
@@ -83,8 +83,8 @@ jobs:
8383
if [ -f .editorconfig ] && cmp -s .editorconfig canonical.editorconfig; then
8484
echo "changed=false" >> "$GITHUB_OUTPUT"
8585
else
86-
echo "changed=true" >> "$GITHUB_OUTPUT"
8786
mv canonical.editorconfig .editorconfig
87+
echo "changed=true" >> "$GITHUB_OUTPUT"
8888
fi
8989
9090
- name: Create or update PR

0 commit comments

Comments
 (0)