Skip to content

Commit d4bd878

Browse files
committed
Add website PR creation script
1 parent 93fb3ae commit d4bd878

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

.github/scripts/readme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ For every push to `next`:
4747
- labels: `release`
4848
```
4949

50+
```
51+
- create a PR from 'next' to 'main' if it doesn't exist
52+
- title: Update website
53+
```
54+
5055
## release-pr-merged
5156

5257
for every `release` pr merged to `next`:

.github/scripts/website-pr.mjs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Octokit } from "@octokit/action"
2+
import github from "@actions/github"
3+
import { BASE_BRANCH } from "./params.mjs"
4+
5+
const octokit = new Octokit({})
6+
7+
console.log("Find existing PR")
8+
const { data: prs } = await octokit.pulls.list({
9+
...github.context.repo,
10+
state: "open",
11+
base: "main",
12+
head: `${github.context.repo.owner}:${BASE_BRANCH}`,
13+
})
14+
console.log("Existing PRs", prs)
15+
16+
const title = `✨ Update website ✨`
17+
const body = ""
18+
19+
if (prs.length === 0) {
20+
console.log("Creating new PR")
21+
await octokit.rest.pulls.create({
22+
...github.context.repo,
23+
base: "main",
24+
head: BASE_BRANCH,
25+
title,
26+
body,
27+
})
28+
} else {
29+
// console.log("Updating existing PR")
30+
// const { number } = prs[0]
31+
// await octokit.rest.pulls.update({
32+
// ...github.context.repo,
33+
// pull_number: number,
34+
// title,
35+
// body,
36+
// })
37+
}

.github/workflows/push-to-next.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,32 @@ jobs:
4343
run: node .github/scripts/prepare-release.mjs
4444
env:
4545
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
47+
website-pr:
48+
name: Update website PR
49+
runs-on: ubuntu-latest
50+
51+
permissions:
52+
pull-requests: write
53+
54+
steps:
55+
- name: Checkout code
56+
uses: actions/checkout@v4
57+
58+
- name: Install pnpm
59+
uses: pnpm/action-setup@v4
60+
with:
61+
run_install: false
62+
63+
- name: Set up Node.js
64+
uses: actions/setup-node@v4
65+
with:
66+
node-version: 20
67+
cache: "pnpm"
68+
69+
- run: pnpm install
70+
71+
- name: Create or update website PR
72+
run: node .github/scripts/website-pr.mjs
73+
env:
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)