-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yaml
137 lines (120 loc) · 4.81 KB
/
action.yaml
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: "Create sync PR"
description: "Create PR that syncs between two branches"
inputs:
repository:
description: "Repository (e.g., gisce/react-ooui)"
required: true
baseBranch:
description: "Base branch (e.g., main)"
required: true
targetBranch:
description: "Target branch (e.g., alpha)"
required: true
githubToken:
description: "GitHub token for authentication"
required: true
releaseType:
description: "Type of release (e.g., minor, major, patch)"
required: true
runs:
using: "composite"
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ inputs.targetBranch }}
fetch-depth: 0
- name: Configure Git
shell: bash
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
- name: Create sync branch and merge
shell: bash
run: |
# Create sync branch from current position
sync_branch="sync/${{ inputs.baseBranch }}-to-${{ inputs.targetBranch }}-$(date +%Y%m%d-%H%M%S)"
echo "SYNC_BRANCH=$sync_branch" >> $GITHUB_ENV
# Fetch all branches
git fetch origin --unshallow || true
git fetch origin ${{ inputs.baseBranch }}
echo "Creating sync branch $sync_branch from ${{ inputs.targetBranch }}"
# Create and checkout the sync branch FROM targetBranch
git checkout ${{ inputs.targetBranch }}
git checkout -b $sync_branch
# Store current commit for comparison
BEFORE_MERGE=$(git rev-parse HEAD)
# Get the tree hash before merge
BEFORE_TREE=$(git rev-parse HEAD^{tree})
echo "Current branch for merge: $(git branch --show-current)"
# First try a dry-run merge to detect conflicts
if git merge-tree $(git merge-base HEAD origin/${{ inputs.baseBranch }}) HEAD origin/${{ inputs.baseBranch }} | grep -q "^<<<<<<< "; then
echo "CONFLICTS=true" >> $GITHUB_ENV
fi
echo "Merging ${{ inputs.baseBranch }} into sync branch"
# Perform the actual merge with conflict resolution
git merge origin/${{ inputs.baseBranch }} -X theirs --no-edit --no-verify
# Get the tree hash after merge
AFTER_TREE=$(git rev-parse HEAD^{tree})
# Check if the actual content changed
if [ "$BEFORE_TREE" = "$AFTER_TREE" ]; then
echo "No changes from merge - branches are already in sync"
echo "HAS_CHANGES=false" >> $GITHUB_ENV
exit 0
else
echo "Changes detected from merge - continuing with PR creation"
echo "HAS_CHANGES=true" >> $GITHUB_ENV
fi
- name: Push sync branch
if: env.HAS_CHANGES == 'true'
shell: bash
run: |
echo "Pushing branch: ${{ env.SYNC_BRANCH }}"
echo "Current git status:"
git status
echo "Current branch:"
git branch --show-current
echo "Commits to be pushed:"
git log origin/${{ inputs.targetBranch }}..HEAD --oneline
echo "Attempting push with tags..."
git push origin ${{ env.SYNC_BRANCH }} --tags -v
- name: Determine Commit Message
if: env.HAS_CHANGES == 'true'
id: commit-message
run: |
RELEASE_TYPE=${{ inputs.releaseType }}
if [[ "$RELEASE_TYPE" == "patch" ]]; then
PREFIX="fix"
elif [[ "$RELEASE_TYPE" == "minor" ]]; then
PREFIX="feat"
elif [[ "$RELEASE_TYPE" == "major" ]]; then
PREFIX="feat"
BREAKING_CHANGE="BREAKING CHANGE: bump major version"
echo "BREAKING_CHANGE=$BREAKING_CHANGE" >> $GITHUB_ENV
elif [[ "$RELEASE_TYPE" == "none" ]]; then
PREFIX="chore"
fi
echo "PREFIX=$PREFIX" >> $GITHUB_ENV
shell: bash
- name: Create Pull Request
if: env.HAS_CHANGES == 'true'
shell: bash
env:
GH_TOKEN: ${{ inputs.githubToken }}
run: |
# Prepare PR title and body
PR_TITLE="${{ env.PREFIX }}: sync changes from ${{ inputs.baseBranch }} to ${{ inputs.targetBranch }}${{ env.CONFLICTS == 'true' && ' (🚨 CONFLICTS RESOLVED)' || '' }}"
if [[ "${{ env.CONFLICTS }}" == "true" ]]; then
PR_BODY="This PR syncs changes from the ${{ inputs.baseBranch }} branch to ${{ inputs.targetBranch }}.
🚨 **BE CAREFUL BEFORE MERGING**
There were conflicts that were automatically resolved using changes from base branch."
else
PR_BODY="This PR syncs changes from the ${{ inputs.baseBranch }} branch to ${{ inputs.targetBranch }}."
fi
# Create PR using gh cli
gh pr create \
--title "${PR_TITLE}" \
--body "${PR_BODY}" \
--base "${{ inputs.targetBranch }}" \
--head "${{ env.SYNC_BRANCH }}" \
--repo "gisce/${{ inputs.repository }}"