Skip to content

Commit 1f031ef

Browse files
committed
Try to resolve the race condition for the tool update job
Signed-off-by: Radoslav Dimitrov <[email protected]>
1 parent 3446791 commit 1f031ef

File tree

1 file changed

+100
-19
lines changed

1 file changed

+100
-19
lines changed

.github/workflows/update-tools.yml

Lines changed: 100 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -184,34 +184,32 @@ jobs:
184184
fi
185185
fi
186186
187-
- name: Commit changes
187+
- name: Stage changes for later commit
188188
if: (steps.update.outputs.changed == 'true' || steps.update.outputs.warning-added == 'true') && github.event_name == 'pull_request'
189189
run: |
190-
git config --local user.email "[email protected]"
191-
git config --local user.name "GitHub Action"
190+
# Just stage the files, don't commit yet
191+
git add "${{ matrix.spec }}"
192192
193+
# Create a summary file for the commit job to use
193194
SERVER_NAME="${{ steps.server-info.outputs.server-name }}"
195+
mkdir -p /tmp/commit-info
194196
195197
if [ "${{ steps.update.outputs.changed }}" = "true" ]; then
196-
git add "${{ matrix.spec }}"
197-
git commit -m "chore: update tool list for $SERVER_NAME
198-
199-
Automatically updated tool list using 'thv mcp list --server $SERVER_NAME'
200-
201-
Co-authored-by: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>"
198+
echo "update" > "/tmp/commit-info/${SERVER_NAME}.type"
199+
echo "$SERVER_NAME" > "/tmp/commit-info/${SERVER_NAME}.name"
200+
echo "${{ matrix.spec }}" > "/tmp/commit-info/${SERVER_NAME}.spec"
202201
else
203-
git add "${{ matrix.spec }}"
204-
git commit -m "chore: add warning for $SERVER_NAME tool list update failure
205-
206-
Could not fetch tools from MCP server, added warning comment.
207-
208-
Co-authored-by: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>"
202+
echo "warning" > "/tmp/commit-info/${SERVER_NAME}.type"
203+
echo "$SERVER_NAME" > "/tmp/commit-info/${SERVER_NAME}.name"
204+
echo "${{ matrix.spec }}" > "/tmp/commit-info/${SERVER_NAME}.spec"
209205
fi
210-
211-
- name: Push changes
206+
207+
- name: Upload commit info
212208
if: (steps.update.outputs.changed == 'true' || steps.update.outputs.warning-added == 'true') && github.event_name == 'pull_request'
213-
run: |
214-
git push
209+
uses: actions/upload-artifact@v4
210+
with:
211+
name: commit-info-${{ steps.server-info.outputs.server-name }}
212+
path: /tmp/commit-info/
215213

216214
- name: Output diff for workflow dispatch
217215
if: github.event_name == 'workflow_dispatch' && (steps.update.outputs.changed == 'true' || steps.update.outputs.warning-added == 'true')
@@ -247,6 +245,89 @@ jobs:
247245
echo "**Spec File**: \`${{ matrix.spec }}\`" >> $GITHUB_STEP_SUMMARY
248246
echo "**Triggered by**: @${{ github.actor }}" >> $GITHUB_STEP_SUMMARY
249247
248+
commit-all-changes:
249+
name: Commit All Tool Updates
250+
needs: update-tools
251+
if: always() && needs.detect-changes.outputs.has-changes == 'true' && github.event_name == 'pull_request'
252+
runs-on: ubuntu-latest
253+
steps:
254+
- name: Checkout code
255+
uses: actions/checkout@v5
256+
with:
257+
token: ${{ secrets.GITHUB_TOKEN }}
258+
ref: ${{ github.head_ref || github.ref }}
259+
260+
- name: Download all commit info artifacts
261+
uses: actions/download-artifact@v4
262+
with:
263+
path: /tmp/artifacts/
264+
pattern: commit-info-*
265+
merge-multiple: true
266+
267+
- name: Check if any changes were made
268+
id: check_changes
269+
run: |
270+
if [ -d "/tmp/artifacts" ] && [ "$(ls -A /tmp/artifacts 2>/dev/null)" ]; then
271+
echo "changes=true" >> $GITHUB_OUTPUT
272+
echo "Found commit info files:"
273+
ls -la /tmp/artifacts/
274+
else
275+
echo "changes=false" >> $GITHUB_OUTPUT
276+
echo "No changes to commit"
277+
fi
278+
279+
- name: Commit and push all changes
280+
if: steps.check_changes.outputs.changes == 'true'
281+
run: |
282+
git config --local user.email "[email protected]"
283+
git config --local user.name "GitHub Action"
284+
285+
# Pull any remote changes first to avoid conflicts
286+
git pull origin ${{ github.head_ref || github.ref_name }} --rebase
287+
288+
# Collect all the server names that were updated
289+
UPDATED_SERVERS=""
290+
WARNING_SERVERS=""
291+
292+
for file in /tmp/artifacts/*.type; do
293+
if [ -f "$file" ]; then
294+
SERVER_NAME=$(basename "$file" .type)
295+
TYPE=$(cat "$file")
296+
297+
if [ "$TYPE" = "update" ]; then
298+
UPDATED_SERVERS="$UPDATED_SERVERS $SERVER_NAME"
299+
else
300+
WARNING_SERVERS="$WARNING_SERVERS $SERVER_NAME"
301+
fi
302+
303+
# Stage the corresponding spec file
304+
SPEC_FILE=$(cat "/tmp/artifacts/${SERVER_NAME}.spec")
305+
git add "$SPEC_FILE"
306+
fi
307+
done
308+
309+
# Create commit message
310+
COMMIT_MSG="chore: update tool lists for MCP servers"
311+
312+
if [ -n "$UPDATED_SERVERS" ]; then
313+
COMMIT_MSG="$COMMIT_MSG\n\nUpdated servers:$(echo $UPDATED_SERVERS | sed 's/ /\\n- /g' | sed 's/^/\\n- /')"
314+
fi
315+
316+
if [ -n "$WARNING_SERVERS" ]; then
317+
COMMIT_MSG="$COMMIT_MSG\n\nWarning added for servers:$(echo $WARNING_SERVERS | sed 's/ /\\n- /g' | sed 's/^/\\n- /')"
318+
fi
319+
320+
COMMIT_MSG="$COMMIT_MSG\n\nAutomatically updated using 'thv mcp list' command.\n\nCo-authored-by: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>"
321+
322+
# Check if there are actually any changes to commit
323+
if ! git diff --cached --quiet; then
324+
git commit -m "$COMMIT_MSG"
325+
git push
326+
echo "✅ Successfully committed and pushed all tool updates"
327+
else
328+
echo "ℹ️ No changes to commit (files may have been identical)"
329+
fi
330+
250331
comment-summary:
251332
name: Post Summary Comment
252333
needs: [detect-changes, update-tools]

0 commit comments

Comments
 (0)