Skip to content

Add a switcher for 3.15/3.14 #40

Add a switcher for 3.15/3.14

Add a switcher for 3.15/3.14 #40

Workflow file for this run

name: "Build"
on:
push:
branches:
- main
pull_request:
branches:
- main
types:
- opened
- synchronize
- reopened
workflow_dispatch:
inputs:
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:
setup:
name: "Resolve deploy channel"
runs-on: ubuntu-latest
outputs:
deploy_channel: ${{ steps.channel.outputs.deploy_channel }}
deploy_destination: ${{ steps.channel.outputs.deploy_destination }}
steps:
- 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"
build:
name: "Build CPython ${{ matrix.version }}"
needs: setup
runs-on: ubuntu-latest
timeout-minutes: 120
strategy:
fail-fast: false
matrix:
include:
- version: "3.14"
ref: "3.14"
- version: "3.15"
ref: "main"
env:
CPYTHON_REF: ${{ matrix.ref }}
CPYTHON_VERSION: ${{ matrix.version }}
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: "Read pinned Emscripten/Node versions from CPython"
id: versions
shell: python
run: |
import os, tomllib
from pathlib import Path
cfg = tomllib.loads(Path("cpython/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")
- name: "Install Node"
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: ${{ steps.versions.outputs.node_version }}
- name: "Install Emscripten SDK ${{ steps.versions.outputs.emscripten_version }}"
uses: mymindstorm/setup-emsdk@6ab9eb1bda2574c4ddb79809fc9247783eaf9021 # v14
with:
version: ${{ steps.versions.outputs.emscripten_version }}
actions-cache-folder: emsdk-${{ matrix.version }}
- name: "Build"
working-directory: cpython
run: python3 Tools/wasm/emscripten build --quiet
- name: "Stage runtime for ${{ matrix.version }}"
run: |
set -euo pipefail
dest="runtime/cpython/${CPYTHON_VERSION}"
src="cpython/cross-build/wasm32-emscripten/build/python/web_example"
mkdir -p "$dest"
cp "$src/python.mjs" "$dest/"
cp "$src/python.wasm" "$dest/"
cp "$src/python${CPYTHON_VERSION}.zip" "$dest/"
- name: "Upload runtime artifact"
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: cpython-runtime-${{ matrix.version }}
path: runtime
if-no-files-found: error
retention-days: 7
assemble:
name: "Assemble site"
needs: [setup, build]
runs-on: ubuntu-latest
steps:
- name: "Checkout codoscope"
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: "Download runtime artifacts"
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
pattern: cpython-runtime-*
path: runtime-artifacts
merge-multiple: true
- name: "Assemble site"
run: |
set -euo pipefail
cp -a web _site
cp -a runtime-artifacts/cpython _site/cpython
# 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 _site/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: [setup, assemble]
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.setup.outputs.deploy_channel }}
DEPLOY_DESTINATION: ${{ needs.setup.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 3.14/3.15)"
- 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}`,
});