@@ -22,90 +22,19 @@ jobs:
22
22
run : pnpm build
23
23
24
24
- run : pnpx pkg-pr-new publish --comment=off --json output.json --compact --no-template './packages/svelte'
25
- - name : Post or update comment
25
+ - name : Add metadata to output
26
26
uses : actions/github-script@v6
27
27
with :
28
28
github-token : ${{ secrets.GITHUB_TOKEN }}
29
29
script : |
30
30
const fs = require('fs');
31
31
const output = JSON.parse(fs.readFileSync('output.json', 'utf8'));
32
-
33
- const bot_comment_identifier = `<!-- pkg.pr.new comment -->`;
34
-
35
- const body = (number) => `${bot_comment_identifier}
36
-
37
- [Playground](https://svelte.dev/playground?version=pr-${number})
38
-
39
- \`\`\`
40
- ${output.packages.map((p) => `pnpm add https://pkg.pr.new/${p.name}@${number}`).join('\n')}
41
- \`\`\`
42
- `;
43
-
44
- async function find_bot_comment(issue_number) {
45
- if (!issue_number) return null;
46
- const comments = await github.rest.issues.listComments({
47
- owner: context.repo.owner,
48
- repo: context.repo.repo,
49
- issue_number: issue_number,
50
- });
51
- return comments.data.find((comment) =>
52
- comment.body.includes(bot_comment_identifier)
53
- );
54
- }
55
-
56
- async function create_or_update_comment(issue_number) {
57
- if (!issue_number) {
58
- console.log('No issue number provided. Cannot post or update comment.');
59
- return;
60
- }
61
-
62
- const existing_comment = await find_bot_comment(issue_number);
63
- if (existing_comment) {
64
- await github.rest.issues.updateComment({
65
- owner: context.repo.owner,
66
- repo: context.repo.repo,
67
- comment_id: existing_comment.id,
68
- body: body(issue_number),
69
- });
70
- } else {
71
- await github.rest.issues.createComment({
72
- issue_number: issue_number,
73
- owner: context.repo.owner,
74
- repo: context.repo.repo,
75
- body: body(issue_number),
76
- });
77
- }
78
- }
79
-
80
- async function log_publish_info() {
81
- console.log('\n' + '='.repeat(50));
82
- console.log('Publish Information');
83
- console.log('='.repeat(50));
84
- console.log('\nPublished Packages:');
85
- console.log(packages);
86
- console.log('\nPlayground URL:');
87
- console.log(`\nhttps://svelte.dev/playground?version=commit-${context.sha.substring(0, 7)}`)
88
- console.log('\n' + '='.repeat(50));
89
- }
90
-
91
- if (context.eventName === 'pull_request') {
92
- if (context.issue.number) {
93
- await create_or_update_comment(context.issue.number);
94
- }
95
- } else if (context.eventName === 'push') {
96
- const pull_requests = await github.rest.pulls.list({
97
- owner: context.repo.owner,
98
- repo: context.repo.repo,
99
- state: 'open',
100
- head: `${context.repo.owner}:${context.ref.replace('refs/heads/', '')}`,
101
- });
102
-
103
- if (pull_requests.data.length > 0) {
104
- await create_or_update_comment(pull_requests.data[0].number);
105
- } else {
106
- console.log(
107
- 'No open pull request found for this push. Logging publish information to console:'
108
- );
109
- await log_publish_info();
110
- }
111
- }
32
+ output.number = context.issue.number;
33
+ output.event_name = context.eventName;
34
+ output.ref = context.ref;
35
+ fs.writeFileSync('output.json', JSON.stringify(output), 'utf8');
36
+ - name : Upload output
37
+ uses : actions/upload-artifact@v4
38
+ with :
39
+ name : output.json
40
+ path : output.json
0 commit comments