1111 issue_comment :
1212 types : [created]
1313
14+ permissions :
15+ contents : read
16+
1417jobs :
1518 init :
1619 runs-on : ubuntu-latest
@@ -100,7 +103,7 @@ jobs:
100103 key : git-repo
101104
102105 - name : Checkout ${{ needs.init.outputs.head_ref }}
103- uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
106+ uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
104107 with :
105108 # Needed to allow force push later
106109 persist-credentials : true
@@ -121,19 +124,53 @@ jobs:
121124 fallbackNpm : ' ^10'
122125
123126 - name : Set up node ${{ steps.package-engines-versions.outputs.nodeVersion }}
124- uses : actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1 .0
127+ uses : actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4 .0
125128 with :
126129 node-version : ${{ steps.package-engines-versions.outputs.nodeVersion }}
127130 cache : npm
128131
129132 - name : Set up npm ${{ steps.package-engines-versions.outputs.npmVersion }}
130133 run : npm i -g 'npm@${{ steps.package-engines-versions.outputs.npmVersion }}'
131-
134+
132135 - name : Rebase to ${{ needs.init.outputs.base_ref }}
133136 if : ${{ contains(needs.init.outputs.arg1, 'rebase') }}
134137 run : |
135138 git fetch origin '${{ needs.init.outputs.base_ref }}:${{ needs.init.outputs.base_ref }}'
136- git rebase 'origin/${{ needs.init.outputs.base_ref }}'
139+
140+ # Start the rebase
141+ git rebase 'origin/${{ needs.init.outputs.base_ref }}' || {
142+ # Handle rebase conflicts in a loop
143+ while [ -d .git/rebase-merge ] || [ -d .git/rebase-apply ]; do
144+ echo "Handling rebase conflict..."
145+
146+ # Remove and checkout /dist and /js folders from the base branch
147+ if [ -d "dist" ]; then
148+ rm -rf dist
149+ git checkout origin/${{ needs.init.outputs.base_ref }} -- dist/ 2>/dev/null || echo "No dist folder in base branch"
150+ fi
151+ if [ -d "js" ]; then
152+ rm -rf js
153+ git checkout origin/${{ needs.init.outputs.base_ref }} -- js/ 2>/dev/null || echo "No js folder in base branch"
154+ fi
155+
156+ # Stage all changes
157+ git add .
158+
159+ # Check if there are any changes after resolving conflicts
160+ if git diff --cached --quiet; then
161+ echo "No changes after conflict resolution, skipping commit"
162+ git rebase --skip
163+ else
164+ echo "Changes found, continuing rebase without editing commit message"
165+ git -c core.editor=true rebase --continue
166+ fi
167+
168+ # Break if rebase is complete
169+ if [ ! -d .git/rebase-merge ] && [ ! -d .git/rebase-apply ]; then
170+ break
171+ fi
172+ done
173+ }
137174
138175 - name : Install dependencies & build
139176 env :
@@ -148,7 +185,7 @@ jobs:
148185 run : |
149186 git add '${{ github.workspace }}${{ needs.init.outputs.git_path }}'
150187 git commit --signoff -m 'chore(assets): Recompile assets'
151-
188+
152189 - name : Commit fixup
153190 if : ${{ contains(needs.init.outputs.arg1, 'fixup') }}
154191 run : |
@@ -165,11 +202,15 @@ jobs:
165202
166203 - name : Push normally
167204 if : ${{ !contains(needs.init.outputs.arg1, 'rebase') && !contains(needs.init.outputs.arg1, 'amend') }}
168- run : git push origin '${{ needs.init.outputs.head_ref }}'
205+ env :
206+ HEAD_REF : ${{ needs.init.outputs.head_ref }}
207+ run : git push origin "$HEAD_REF"
169208
170209 - name : Force push
171210 if : ${{ contains(needs.init.outputs.arg1, 'rebase') || contains(needs.init.outputs.arg1, 'amend') }}
172- run : git push --force origin '${{ needs.init.outputs.head_ref }}'
211+ env :
212+ HEAD_REF : ${{ needs.init.outputs.head_ref }}
213+ run : git push --force-with-lease origin "$HEAD_REF"
173214
174215 - name : Add reaction on failure
175216 uses : peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
0 commit comments