Skip to content

Commit 64a33c6

Browse files
authored
Merge pull request CactuseSecurity#3612 from tpurschke/develop
fix update branch behaviour of sync automation
2 parents e0a98d3 + 8095ca3 commit 64a33c6

File tree

1 file changed

+33
-25
lines changed

1 file changed

+33
-25
lines changed

.github/workflows/auto-sync-develop-to-importer-rework.yml.yml

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,74 @@ name: Sync develop to importer-rework
22

33
on:
44
push:
5-
branches:
6-
- develop
5+
branches: [develop]
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
710

811
jobs:
912
sync-branches:
1013
runs-on: ubuntu-latest
1114

1215
steps:
13-
- name: Checkout repo
14-
uses: actions/checkout@v4
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
1519

1620
- name: Set up Git
1721
run: |
1822
git config --global user.name "github-actions[bot]"
1923
git config --global user.email "github-actions[bot]@users.noreply.github.com"
2024
21-
- name: Ensure "automation" label exists (create or update)
25+
- name: Ensure "automation" label exists
2226
run: |
23-
gh label create automation \
27+
gh label create automation \
2428
--color "0e8a16" \
2529
--description "Automatically created for syncing branches" \
2630
--force
2731
env:
28-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2933

30-
- name: Fetch all branches
31-
run: git fetch origin importer-rework
34+
- name: Compute ahead/behind
35+
id: ab
36+
run: |
37+
git fetch origin develop importer-rework
38+
read behind ahead < <(git rev-list --left-right --count origin/importer-rework...origin/develop)
39+
echo "ahead=$ahead" >> $GITHUB_OUTPUT
40+
echo "behind=$behind" >> $GITHUB_OUTPUT
41+
# rev-list separates counts with a TAB. :contentReference[oaicite:2]{index=2}
3242

33-
- name: Check if develop is ahead of importer-rework
34-
id: ahead_check
43+
- name: Push sync branch (mirror develop)
44+
if: steps.ab.outputs.ahead != '0'
3545
run: |
36-
git fetch origin
37-
git rev-list --left-right --count origin/importer-rework...origin/develop > counts.txt
38-
ahead=$(cut -f2 counts.txt)
39-
echo "ahead_count=$ahead" >> $GITHUB_OUTPUT
46+
BR=bot/sync-develop-into-importer-rework
47+
git checkout -B "$BR" origin/develop
48+
git push -f origin "HEAD:$BR"
4049
41-
- name: Check for existing PR
50+
- name: Check for existing PR (sync branch → importer-rework)
4251
id: pr_check
52+
if: steps.ab.outputs.ahead != '0'
4353
run: |
4454
existing_pr=$(gh pr list \
4555
--base importer-rework \
46-
--head develop \
56+
--head bot/sync-develop-into-importer-rework \
4757
--state open \
4858
--json number \
49-
--jq '.[0].number')
50-
59+
--jq '.[0].number // empty')
5160
echo "existing_pr=$existing_pr" >> $GITHUB_OUTPUT
5261
env:
5362
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5463

55-
- name: Create PR from develop to importer-rework
56-
if: steps.ahead_check.outputs.ahead_count != '0' && steps.pr_check.outputs.existing_pr == ''
64+
- name: Create PR from sync branch to importer-rework
65+
if: steps.ab.outputs.ahead != '0' && steps.pr_check.outputs.existing_pr == ''
5766
run: |
5867
gh pr create \
5968
--base importer-rework \
60-
--head develop \
69+
--head bot/sync-develop-into-importer-rework \
6170
--title "Sync develop → importer-rework" \
62-
--body "This PR was auto-created to sync changes from \`develop\` into \`importer-rework\`." \
63-
--label automation \
64-
--repo ${{ github.repository }}
71+
--body "Auto-sync from \`develop\` via sync branch." \
72+
--label automation
6573
env:
6674
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6775

0 commit comments

Comments
 (0)