Skip to content

Commit a76673d

Browse files
committed
publish preview version of main branch commits
1 parent c5e83e8 commit a76673d

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

.github/workflows/main-publish.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Package Main Publish
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
publish-main:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Enable corepack
16+
run: corepack enable
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: 20
22+
cache: "npm"
23+
24+
- name: Install dependencies
25+
run: npm install
26+
27+
- name: Build package
28+
run: npm run build
29+
30+
- name: Publish main version with pkg.pr.new
31+
run: npx pkg-pr-new publish --json output.json --comment=off
32+
33+
- name: Comment commit with install instructions
34+
uses: actions/github-script@v6
35+
with:
36+
script: |
37+
const fs = require('fs');
38+
const output = JSON.parse(fs.readFileSync('output.json', 'utf8'));
39+
if (!output.packages || output.packages.length === 0) {
40+
core.setFailed('No packages published by pkg.pr.new');
41+
return;
42+
}
43+
const pkg = output.packages[0];
44+
const installCmd = `npm i ${pkg.url}`;
45+
const badge = `[![pkg.pr.new](https://pkg.pr.new/badge/${context.repo.owner}/${context.repo.repo})](https://pkg.pr.new/~/${context.repo.owner}/${context.repo.repo})`;
46+
const body = `### 🚀 Main Branch Package Published!
47+
48+
${badge}
49+
50+
---
51+
52+
**Install this main branch build with npm:**
53+
54+
\`\`\`sh
55+
${installCmd}
56+
\`\`\`
57+
58+
- 📦 [Main Package on pkg.pr.new](${pkg.url})
59+
- 🔗 [View this commit on GitHub](https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${pkg.commit})
60+
61+
---
62+
<sub>Package powered by [pkg.pr.new](https://pkg.pr.new) — instant package publishing from your main branch!</sub>
63+
`;
64+
65+
// Create a comment on the commit
66+
await github.rest.repos.createCommitComment({
67+
owner: context.repo.owner,
68+
repo: context.repo.repo,
69+
commit_sha: context.sha,
70+
body: body,
71+
});
72+
73+
permissions:
74+
contents: read

0 commit comments

Comments
 (0)