Skip to content

Commit 01d3462

Browse files
committed
added new github action
1 parent a9b9640 commit 01d3462

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

.github/workflows/sync-demo-branch.yml

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,35 @@ jobs:
99
sync-demo-branch:
1010
runs-on: ubuntu-latest
1111
steps:
12+
# Checkout the demo branch first, this is where we'll merge into
1213
- name: Checkout demo branch
13-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
1415
with:
1516
ref: 'demo'
16-
token: ${{ secrets.DEMO_UPDATE_PAT }} # Use the PAT for checkout
17+
token: ${{ secrets.DEMO_UPDATE_PAT }}
18+
fetch-depth: 0 # Needed for merge history
1719

18-
- name: Fetch changes from main branch
19-
run: git fetch origin main
20-
21-
- name: Checkout main branch files excluding .github, cypress-example, and playwright-example
20+
# Configure Git user for the commit
21+
- name: Configure Git User
2222
run: |
23-
git checkout origin/main -- . ':!/.github' ':!/cypress-example' ':!/playwright-example'
23+
# Using generic bot details, you can change these if desired
24+
git config user.name "GitHub Actions Bot"
25+
git config user.email "actions-bot@github.com"
26+
27+
# Fetch the latest changes from the remote, including main
28+
- name: Fetch origin
29+
run: git fetch origin
2430

25-
- name: Find last merged branch
26-
id: last-merged-branch
31+
# Perform the merge from main into the currently checked out demo branch
32+
- name: Merge main into demo
2733
run: |
28-
git fetch --all
29-
last_branch=$(git log -1 --pretty=format:"%s" | awk -F 'from ' '{print $2}')
30-
echo "branch=$last_branch" >> $GITHUB_OUTPUT
34+
# Merge main. --no-ff creates a merge commit.
35+
# Git automatically uses .gitattributes in the demo branch.
36+
git merge --no-ff origin/main -m "Auto-merge main into demo"
37+
# This step might fail on complex conflicts not handled by merge=ours.
3138

32-
- name: Commit and push changes to demo branch
39+
# Push the merge commit back to the demo branch
40+
- name: Push changes to demo
3341
run: |
34-
git config --global user.email "peter@petermsouzajr.com"
35-
git config --global user.name "Peter Souza"
36-
branch_name="${{ steps.last-merged-branch.outputs.branch }}"
37-
git commit -am "Sync changes from main branch to demo (merged from $branch_name)" || echo "No changes to commit"
38-
git push https://${{ secrets.DEMO_UPDATE_PAT }}@github.com/petermsouzajr/qa-shadow-report.git demo
42+
git push origin demo
43+
# actions/checkout@v4 with token handles auth for push

0 commit comments

Comments
 (0)