Skip to content

Commit 5849180

Browse files
authored
Refactor sync-editorconfig workflow for clarity
1 parent bdc6a04 commit 5849180

1 file changed

Lines changed: 34 additions & 18 deletions

File tree

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

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,34 @@ jobs:
5959
fi
6060
6161
open-or-update-sync-pr:
62-
# PR-only syncing: create/update a PR on default-branch pushes, or manual runs
63-
if: >
64-
github.event_name != 'pull_request' && github.actor != 'github-actions[bot]'
62+
if: github.actor != 'github-actions[bot]'
6563
runs-on: ubuntu-latest
6664
steps:
67-
- name: Checkout default branch
65+
- name: Determine base branch
66+
id: base
67+
shell: bash
68+
run: |
69+
set -euo pipefail
70+
if [ "${{ github.event_name }}" = "pull_request" ]; then
71+
echo "name=${{ github.head_ref }}" >> "$GITHUB_OUTPUT"
72+
else
73+
echo "name=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
74+
fi
75+
76+
- name: Checkout base branch
6877
uses: actions/checkout@v4
6978
with:
70-
ref: ${{ github.event.repository.default_branch }}
71-
79+
ref: ${{ steps.base.outputs.name }}
80+
7281
- name: Download canonical .editorconfig
7382
run: |
7483
set -euo pipefail
75-
curl -fsSL "${CANONICAL_RAW_URL}" -o canonical.editorconfig
76-
77-
- name: Detect changes
84+
curl -fsSL "https://raw.githubusercontent.com/BionicCode/bioniccode-code-style/main/.editorconfig" \
85+
-o canonical.editorconfig
86+
87+
- name: Apply if changed
7888
id: diff
89+
shell: bash
7990
run: |
8091
set -euo pipefail
8192
if [ -f .editorconfig ] && cmp -s .editorconfig canonical.editorconfig; then
@@ -84,19 +95,24 @@ jobs:
8495
mv canonical.editorconfig .editorconfig
8596
echo "changed=true" >> "$GITHUB_OUTPUT"
8697
fi
87-
88-
- name: Create or update PR
98+
99+
- name: Compute sync branch name (per-base)
100+
if: steps.diff.outputs.changed == 'true'
101+
id: syncbranch
102+
shell: bash
103+
run: |
104+
set -euo pipefail
105+
base="${{ steps.base.outputs.name }}"
106+
safe="$(echo "$base" | tr '/ ' '--')"
107+
echo "name=chore/sync-editorconfig/$safe" >> "$GITHUB_OUTPUT"
108+
109+
- name: Create or update PR into the base branch
89110
if: steps.diff.outputs.changed == 'true'
90111
uses: peter-evans/create-pull-request@v7
91112
with:
92-
branch: ${{ env.SYNC_BRANCH }}
93-
base: ${{ github.event.repository.default_branch }}
113+
branch: ${{ steps.syncbranch.outputs.name }}
114+
base: ${{ steps.base.outputs.name }}
94115
title: "chore: sync .editorconfig from canonical"
95116
commit-message: "chore(sync): update .editorconfig from canonical"
96-
body: |
97-
Automated sync of `.editorconfig` from the canonical repository.
98-
99-
Source: BionicCode/bioniccode-code-style (main)
100117
add-paths: |
101118
.editorconfig
102-
labels: automation

0 commit comments

Comments
 (0)