Skip to content

Commit 2b964d2

Browse files
committed
only update comment
1 parent cff2414 commit 2b964d2

File tree

1 file changed

+72
-78
lines changed

1 file changed

+72
-78
lines changed

.github/workflows/external-test.yml

Lines changed: 72 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,12 @@ jobs:
4949
run: |
5050
npm ci
5151
npm run build
52-
5352
- name: Install preview dependency
5453
run: |
5554
# Install the preview package
5655
PREVIEW_PACKAGE="${{ inputs.preview_url }}"
5756
echo "Installing preview package: $PREVIEW_PACKAGE"
5857
npm install "$PREVIEW_PACKAGE" --no-save
59-
6058
- name: Run Type Check
6159
id: type-check
6260
continue-on-error: true
@@ -66,7 +64,6 @@ jobs:
6664
else
6765
echo "result=failure" >> $GITHUB_OUTPUT
6866
fi
69-
7067
- name: Setup Supabase CLI
7168
uses: supabase/setup-cli@v1
7269
with:
@@ -87,7 +84,6 @@ jobs:
8784
else
8885
echo "result=failure" >> $GITHUB_OUTPUT
8986
fi
90-
9187
- name: Run Integration Tests
9288
id: integration-tests
9389
continue-on-error: true
@@ -98,7 +94,6 @@ jobs:
9894
else
9995
echo "result=failure" >> $GITHUB_OUTPUT
10096
fi
101-
10297
- name: Generate GitHub App token
10398
id: generate-token
10499
uses: actions/create-github-app-token@v1
@@ -115,82 +110,81 @@ jobs:
115110
echo "App ID: ${{ vars.CROSS_REPO_APP_ID }}"
116111
echo "Target repositories: realtime-js,supabase-js"
117112
echo "Attempting to comment on: supabase/realtime-js#${{ inputs.triggering_pr }}"
118-
119113
- name: Stop Supabase
120114
if: always()
121115
run: supabase stop
122116

123-
- name: Find existing test results comment
124-
if: always() && inputs.triggering_pr != 'push'
125-
uses: peter-evans/find-comment@v3
126-
id: find-comment
127-
with:
128-
repository: supabase/${{ inputs.triggering_repo }}
129-
issue-number: ${{ inputs.triggering_pr }}
130-
comment-author: 'github-actions[bot]'
131-
body-includes: '<!-- supabase-js-test-results -->'
132-
token: ${{ steps.generate-token.outputs.token }}
133-
134-
- name: Prepare test results body
135-
if: always()
136-
id: prepare-body
137-
run: |
138-
TYPE_CHECK="${{ steps.type-check.outputs.result }}"
139-
UNIT_TEST="${{ steps.unit-tests.outputs.result }}"
140-
INTEGRATION_TEST="${{ steps.integration-tests.outputs.result }}"
141-
142-
TYPE_CHECK=${TYPE_CHECK:-failure}
143-
UNIT_TEST=${UNIT_TEST:-failure}
144-
INTEGRATION_TEST=${INTEGRATION_TEST:-failure}
145-
146-
if [[ "$TYPE_CHECK" == "success" && "$UNIT_TEST" == "success" && "$INTEGRATION_TEST" == "success" ]]; then
147-
STATUS_ICON="✅"
148-
OVERALL_STATUS="PASSED"
149-
STATUS_MESSAGE="🎉 All tests passed! This preview release is compatible with supabase-js."
150-
else
151-
STATUS_ICON="❌"
152-
OVERALL_STATUS="FAILED"
153-
STATUS_MESSAGE="⚠️ Some tests failed. Please review the failing tests before merging."
154-
fi
155-
156-
TYPE_CHECK_DISPLAY=$([ "$TYPE_CHECK" == "success" ] && echo "✅ PASSED" || echo "❌ FAILED")
157-
UNIT_TEST_DISPLAY=$([ "$UNIT_TEST" == "success" ] && echo "✅ PASSED" || echo "❌ FAILED")
158-
INTEGRATION_TEST_DISPLAY=$([ "$INTEGRATION_TEST" == "success" ] && echo "✅ PASSED" || echo "❌ FAILED")
159-
160-
cat << EOF > comment-body.md
161-
<!-- supabase-js-test-results -->
162-
## ${STATUS_ICON} supabase-js CI Test Results
163-
164-
**Overall Status: ${OVERALL_STATUS}**
165-
166-
Tests triggered by preview release of \`${{ inputs.package_name }}\`
167-
168-
| Test Suite | Result |
169-
|------------|--------|
170-
| Type Check | ${TYPE_CHECK_DISPLAY} |
171-
| Unit Tests | ${UNIT_TEST_DISPLAY} |
172-
| Integration Tests | ${INTEGRATION_TEST_DISPLAY} |
173-
174-
**Preview Package:** \`${{ inputs.preview_url }}\`
175-
**Commit:** [\`${{ inputs.triggering_sha }}\`](https://github.com/supabase/${{ inputs.triggering_repo }}/commit/${{ inputs.triggering_sha }})
176-
177-
${STATUS_MESSAGE}
178-
179-
<details>
180-
<summary>View workflow run</summary>
181-
182-
[View full test results](https://github.com/supabase/supabase-js/actions/runs/${{ github.run_id }})
183-
</details>
184-
185-
EOF
186-
187117
- name: Report results to triggering PR
188-
if: always() && inputs.triggering_pr != 'push'
189-
uses: peter-evans/create-or-update-comment@v4
118+
if: always()
119+
uses: actions/github-script@v7
190120
with:
191-
repository: supabase/${{ inputs.triggering_repo }}
192-
comment-id: ${{ steps.find-comment.outputs.comment-id }}
193-
issue-number: ${{ inputs.triggering_pr }}
194-
body-path: comment-body.md
195-
edit-mode: replace
196-
token: ${{ steps.generate-token.outputs.token }}
121+
github-token: ${{ steps.generate-token.outputs.token }}
122+
script: |
123+
const typeCheckResult = '${{ steps.type-check.outputs.result }}' || 'failure';
124+
const unitTestResult = '${{ steps.unit-tests.outputs.result }}' || 'failure';
125+
const integrationTestResult = '${{ steps.integration-tests.outputs.result }}' || 'failure';
126+
const allPassed = typeCheckResult === 'success' &&
127+
unitTestResult === 'success' &&
128+
integrationTestResult === 'success';
129+
const statusIcon = allPassed ? '✅' : '❌';
130+
const overallStatus = allPassed ? 'PASSED' : 'FAILED';
131+
// Unique identifier for this bot's comments
132+
const commentIdentifier = '<!-- supabase-js-test-results -->';
133+
const body = `${commentIdentifier}
134+
## ${statusIcon} supabase-js CI Test Results
135+
**Overall Status: ${overallStatus}**
136+
Tests triggered by preview release of \`${{ inputs.package_name }}\`
137+
| Test Suite | Result |
138+
|------------|--------|
139+
| Type Check | ${typeCheckResult === 'success' ? '✅ PASSED' : '❌ FAILED'} |
140+
| Unit Tests | ${unitTestResult === 'success' ? '✅ PASSED' : '❌ FAILED'} |
141+
| Integration Tests | ${integrationTestResult === 'success' ? '✅ PASSED' : '❌ FAILED'} |
142+
**Preview Package:** \`${{ inputs.preview_url }}\`
143+
**Commit:** [\`${{ inputs.triggering_sha }}\`](https://github.com/supabase/${{ inputs.triggering_repo }}/commit/${{ inputs.triggering_sha }})
144+
${allPassed ?
145+
'🎉 All tests passed! This preview release is compatible with supabase-js.' :
146+
'⚠️ Some tests failed. Please review the failing tests before merging.'}
147+
<details>
148+
<summary>View workflow run</summary>
149+
[View full test results](https://github.com/supabase/supabase-js/actions/runs/${context.runId})
150+
</details>`;
151+
try {
152+
// First, try to find an existing comment from this bot
153+
const { data: comments } = await github.rest.issues.listComments({
154+
owner: 'supabase',
155+
repo: '${{ inputs.triggering_repo }}',
156+
issue_number: parseInt('${{ inputs.triggering_pr }}')
157+
});
158+
// Look for a comment with our identifier
159+
const botComment = comments.find(comment =>
160+
comment.body && comment.body.includes(commentIdentifier)
161+
);
162+
if (botComment) {
163+
// Update existing comment
164+
await github.rest.issues.updateComment({
165+
owner: 'supabase',
166+
repo: '${{ inputs.triggering_repo }}',
167+
comment_id: botComment.id,
168+
body: body
169+
});
170+
console.log('Successfully updated existing comment');
171+
} else {
172+
// Create new comment if none exists
173+
await github.rest.issues.createComment({
174+
owner: 'supabase',
175+
repo: '${{ inputs.triggering_repo }}',
176+
issue_number: parseInt('${{ inputs.triggering_pr }}'),
177+
body: body
178+
});
179+
console.log('Successfully posted new comment to PR');
180+
}
181+
} catch (error) {
182+
console.log('Failed to post/update comment:', error.message);
183+
// Still log the results for manual review
184+
console.log('Test Results Summary:', {
185+
typeCheck: typeCheckResult,
186+
unitTests: unitTestResult,
187+
integrationTests: integrationTestResult,
188+
overallStatus: overallStatus
189+
});
190+
}

0 commit comments

Comments
 (0)