Skip to content

Allow highlighting lines (#25) #30

Allow highlighting lines (#25)

Allow highlighting lines (#25) #30

Workflow file for this run

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}`,
});