-
Notifications
You must be signed in to change notification settings - Fork 5
231 lines (213 loc) · 8.15 KB
/
Copy pathcpython-wasm.yml
File metadata and controls
231 lines (213 loc) · 8.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
name: "Build"
on:
push:
branches:
- main
pull_request:
branches:
- main
types:
- opened
- synchronize
- reopened
workflow_dispatch:
inputs:
cpython_ref:
required: true
default: "main"
description: "Ref of CPython to build"
deploy_channel:
required: true
default: "stable"
description: "Where to publish the site (manual runs)"
type: choice
options:
- stable
# Maybe rebuild evrery now and again?
# schedule:
# - cron: ""
permissions: {}
concurrency:
group: cpython-wasm
cancel-in-progress: false
jobs:
get-emscripten-version:
name: "Read pinned Emscripten/Node versions from CPython"
runs-on: ubuntu-latest
outputs:
emscripten_version: ${{ steps.versions.outputs.emscripten_version }}
node_version: ${{ steps.versions.outputs.node_version }}
cpython_ref: ${{ steps.ref.outputs.cpython_ref }}
deploy_channel: ${{ steps.channel.outputs.deploy_channel }}
deploy_destination: ${{ steps.channel.outputs.deploy_destination }}
steps:
- name: "Resolve cpython ref"
id: ref
env:
REF_INPUT: ${{ inputs.cpython_ref }}
run: |
ref="${REF_INPUT:-main}"
echo "cpython_ref=$ref" >> "$GITHUB_OUTPUT"
- name: "Resolve deploy channel"
id: channel
env:
CHANNEL_INPUT: ${{ inputs.deploy_channel }}
EVENT_NAME: ${{ github.event_name }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
if [ "$EVENT_NAME" = "push" ]; then
channel="stable"
destination=""
elif [ "$EVENT_NAME" = "pull_request" ]; then
channel="preview"
destination="pr-${PR_NUMBER}"
else
channel="${CHANNEL_INPUT:-stable}"
destination=""
fi
echo "deploy_channel=$channel" >> "$GITHUB_OUTPUT"
echo "deploy_destination=$destination" >> "$GITHUB_OUTPUT"
- name: "Checkout cpython @ ${{ steps.ref.outputs.cpython_ref }}"
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: "python/cpython"
ref: ${{ steps.ref.outputs.cpython_ref }}
persist-credentials: false
- name: "Install Python"
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3.x"
- name: "Read config.toml"
id: versions
shell: python
run: |
import os, tomllib
from pathlib import Path
cfg = tomllib.loads(Path("Platforms/emscripten/config.toml").read_text())
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
f.write(f"emscripten_version={cfg['emscripten-version']}\n")
f.write(f"node_version={cfg['node-version']}\n")
build:
name: "Cross-compile CPython to wasm32-emscripten"
needs: get-emscripten-version
runs-on: ubuntu-latest
timeout-minutes: 120
env:
CPYTHON_REF: ${{ needs.get-emscripten-version.outputs.cpython_ref }}
defaults:
run:
working-directory: cpython
steps:
- name: "Checkout codoscope"
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
path: codoscope
persist-credentials: false
- name: "Checkout cpython@${{ env.CPYTHON_REF }}"
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: "python/cpython"
ref: ${{ env.CPYTHON_REF }}
path: cpython
persist-credentials: false
- name: "Install build Python"
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3"
- name: "Install Node"
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: ${{ needs.get-emscripten-version.outputs.node_version }}
- name: "Install Emscripten SDK ${{ needs.get-emscripten-version.outputs.emscripten_version }}"
uses: mymindstorm/setup-emsdk@6ab9eb1bda2574c4ddb79809fc9247783eaf9021 # v14
with:
version: ${{ needs.get-emscripten-version.outputs.emscripten_version }}
actions-cache-folder: emsdk-cache
- name: "Build"
run: python3 Tools/wasm/emscripten build --quiet
- name: "Stage site"
working-directory: ${{ github.workspace }}
run: |
mkdir _site
cp -a cpython/cross-build/wasm32-emscripten/build/python/web_example/. _site/
rm _site/server.py
cp codoscope/web/index.html _site/index.html
cp codoscope/web/driver.py _site/driver.py
if [ -f codoscope/web/python.worker.mjs ]; then
cp codoscope/web/python.worker.mjs _site/python.worker.mjs
fi
- name: "Add Pages bits"
shell: bash
working-directory: ${{ github.workspace }}/_site
run: |
set -euo pipefail
# GitHub Pages cannot set COOP/COEP headers, but the Emscripten
# thingy needs SharedArrayBuffer. coi-serviceworker installs
# those headers client-side (which costs us one automatic reload).
# The <script src="coi-serviceworker.js"> tag lives in web/index.html.
curl -fsSL -o coi-serviceworker.js \
https://cdn.jsdelivr.net/gh/gzuidhof/coi-serviceworker@7b1d2a092d0d2dd2b7270b6f12f13605de26f214/coi-serviceworker.min.js
- name: "Upload site artifact"
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: site
path: _site
if-no-files-found: error
retention-days: 7
include-hidden-files: true
deploy:
name: "Publish site"
needs: [get-emscripten-version, build]
runs-on: ubuntu-latest
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
permissions:
contents: write
pull-requests: write
env:
DEPLOY_CHANNEL: ${{ needs.get-emscripten-version.outputs.deploy_channel }}
DEPLOY_DESTINATION: ${{ needs.get-emscripten-version.outputs.deploy_destination }}
steps:
- name: "Checkout"
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: true
- name: "Download site artifact"
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
name: site
path: site
- name: "Deploy PR preview site"
if: env.DEPLOY_CHANNEL == 'preview'
uses: peaceiris/actions-gh-pages@e9c66a37f080288a11235e32cbe2dc5fb3a679cc # v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./site
publish_branch: gh-pages
destination_dir: ${{ env.DEPLOY_DESTINATION }}
keep_files: true
force_orphan: false
commit_message: "Publish PR preview #${{ github.event.pull_request.number }}"
- name: "Deploy stable site to gh-pages root"
if: env.DEPLOY_CHANNEL == 'stable'
uses: peaceiris/actions-gh-pages@e9c66a37f080288a11235e32cbe2dc5fb3a679cc # v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./site
publish_branch: gh-pages
keep_files: true
force_orphan: false
commit_message: "Publish site from main (cpython@${{ needs.get-emscripten-version.outputs.cpython_ref || 'main' }})"
- name: "Comment PR preview URL"
if: env.DEPLOY_CHANNEL == 'preview'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const previewUrl = `https://${owner}.github.io/${repo}/${process.env.DEPLOY_DESTINATION}/`;
await github.rest.issues.createComment({
owner,
repo,
issue_number: context.issue.number,
body: `Preview deployed: ${previewUrl}`,
});