Skip to content

Commit de0eadc

Browse files
authored
chore: update pkg.pr.new workflow (#662)
1 parent f7d36ee commit de0eadc

File tree

3 files changed

+52
-26
lines changed

3 files changed

+52
-26
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Update pkg.pr.new comment
2+
3+
on:
4+
workflow_run:
5+
workflows: [Publish to pkg.pr.new]
6+
types:
7+
- completed
8+
9+
jobs:
10+
build:
11+
if: github.repository == 'sveltejs/svelte-eslint-parser'
12+
name: Update comment
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Download artifact
17+
uses: actions/download-artifact@v4
18+
with:
19+
name: output
20+
github-token: ${{ secrets.GITHUB_TOKEN }}
21+
run-id: ${{ github.event.workflow_run.id }}
22+
- run: ls -R .
23+
- name: Post or update comment
24+
uses: actions/github-script@v7
25+
with:
26+
github-token: ${{ secrets.GITHUB_TOKEN }}
27+
script: |
28+
const fs = require('fs');
29+
const output = JSON.parse(fs.readFileSync('output.json', 'utf8'));
30+
const { default: process } = await import('${{ github.workspace }}/tools/pkg.pr.new-comment.mjs')
31+
32+
await process({github, context, core, output})

.github/workflows/pkg.pr.new.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
jobs:
1010
build:
11+
if: github.repository == 'sveltejs/svelte-eslint-parser'
1112
runs-on: ubuntu-latest
1213

1314
steps:
@@ -19,12 +20,24 @@ jobs:
1920
- name: Build
2021
run: pnpm run build
2122
- run: pnpx pkg-pr-new publish --compact --json output.json --comment=off
22-
- uses: actions/github-script@v7
23+
- name: Add metadata to output
24+
uses: actions/github-script@v7
2325
with:
2426
github-token: ${{ secrets.GITHUB_TOKEN }}
2527
script: |
2628
const fs = require('fs');
2729
const output = JSON.parse(fs.readFileSync('output.json', 'utf8'));
28-
const { default: process } = await import('${{ github.workspace }}/tools/pkg.pr.new-comment.mjs')
30+
output.number = context.issue.number;
31+
output.event_name = context.eventName;
32+
output.ref = context.ref;
33+
output.sha = context.eventName === 'pull_request'
34+
? context.payload.pull_request.head.sha
35+
: context.payload.after;
36+
fs.writeFileSync('output.json', JSON.stringify(output), 'utf8');
37+
- name: Upload output
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: output
41+
path: ./output.json
2942

30-
await process({github, context, core, output})
43+
- run: ls -R .

tools/pkg.pr.new-comment.mjs

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ export default async function ({ github, context, output }) {
55
// eslint-disable-next-line no-console -- For debugging on github actions.
66
console.log("pkg-pr-new publish output:", JSON.stringify(output));
77

8-
const sha =
9-
context.eventName === "pull_request"
10-
? context.payload.pull_request.head.sha
11-
: context.payload.after;
8+
const sha = output.sha;
129
const commitUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${sha}`;
1310

14-
const pullRequestNumber = await getPullRequestNumber();
11+
const pullRequestNumber = getPullRequestNumber();
1512

1613
const packages = output.packages.map((p) => {
1714
let normalizedUrl = p.url;
@@ -68,24 +65,8 @@ ${packages.map((p) => `- ${p.name}: ${p.url}`).join("\n")}
6865
/* eslint-enable no-console -- For debugging on github actions. */
6966
}
7067

71-
async function getPullRequestNumber() {
72-
if (context.eventName === "pull_request") {
73-
if (context.issue.number) {
74-
return context.issue.number;
75-
}
76-
} else if (context.eventName === "push") {
77-
const pullRequests = await github.rest.pulls.list({
78-
owner: context.repo.owner,
79-
repo: context.repo.repo,
80-
state: "open",
81-
head: `${context.repo.owner}:${context.ref.replace("refs/heads/", "")}`,
82-
});
83-
84-
if (pullRequests.data.length > 0) {
85-
return pullRequests.data[0].number;
86-
}
87-
}
88-
return null;
68+
function getPullRequestNumber() {
69+
return output.number;
8970
}
9071

9172
async function findBotComment(issueNumber) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy