-
Notifications
You must be signed in to change notification settings - Fork 1
66 lines (59 loc) · 1.97 KB
/
sync-demo-branches.yml
File metadata and controls
66 lines (59 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
name: Sync Demo Branches with Main
on:
schedule:
# Run every day at 3am UTC (after the signals-demo workflow at 2am UTC)
- cron: '0 3 * * *'
workflow_dispatch:
concurrency:
group: sync-demo-branches
cancel-in-progress: false
jobs:
sync-demo-branches:
name: Sync ${{ matrix.branch }} with main
runs-on: ubuntu-latest
strategy:
matrix:
branch:
- demo/env0
- demo/spacelift
- demo/tfc
permissions:
contents: write
steps:
- name: Configure Git
run: |
git config --global user.name "Platform Automation"
git config --global user.email "platform-automation@company.com"
- name: Checkout main branch
uses: actions/checkout@v6
with:
token: ${{ secrets.GH_PAT }}
ref: main
fetch-depth: 0
- name: Fetch all branches
run: |
git fetch origin
- name: Sync branch with main
env:
GH_TOKEN: ${{ secrets.GH_PAT }}
run: |
echo "Syncing ${{ matrix.branch }} with main..."
BRANCH="${{ matrix.branch }}"
# Checkout or create the branch
if git show-ref --verify --quiet refs/remotes/origin/$BRANCH; then
git checkout -B $BRANCH origin/$BRANCH
else
git checkout -B $BRANCH origin/main
fi
# Check if branch commit differs from main
BRANCH_COMMIT=$(git rev-parse HEAD)
MAIN_COMMIT=$(git rev-parse origin/main)
if [ "$BRANCH_COMMIT" = "$MAIN_COMMIT" ]; then
echo "${{ matrix.branch }} is already in sync with main (both at $MAIN_COMMIT)"
else
echo "${{ matrix.branch }} is at $BRANCH_COMMIT, main is at $MAIN_COMMIT"
echo "Resetting ${{ matrix.branch }} to match main..."
git reset --hard origin/main
git push origin $BRANCH --force
echo "Successfully synced ${{ matrix.branch }} with main"
fi