Skip to content

Commit 1cdbc38

Browse files
authored
Merge pull request #20103 from Homebrew/sync-default-branches
Add `sync-default-branches` workflow
2 parents 9494385 + a0d1e1d commit 1cdbc38

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Sync default branches
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
pull_request:
9+
paths:
10+
- .github/workflows/sync-default-branches.yml
11+
12+
permissions: {}
13+
14+
defaults:
15+
run:
16+
shell: bash -xeuo pipefail {0}
17+
18+
concurrency:
19+
group: "sync-default-branches-${{ github.ref }}"
20+
cancel-in-progress: true
21+
22+
jobs:
23+
sync:
24+
runs-on: ubuntu-latest
25+
permissions:
26+
contents: write
27+
steps:
28+
- name: Configure Git user
29+
uses: Homebrew/actions/git-user-config@main
30+
with:
31+
username: github-actions[bot]
32+
33+
- name: Determine source and target branches
34+
id: branches
35+
run: |
36+
if [[ "${GITHUB_REF_NAME}" == "main" ]]; then
37+
target="master"
38+
source="main"
39+
else
40+
target="main"
41+
source="master"
42+
fi
43+
echo "target=${target}" >> "$GITHUB_OUTPUT"
44+
echo "source=${source}" >> "$GITHUB_OUTPUT"
45+
46+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
47+
with:
48+
fetch-depth: 0
49+
persist-credentials: true
50+
51+
- name: Setup target branch
52+
run: |
53+
git checkout "${TARGET_BRANCH}" || git checkout -b "${TARGET_BRANCH}"
54+
git reset --hard "origin/${SOURCE_BRANCH}"
55+
env:
56+
SOURCE_BRANCH: ${{ steps.branches.outputs.source }}
57+
TARGET_BRANCH: ${{ steps.branches.outputs.target }}
58+
59+
- name: Push target branch
60+
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
61+
run: git push origin "${TARGET_BRANCH}" --force-with-lease
62+
env:
63+
TARGET_BRANCH: ${{ steps.branches.outputs.target }}

0 commit comments

Comments
 (0)