Skip to content

Commit

Permalink
add post-comment for testing purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
AmirSa12 committed Oct 10, 2024
1 parent 27c362f commit 3fb445c
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,91 @@ jobs:

- name: pkg.pr.new
run: pnpm publish:playgrounds --json output.json --comment=off

post-comment:
runs-on: ubuntu-latest
steps:
- name: Post or update comment
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const output = JSON.parse(fs.readFileSync('output.json', 'utf8'));
const packages = output.packages.map(p => `- ${p.name}: ${p.url}`).join('\n');
const templates = output.templates.map(t => `- [${t.name}](${t.url})`).join('\n');
const body = `## Custom Publish Message for ${context.sha.substring(0, 7)}
### Published Packages:
${packages}
### Templates:
${templates}`;
const botCommentIdentifier = '## Custom Publish Message';
async function findBotComment(issueNumber) {
if (!issueNumber) return null;
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber
});
return comments.data.find(comment => comment.body.includes(botCommentIdentifier));
}
async function createOrUpdateComment(issueNumber) {
if (!issueNumber) {
console.log('No issue number provided. Cannot post or update comment.');
return;
}
const existingComment = await findBotComment(issueNumber);
if (existingComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
issue_number: issueNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
}
}
function logPublishInfo() {
console.log('\n' + '='.repeat(50));
console.log('Publish Information for commit:', context.sha.substring(0, 7));
console.log('='.repeat(50));
console.log('\nPublished Packages:');
console.log(packages);
console.log('\nTemplates:');
console.log(templates);
console.log('\n' + '='.repeat(50));
}
if (context.eventName === 'pull_request') {
await createOrUpdateComment(context.issue.number);
} else if (context.eventName === 'push') {
const pullRequests = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
head: `${context.repo.owner}:${context.ref.replace('refs/heads/', '')}`
});
if (pullRequests.data.length > 0) {
await createOrUpdateComment(pullRequests.data[0].number);
} else {
console.log('No open pull request found for this push. Logging publish information to console:');
logPublishInfo();
}

0 comments on commit 3fb445c

Please sign in to comment.