Skip to content

Commit f5435c3

Browse files
authored
ci: Deploy to Cloudflare using a Github Action (#1159)
* ci: use Cloudflare worker github action * give job a name * fix env * fix project name * functions * add workflow_dispath * stick with out dir for now * try different action * fix name * format * remove environment from inputs * remove () * add pull_request * on changes * add wrangler * update readme * break out into different jobs * update commands * go back to official action * add comment * fix permissions * remove trailing comma * add code block around errors * add back output * wrap in console * add header * disable color output * update wrangler * remove err * run on all branches for PRs
1 parent 8f32205 commit f5435c3

9 files changed

Lines changed: 642 additions & 54 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Deploy to Cloudflare Pages
2+
on:
3+
push:
4+
branches:
5+
- master
6+
workflow_dispatch:
7+
inputs:
8+
environment:
9+
description: "Choose an environment to deploy to: <preview|production>"
10+
required: true
11+
default: "preview"
12+
pull_request:
13+
14+
jobs:
15+
deploy:
16+
runs-on: ubuntu-latest
17+
name: Deploy
18+
permissions:
19+
contents: read
20+
deployments: write
21+
pull-requests: write
22+
steps:
23+
- uses: actions/checkout@v4
24+
- name: Setup yarn
25+
uses: actions/setup-node@v3
26+
with:
27+
cache: "yarn"
28+
node-version: "24"
29+
- name: Install dependencies
30+
run: yarn install
31+
- name: Build
32+
run: yarn build
33+
- name: Deploy
34+
id: deploy
35+
uses: cloudflare/wrangler-action@v3
36+
with:
37+
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
38+
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
39+
command: pages deploy out --project-name=rescript-lang-org
40+
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
41+
wranglerVersion: 4.61.1
42+
continue-on-error: true
43+
env:
44+
FORCE_COLOR: 0
45+
- name: Comment PR with deployment link
46+
uses: marocchino/sticky-pull-request-comment@v2
47+
with:
48+
recreate: true
49+
header: deploymemt
50+
message: |
51+
## Cloudflare deployment
52+
Deployement ID: ${{ steps.deploy.outputs.pages-deployment-id }}
53+
Deployment Environment: ${{ steps.deploy.outputs.pages-environment }}
54+
55+
${{ steps.deploy.outputs.command-output }}

.github/workflows/pull-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ jobs:
1010
node-version-file: ".node-version"
1111
cache: yarn
1212
- run: yarn
13-
- run: yarn res:build --warn-error +3+8+11+12+26+27+31+32+33+34+35+39+44+45+110
13+
- run: yarn build:res --warn-error +3+8+11+12+26+27+31+32+33+34+35+39+44+45+110
1414
- run: yarn test
1515
- run: yarn ci:format

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,11 @@ app/**/*.jsx
5757
!.yarn/sdks
5858
!.yarn/versions
5959

60+
# wrangler
61+
.wrangler
62+
6063
# Scripts generated from rolldown to convert them from .jsx files to .mjs files
61-
_scripts
64+
_scripts
65+
66+
# Local env files
67+
.env

README.md

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,10 @@ This is the official documentation platform for the [ReScript](https://rescript-
2323
# For first time clone / build (install dependencies)
2424
yarn
2525

26-
# Initial build
27-
yarn rescript
28-
29-
# Build the index data. Only needed for initial clone (or content H2 changes)
30-
yarn update-index
31-
32-
# In a new tab
26+
# Run ReScript, Vite, and Wrangler in development mode
3327
yarn dev
34-
35-
open localhost:3000
36-
```
37-
38-
In case you want to run ReScript in watchmode:
39-
40-
```sh
41-
yarn rescript -w
4228
```
4329

44-
## Build Index Data
45-
46-
We are parsing our content for specific index data (such as, all interesting
47-
search terms we need for searching inside the `Belt` docs). You can create your
48-
index by running following command:
49-
50-
```sh
51-
yarn update-index
52-
```
53-
54-
All the index data is stored in `index_data`, but will not be tracked by git.
55-
Make sure to build the index after a fresh clone, otherwise Next might not
56-
build specific pages (file `index_data/x.json` not found).
57-
5830
## Project Structure Overview
5931

6032
- `data`: Contains hand-curated data, such as sidebar ordering, blog data, etc

functions/echo.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export function onRequest(context) {
2+
const url = new URL(context.request.url);
3+
return new Response(url.searchParams.toString());
4+
}

markdown-pages/docs/manual/installation.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ bun create rescript-app
5656
- Trigger a ReScript build:
5757

5858
```sh
59-
npm run res:build
59+
npm run build:res
6060
```
6161
- If you selected the "basic" template, simply run it with:
6262

@@ -156,8 +156,8 @@ bun create rescript-app
156156
- Add convenience `npm` scripts to `package.json`:
157157
```json
158158
"scripts": {
159-
"res:build": "rescript",
160-
"res:dev": "rescript -w"
159+
"build:res": "rescript",
160+
"dev:res": "rescript watch"
161161
}
162162
```
163163

markdown-pages/docs/manual/typescript-integration.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ In case of the TypeScript project using `Bundler` module resolution, `allowImpor
201201

202202
Open any relevant `*.res` file and add `@genType` annotations to any bindings / values / functions to be used from JavaScript. If an annotated value uses a type, the type must be annotated too. See e.g. [Hooks.res](https://github.com/rescript-lang/rescript-compiler/blob/master/jscomp/gentype_tests/typescript-react-example/src/Hooks.res).
203203

204-
Save the file and rebuild the project via `npm run res:build` or similar. You should now see a `*.gen.tsx` file with the same name (e.g. `MyComponent.res` -> `MyComponent.gen.tsx`).
204+
Save the file and rebuild the project via `npm run build:res` or similar. You should now see a `*.gen.tsx` file with the same name (e.g. `MyComponent.res` -> `MyComponent.gen.tsx`).
205205

206206
Any values exported from `MyComponent.res` can then be imported from TypeScript. For example:
207207

package.json

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,25 @@
1010
"packageManager": "yarn@4.12.0",
1111
"type": "module",
1212
"scripts": {
13-
"dev": "react-router dev --host",
14-
"res:watch": "rescript watch",
15-
"res:clean": "rescript clean",
16-
"res:build": "rescript build",
17-
"build": "rescript build && yarn build-scripts && yarn update-index && react-router build",
18-
"test": "node scripts/test-examples.mjs && node scripts/test-hrefs.mjs",
19-
"update-index": "yarn generate-llms && node _scripts/generate_feed.mjs > public/blog/feed.xml",
20-
"reanalyze": "rescript-tools reanalyze -all-cmt .",
21-
"sync-bundles": "node scripts/sync-playground-bundles.mjs",
22-
"generate-llms": "node _scripts/generate_llms.mjs",
23-
"format": "prettier . --write --experimental-cli && rescript format",
13+
"build:scripts": "yarn dlx tsdown@0.20.0 scripts/*.jsx -d _scripts --no-clean --ext .mjs",
14+
"build:generate-llms": "node _scripts/generate_llms.mjs",
15+
"build:res": "rescript build",
16+
"build:sync-bundles": "node scripts/sync-playground-bundles.mjs",
17+
"build:update-index": "yarn build:generate-llms && node _scripts/generate_feed.mjs > public/blog/feed.xml",
18+
"build:vite": "react-router build",
19+
"build": "yarn build:res && yarn build:scripts && yarn build:update-index && yarn build:vite",
2420
"ci:format": "prettier . --check --experimental-cli",
25-
"preview": "yarn build && static-server build/client",
21+
"clean:res": "rescript clean",
2622
"convert-images": "auto-convert-images",
27-
"build-scripts": "yarn dlx tsdown@0.20.0 scripts/*.jsx -d _scripts --no-clean --ext .mjs"
23+
"dev:res": "rescript watch",
24+
"dev:vite": "react-router dev --host",
25+
"dev:wrangler": "yarn wrangler pages dev build/client",
26+
"dev": "yarn prepare && yarn dev:res & yarn dev:vite & yarn dev:wrangler",
27+
"format": "prettier . --write --experimental-cli && rescript format",
28+
"prepare": "yarn build:res && yarn build:scripts && yarn build:update-index",
29+
"preview": "yarn build && static-server build/client",
30+
"reanalyze": "rescript-tools reanalyze -all-cmt .",
31+
"test": "node scripts/test-examples.mjs && node scripts/test-hrefs.mjs"
2832
},
2933
"dependencies": {
3034
"@babel/generator": "^7.24.7",
@@ -93,6 +97,7 @@
9397
"vite": "^7.0.6",
9498
"vite-plugin-devtools-json": "^1.0.0",
9599
"vite-plugin-env-compatible": "^2.0.1",
96-
"vite-plugin-page-reload": "^0.2.2"
100+
"vite-plugin-page-reload": "^0.2.2",
101+
"wrangler": "^4.61.1"
97102
}
98-
}
103+
}

0 commit comments

Comments
 (0)