-
Notifications
You must be signed in to change notification settings - Fork 48
69 lines (56 loc) · 2.13 KB
/
sync-cloud.yml
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
66
67
68
69
name: Sync Cloud Branch
on:
release:
types: [published]
# on demand
workflow_dispatch:
jobs:
sync-cloud:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Important for getting all branches and history
- name: Configure Git
run: |
git config user.name "GitHub Actions Bot"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Sync cloud branch
run: |
# Fetch all branches
git fetch origin
# Check if cloud branch exists
if git show-ref --verify --quiet refs/remotes/origin/cloud; then
# Switch to cloud branch
git checkout cloud
# Ensure we're up to date
git pull origin cloud
# Merge main into cloud
git merge --no-ff origin/main -m "Merge main branch for release ${{ github.event.release.tag_name }}"
# Push changes
git push origin cloud
else
# Create and push cloud branch if it doesn't exist
git checkout -b cloud
git push --set-upstream origin cloud
fi
- name: Handle merge conflicts
if: failure()
run: |
# If there were merge conflicts, abort and create an issue
git merge --abort || true
# Create an issue using GitHub API
curl -X POST \
-H "Authorization: token ${{ secrets.PAT_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues \
-d '{
"title": "Merge Conflict: main to cloud sync failed",
"body": "There was a merge conflict while trying to sync main branch to cloud branch for release ${{ github.event.release.tag_name }}.\n\nPlease resolve conflicts manually.",
"labels": ["merge-conflict", "bot"]
}'
# Fail the workflow
exit 1