@@ -97,15 +97,16 @@ jobs:
9797
9898 steps :
9999 - name : Restore cached git repository
100- uses : buildjet/cache/save @3e70d19e31d6a8030aeddf6ed8dbe601f94d09f4 # v4.0.2
100+ uses : buildjet/cache@3e70d19e31d6a8030aeddf6ed8dbe601f94d09f4 # v4.0.2
101101 with :
102102 path : .git
103103 key : git-repo
104104
105105 - name : Checkout ${{ needs.init.outputs.head_ref }}
106- uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
106+ uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
107107 with :
108- persist-credentials : false
108+ # Needed to allow force push later
109+ persist-credentials : true
109110 token : ${{ secrets.COMMAND_BOT_PAT }}
110111 fetch-depth : 0
111112 ref : ${{ needs.init.outputs.head_ref }}
@@ -123,19 +124,53 @@ jobs:
123124 fallbackNpm : ' ^10'
124125
125126 - name : Set up node ${{ steps.package-engines-versions.outputs.nodeVersion }}
126- uses : actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
127+ uses : actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
127128 with :
128129 node-version : ${{ steps.package-engines-versions.outputs.nodeVersion }}
129130 cache : npm
130131
131132 - name : Set up npm ${{ steps.package-engines-versions.outputs.npmVersion }}
132133 run : npm i -g 'npm@${{ steps.package-engines-versions.outputs.npmVersion }}'
133-
134+
134135 - name : Rebase to ${{ needs.init.outputs.base_ref }}
135136 if : ${{ contains(needs.init.outputs.arg1, 'rebase') }}
136137 run : |
137138 git fetch origin '${{ needs.init.outputs.base_ref }}:${{ needs.init.outputs.base_ref }}'
138- 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+ }
139174
140175 - name : Install dependencies & build
141176 env :
@@ -150,7 +185,7 @@ jobs:
150185 run : |
151186 git add '${{ github.workspace }}${{ needs.init.outputs.git_path }}'
152187 git commit --signoff -m 'chore(assets): Recompile assets'
153-
188+
154189 - name : Commit fixup
155190 if : ${{ contains(needs.init.outputs.arg1, 'fixup') }}
156191 run : |
@@ -167,11 +202,15 @@ jobs:
167202
168203 - name : Push normally
169204 if : ${{ !contains(needs.init.outputs.arg1, 'rebase') && !contains(needs.init.outputs.arg1, 'amend') }}
170- 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"
171208
172209 - name : Force push
173210 if : ${{ contains(needs.init.outputs.arg1, 'rebase') || contains(needs.init.outputs.arg1, 'amend') }}
174- 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"
175214
176215 - name : Add reaction on failure
177216 uses : peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
0 commit comments