Skip to content

Commit 92cb19e

Browse files
committed
Enhance deployment script and documentation for GitHub Pages
- Updated deploy.sh to include error handling and SSH support for GitHub repository URLs. - Modified package.json to streamline the deploy command. - Improved README.md with clearer deployment instructions and emphasized the use of the main branch for GitHub Pages.
1 parent ca80689 commit 92cb19e

5 files changed

Lines changed: 112 additions & 37 deletions

File tree

.github/workflows/build.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [src]
6+
pull_request:
7+
branches: [src]
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: ci-${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
strategy:
18+
matrix:
19+
node-version: [20.x, 22.x]
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: actions/setup-node@v4
23+
with:
24+
node-version: ${{ matrix.node-version }}
25+
cache: npm
26+
- name: Install
27+
run: npm ci
28+
- name: Build
29+
run: npm run build
30+
31+
deploy:
32+
needs: build
33+
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
34+
runs-on: ubuntu-latest
35+
permissions:
36+
contents: write
37+
steps:
38+
- uses: actions/checkout@v4
39+
- uses: actions/setup-node@v4
40+
with:
41+
node-version: 22
42+
cache: npm
43+
- name: Install
44+
run: npm ci
45+
- name: Build
46+
run: npm run build
47+
- name: Deploy to GitHub Pages (main)
48+
uses: peaceiris/actions-gh-pages@v4
49+
with:
50+
github_token: ${{ secrets.GITHUB_TOKEN }}
51+
publish_dir: ./build
52+
publish_branch: main
53+
force_orphan: true
54+
user_name: github-actions[bot]
55+
user_email: 41898282+github-actions[bot]@users.noreply.github.com

README.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ This website is built using [Docusaurus 3](https://docusaurus.io/), a modern sta
66

77
Requires **Node.js 18+** (see `.node-version`).
88

9+
Source lives on the **`src`** branch. GitHub Pages serves the built site from
10+
**`main`**.
11+
912
## Installation
1013

1114
```console
@@ -18,23 +21,42 @@ npm install
1821
npm start
1922
```
2023

21-
This command starts a local development server and open up a browser window. Most changes are reflected live without having to restart the server.
24+
This command starts a local development server and opens a browser window. Most changes are reflected live without having to restart the server.
2225

2326
## Build
2427

2528
```console
2629
npm run build
2730
```
2831

29-
This command generates static content into the `build` directory and can be served using any static contents hosting service.
32+
This command generates static content into the `build` directory.
3033

3134
## Deployment
3235

36+
### Automatic (recommended)
37+
38+
Push to the **`src`** branch (or run the workflow manually). GitHub Actions
39+
builds the site and publishes `build/` to **`main`** (GitHub Pages).
40+
41+
Workflow: [`.github/workflows/ci.yml`](.github/workflows/ci.yml)
42+
43+
### Manual
44+
45+
```console
46+
npm run deploy
47+
```
48+
49+
Requires push access to the repo (SSH recommended). Optional overrides:
50+
3351
```console
34-
GIT_USER=<Your GitHub username> USE_SSH=true npm run deploy
52+
GIT_DEPLOY_REPO=git@github.com:rescript-react-native/rescript-react-native.github.io.git \
53+
GIT_USER_NAME="Your Name" \
54+
GIT_USER_EMAIL="you@example.com" \
55+
npm run deploy
3556
```
3657

37-
If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
58+
> Do not use `docusaurus deploy` / a `gh-pages` branch for this repo — Pages is
59+
> configured on `main`.
3860
3961
---
4062

deploy.sh

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
11
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Publish the static site from ./build to the GitHub Pages branch (main).
5+
# Source lives on the `src` branch; GitHub Pages serves `main`.
6+
7+
ROOT="$(cd "$(dirname "$0")" && pwd)"
8+
cd "$ROOT"
9+
10+
if [[ ! -d build ]]; then
11+
echo "Missing ./build — run \`npm run build\` first (or \`npm run deploy\`)." >&2
12+
exit 1
13+
fi
14+
215
GIT_DEPLOY_REPO=${GIT_DEPLOY_REPO:-$(node -e 'process.stdout.write(require("./package.json").repository)')}
316

4-
cd build && \
5-
rm -rf .git && \
6-
git init && \
7-
git checkout -b main && \
8-
git add . -A && \
9-
git commit -m "Deploy to GitHub Pages" && \
17+
# Prefer SSH when the default HTTPS URL is used (typical for local deploys).
18+
if [[ "${GIT_DEPLOY_REPO}" == https://github.com/* ]]; then
19+
GIT_DEPLOY_REPO="git@github.com:${GIT_DEPLOY_REPO#https://github.com/}"
20+
GIT_DEPLOY_REPO="${GIT_DEPLOY_REPO%.git}.git"
21+
fi
22+
23+
cd build
24+
rm -rf .git
25+
git init
26+
git checkout -b main
27+
git add -A
28+
git -c user.name="${GIT_USER_NAME:-github-pages}" \
29+
-c user.email="${GIT_USER_EMAIL:-github-pages@users.noreply.github.com}" \
30+
commit -m "Deploy to GitHub Pages"
1031
git push --force "${GIT_DEPLOY_REPO}" main:main
32+
33+
echo "Deployed to ${GIT_DEPLOY_REPO} (main)"

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
"start": "docusaurus start",
99
"build": "docusaurus build",
1010
"swizzle": "docusaurus swizzle",
11-
"deploy": "docusaurus deploy",
11+
"deploy": "npm run build && ./deploy.sh",
1212
"clear": "docusaurus clear",
1313
"serve": "docusaurus serve",
1414
"write-translations": "docusaurus write-translations",
15-
"write-heading-ids": "docusaurus write-heading-ids",
16-
"publish": "npm run build && ./deploy.sh"
15+
"write-heading-ids": "docusaurus write-heading-ids"
1716
},
1817
"dependencies": {
1918
"@docusaurus/core": "^3.10.2",

0 commit comments

Comments
 (0)