Skip to content

Commit 94dcad6

Browse files
committed
Rationalize deps and add deploy preview
1 parent bbf817f commit 94dcad6

File tree

4 files changed

+176
-42
lines changed

4 files changed

+176
-42
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: Deploy Preview
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
pr_number:
7+
required: true
8+
type: string
9+
commit_sha:
10+
required: true
11+
type: string
12+
action:
13+
required: true
14+
type: string
15+
description: "create or delete preview"
16+
secrets:
17+
TOKEN:
18+
required: true
19+
20+
jobs:
21+
deploy-preview:
22+
name: Deploy Preview
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
with:
28+
token: ${{ secrets.TOKEN }}
29+
ref: gh-pages
30+
path: gh-pages
31+
32+
- name: Setup Node.js
33+
uses: actions/setup-node@v4
34+
with:
35+
node-version: 20
36+
cache: npm
37+
38+
- name: Install dependencies
39+
run: npm install --frozen-lockfile
40+
41+
- name: Restore docs build output
42+
if: inputs.action == 'create'
43+
uses: actions/cache@v4
44+
with:
45+
path: docs/public
46+
key: docs-build-${{ inputs.commit_sha }}
47+
restore-keys: |
48+
docs-build-
49+
50+
- name: Create preview directory
51+
if: inputs.action == 'create'
52+
run: |
53+
mkdir -p gh-pages/preview/PR${{ inputs.pr_number }}
54+
cp -r docs/public/* gh-pages/preview/PR${{ inputs.pr_number }}/
55+
56+
- name: Remove preview directory
57+
if: inputs.action == 'delete'
58+
run: |
59+
rm -rf gh-pages/preview/PR${{ inputs.pr_number }}
60+
61+
- name: Commit and push changes
62+
run: |
63+
cd gh-pages
64+
git config user.name "github-actions[bot]"
65+
git config user.email "github-actions[bot]@users.noreply.github.com"
66+
67+
if [ "${{ inputs.action }}" = "create" ]; then
68+
git add preview/PR${{ inputs.pr_number }}
69+
git commit -m "Add preview for PR #${{ inputs.pr_number }}"
70+
else
71+
git add -A
72+
git commit -m "Remove preview for PR #${{ inputs.pr_number }}"
73+
fi
74+
75+
git push origin gh-pages
76+
77+
- name: Comment on PR
78+
if: inputs.action == 'create'
79+
uses: actions/github-script@v7
80+
with:
81+
script: |
82+
const previewUrl = `https://${{ github.repository_owner }}.github.io/execution-apis/preview/PR${{ inputs.pr_number }}/`;
83+
github.rest.issues.createComment({
84+
issue_number: ${{ inputs.pr_number }},
85+
owner: '${{ github.repository_owner }}',
86+
repo: '${{ github.event.repository.name }}',
87+
body: `🚀 **Deploy Preview Available!**
88+
89+
Your changes are now available for preview at: **${previewUrl}**
90+
91+
This preview will be automatically removed when the PR is merged.`
92+
});
93+
94+
- name: Remove preview comment
95+
if: inputs.action == 'delete'
96+
uses: actions/github-script@v7
97+
with:
98+
script: |
99+
const { data: comments } = await github.rest.issues.listComments({
100+
issue_number: ${{ inputs.pr_number }},
101+
owner: '${{ github.repository_owner }}',
102+
repo: '${{ github.event.repository.name }}'
103+
});
104+
105+
const previewComment = comments.find(comment =>
106+
comment.body.includes('Deploy Preview Available!') &&
107+
comment.user.login === 'github-actions[bot]'
108+
);
109+
110+
if (previewComment) {
111+
await github.rest.issues.deleteComment({
112+
comment_id: previewComment.id,
113+
owner: '${{ github.repository_owner }}',
114+
repo: '${{ github.event.repository.name }}'
115+
});
116+
}

.github/workflows/test-deploy.yaml

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ on:
44
pull_request:
55
branches:
66
- main
7-
# Review gh actions docs if you want to further define triggers, paths, etc
8-
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on
97
workflow_dispatch:
108

119
jobs:
@@ -14,7 +12,7 @@ jobs:
1412
runs-on: ubuntu-latest
1513
strategy:
1614
matrix:
17-
node-version: [20, 22, 24]
15+
node-version: [20, 22]
1816
steps:
1917
- uses: actions/checkout@v4
2018
with:
@@ -29,4 +27,46 @@ jobs:
2927
- name: Test build website
3028
run: |
3129
npm run build
32-
npm run build:docs
30+
npm run build:docs
31+
32+
deploy:
33+
name: Deploy
34+
runs-on: ubuntu-latest
35+
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
36+
strategy:
37+
matrix:
38+
node-version: [24]
39+
steps:
40+
- uses: actions/checkout@v4
41+
with:
42+
fetch-depth: 0
43+
- uses: actions/setup-node@v4
44+
with:
45+
node-version: ${{ matrix.node-version }}
46+
cache: npm
47+
48+
- name: Install dependencies
49+
run: npm install --frozen-lockfile
50+
- name: Build docs
51+
run: |
52+
npm run build
53+
npm run build:docs
54+
- name: Cache docs build output
55+
uses: actions/cache@v4
56+
with:
57+
path: docs/public
58+
key: docs-build-${{ github.sha }}
59+
restore-keys: |
60+
docs-build-
61+
62+
deploy-preview:
63+
name: Deploy Preview
64+
needs: deploy
65+
if: github.event_name == 'pull_request'
66+
uses: ./.github/workflows/deploy-preview.yaml
67+
with:
68+
pr_number: ${{ github.event.number }}
69+
commit_sha: ${{ github.sha }}
70+
action: ${{ github.event.action == 'closed' && 'delete' || 'create' }}
71+
secrets:
72+
TOKEN: ${{ secrets.GITHUB_TOKEN }}

package-lock.json

Lines changed: 10 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
"scripts": {
77
"build": "npm run build:spec",
88
"build:spec": "node scripts/build.js",
9+
"build:test": "which go > /dev/null 2>&1 || (echo 'Error: Go binary not found. Please install Go first.' && exit 1) && go install github.com/lightclient/rpctestgen/cmd/speccheck@latest",
910
"build:docs": "npm run generate-clients && npm run build:docs:gatsby",
1011
"build:docs:gatsby": "cp README.md docs/reference/quickstart.md && cd build/docs/gatsby && npm install && gatsby build --prefix-paths",
1112
"lint": "node scripts/build.js && node scripts/validate.js && node scripts/graphql-validate.js",
1213
"clean": "rm -rf build && mkdir -p build",
1314
"generate-clients": "mkdir -p build && open-rpc-generator generate -c open-rpc-generator-config.json",
1415
"graphql:schema": "node scripts/graphql.js",
1516
"graphql:validate": "node scripts/graphql-validate.js",
16-
"serve": "cd build/docs/gatsby && gatsby develop"
17+
"serve": "cd build/docs/gatsby && gatsby develop",
18+
"test": "speccheck -v"
1719
},
1820
"repository": {
1921
"type": "git",
@@ -26,24 +28,17 @@
2628
},
2729
"type": "module",
2830
"homepage": "https://github.com/ethereum/execution-apis#readme",
29-
"devDependencies": {
31+
"dependencies": {
32+
"@mdx-js/react": "~3.0.0",
3033
"@graphql-inspector/core": "~3.3.0",
3134
"@open-rpc/generator": "^2.1.0",
3235
"@open-rpc/schema-utils-js": "^2.1.2",
3336
"gatsby": "^5.14.3",
34-
"gh-pages": "~4.0.0",
3537
"graphql": "~16.3.0",
3638
"graphql-request": "~4.1.0",
3739
"js-yaml": "~4.1.0",
3840
"json-schema-merge-allof": "~0.8.1",
39-
"remark-gfm": "^4.0.1",
41+
"remark-gfm": "~4.0.1",
4042
"typescript": "~5.6.2"
41-
},
42-
"dependencies": {
43-
"@mdx-js/react": "^3.0.0",
44-
"clsx": "^2.0.0",
45-
"prism-react-renderer": "^2.3.0",
46-
"react": "^18.0.0",
47-
"react-dom": "^18.0.0"
4843
}
4944
}

0 commit comments

Comments
 (0)