Skip to content

Commit 8b3cd4a

Browse files
petebacondarwindario-piotrowicz
authored andcommitted
ci: add prerelease deployments to npm
1 parent 06a41be commit 8b3cd4a

File tree

4 files changed

+95
-10
lines changed

4 files changed

+95
-10
lines changed

.github/utils/update-version.cjs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Update the package.json version property for the given package
3+
* to a pre-release version based off the current SHA.
4+
*
5+
* Usage:
6+
*
7+
* ```
8+
* node ./.github/utils/version-script.js <package-name>
9+
* ```
10+
*/
11+
12+
const { readFileSync, writeFileSync } = require("node:fs");
13+
const { execSync } = require("node:child_process");
14+
const assert = require("node:assert");
15+
16+
try {
17+
const packagePath = getArgs()[0];
18+
assert(packagePath, "Required package path missing.");
19+
const packageJsonPath = `${packagePath}/package.json`;
20+
const pkg = JSON.parse(readFileSync(packageJsonPath));
21+
const stdout = execSync("git rev-parse --short HEAD", { encoding: "utf8" });
22+
pkg.version = "0.0.0-" + stdout.trim();
23+
writeFileSync(packageJsonPath, JSON.stringify(pkg, null, "\t") + "\n");
24+
} catch (error) {
25+
console.error(error);
26+
process.exit(1);
27+
}
28+
29+
/**
30+
* Get the command line args, stripping `node` and script filename, etc.
31+
*/
32+
function getArgs() {
33+
const args = Array.from(process.argv);
34+
while (args.shift() !== module.filename) {}
35+
return args;
36+
}

.github/workflows/prereleases.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Publish prereleases
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
release:
9+
if: ${{ github.repository_owner == 'flarelabs-net' }}
10+
name: Publish builder package
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout Repo
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Install pnpm
20+
uses: pnpm/action-setup@v4
21+
with:
22+
version: 9.10.0
23+
24+
- name: Install Node.js 20
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: 20
28+
cache: "pnpm"
29+
registry-url: "https://registry.npmjs.org"
30+
31+
- name: Install Dependencies
32+
uses: pnpm i --frozen-lockfile
33+
34+
- name: Build
35+
run: pnpm -F builder run build
36+
37+
- name: Update package.json version
38+
run: node .github/utils/version-script.cjs builder
39+
40+
- name: Publish to NPM
41+
run: pnpm publish -F cloudflare --no-git-checks
42+
env:
43+
NODE_ENV: "production"
44+
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

builder/README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
# Next.js builder for Cloudflare
22

3-
## Build your app
3+
## Configure your app
44

55
- add the following `devDependency` to the `package.json`:
66

7-
```json
8-
"node-url": "npm:url@^0.11.4",
9-
"wrangler": "^3.77.0"
7+
```bash
8+
pnpm add -D wrangler@latest @opennextjs/cloudflare
109
```
1110

12-
- Execute `npx @flarelabs-net/builder@latest` in your app folder
13-
1411
## Serve your app
1512

13+
- build the app and adapt it for Cloudflare
14+
15+
```bash
16+
pnpx cloudflare
17+
```
18+
1619
- add a `wrangler.toml` at the root of your project
1720

1821
```toml
@@ -22,11 +25,13 @@
2225

2326
compatibility_date = "2024-08-29"
2427
compatibility_flags = ["nodejs_compat_v2"]
25-
workers_dev = true
26-
minify = false
2728

2829
# Use the new Workers + Assets to host the static frontend files
2930
experimental_assets = { directory = ".worker-next/assets", binding = "ASSETS" }
3031
```
3132

32-
- Use `wrangler dev`
33+
- Preview the app in Wrangler
34+
35+
```bash
36+
pnpm wrangler dev
37+
```

builder/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@flarelabs-net/builder",
2+
"name": "@opennextjs/cloudflare",
33
"description": "Cloudflare builder for next apps",
44
"version": "0.0.1",
55
"scripts": {

0 commit comments

Comments
 (0)