Skip to content

Commit

Permalink
Merge pull request #337 from zugdev/preview-deployer-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4007 authored Oct 16, 2024
2 parents 5f525fa + b0b3cf5 commit 93e6dd8
Show file tree
Hide file tree
Showing 3 changed files with 1,143 additions and 1,101 deletions.
40 changes: 23 additions & 17 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ jobs:
name: Automatic Cloudflare Deploy
runs-on: ubuntu-22.04
steps:
- name: Verify Runner's Identity
id: verify-runner
run: |
echo "Runner name: $RUNNER_NAME"
if [[ "$RUNNER_NAME" != *"GitHub Actions"* ]]; then
echo "This workflow must run on a GitHub Actions runner. (github-actions[bot])"
exit 1
fi
- name: Deploy to Cloudflare
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: ubiquity/cloudflare-deploy-action@main
Expand Down Expand Up @@ -84,25 +92,23 @@ jobs:
issue_number,
});
// Find the comment to update or create a new one if not found
let existingComment = comments.data.find(comment => comment.user.login === 'github-actions[bot]');
let body = '| Preview Deployment |\n| ------------------ |\n';
// Look for an existing "Preview Deployment" comment
let previewComment = comments.data.find(comment =>
comment.body.startsWith("| Preview Deployment |")
);
const body = `| Preview Deployment |\n| ------------------ |\n| [${sha}](${{ env.CLAIMABLE_URL }}) |\n`;
// If the comment exists, update its body
if (existingComment) {
// Check if the SHA already exists in the comment body to avoid duplicates
if (!existingComment.body.includes(sha)) {
body = existingComment.body + `| [${sha}](${{ env.CLAIMABLE_URL }}) |\n`;
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existingComment.id,
body
});
}
if (previewComment) {
// Update the existing "Preview Deployment" comment
await github.rest.issues.updateComment({
owner,
repo,
comment_id: previewComment.id,
body
});
} else {
// Create a new comment if no existing comment is found
body += `| [${sha}](${{ env.CLAIMABLE_URL }}) |\n`;
// Create a new "Preview Deployment" comment if not found
await github.rest.issues.createComment({
owner,
repo,
Expand Down
40 changes: 38 additions & 2 deletions .github/workflows/knip-reporter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ jobs:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion != 'success' }}
steps:
- name: Verify Runner's Identity
id: verify-runner
run: |
echo "Runner name: $RUNNER_NAME"
if [[ "$RUNNER_NAME" != *"GitHub Actions"* ]]; then
echo "This workflow must run on a GitHub Actions runner. (github-actions[bot])"
exit 1
fi
- uses: actions/download-artifact@v4
with:
name: knip-results
Expand All @@ -24,11 +32,39 @@ jobs:
path: ./pr-number.txt
trim: true

- name: Report knip results to pull request
- name: Get or create comment ID for Knip Report
id: get-comment
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const issue_number = ${{ steps.pr-number.outputs.content }};
// Fetch all comments on the PR
const comments = await github.rest.issues.listComments({
owner,
repo,
issue_number,
});
// Look for an existing Knip report comment
let knipComment = comments.data.find(comment =>
comment.body.startsWith("| Knip Report |")
);
if (knipComment) {
console.log('Found existing Knip report comment:', knipComment.id);
core.setOutput('comment_id', knipComment.id); // Set the comment ID output
} else {
console.log('No existing Knip report comment found.');
core.setOutput('comment_id', ''); // No existing comment
}
- name: Report Knip results to pull request
uses: gitcoindev/knip-reporter@main
with:
verbose: true
comment_id: ${{ github.workflow }}-reporter
comment_id: ${{ steps.get-comment.outputs.comment_id || github.workflow }}-knip-report
command_script_name: knip-ci
annotations: true
ignore_results: false
Expand Down
Loading

0 comments on commit 93e6dd8

Please sign in to comment.