Ensure that the SymPy version always remains up to date #54
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Deploy | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- "*" | |
# First, grab pyodide-lock.json from the latest release in https://github.com/pyodide/pyodide-recipes, | |
# whichever it is. Store the Pyodide SymPy version in a variable. | |
# Similarly, grab the latest version of SymPy from PyPI and store it in a variable. | |
# If the SymPy version in Pyodide is older than the one that's available in PyPI, | |
# then we download the PyPI wheel and make it available to the next step. | |
jobs: | |
determine-sympy-version: | |
runs-on: | |
ubuntu-latest | |
steps: | |
- name: Grab pyodide-lock.json from latest pyodide-recipes release | |
run: | | |
gh release download \ | |
--repo pyodide/pyodide-recipes \ | |
--pattern "pyodide-lock.json" \ | |
--dir . | |
- name: Get Pyodide and PyPI SymPy versions | |
run: | | |
PYODIDE_SYMPY_VERSION=$(jq -r '.packages.sympy.version' pyodide-lock.json)" >> $GITHUB_ENV | |
PYPI_SYMPY_VERSION=$(curl -s https://pypi.org/pypi/sympy/json | jq -r '.info.version' | grep -Ev 'alpha|a|beta|b|preview|pre|c|rc|dev') >> $GITHUB_ENV | |
- name: Install packaging | |
run: python -m pip install packaging | |
- name: Compare versions and download SymPy, if necessary | |
id: sympy-version-check | |
shell: python | |
run: | | |
import os | |
from packaging.version import Version | |
PYPI_SYMPY_VERSION = os.environ["PYPI_SYMPY_VERSION"] | |
PYODIDE_SYMPY_VERSION = os.environ["PYODIDE_SYMPY_VERSION"] | |
SHOULD_DOWNLOAD = Version(PYPI_SYMPY_VERSION) > Version(PYODIDE_SYMPY_VERSION) | |
if SHOULD_DOWNLOAD: | |
print("Downloading the latest version of SymPy from PyPI using the JSON API, excluding release candidates and pre-releases.") | |
import urllib.request | |
import json | |
url = "https://pypi.org/pypi/sympy/json" | |
response = urllib.request.urlopen(url) | |
data = json.loads(response.read()) | |
urllib.request.urlretrieve(download_url, f"sympy-{PYPI_SYMPY_VERSION}-py3-none-any.whl") | |
else: | |
print("The SymPy version in Pyodide is up-to-date with the latest version in PyPI, no need to download.") | |
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as f: | |
f.write(f"should_download: {SHOULD_DOWNLOAD}\n") | |
- name: Upload the wheel, if downloaded | |
if: steps.sympy-version-check.outputs.should_download == 'True' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: sympy-wheel-${{ github.run_id }} | |
path: sympy-*-py3-none-any.whl | |
if-no-files-found: error | |
build-jupyterlite: | |
runs-on: ubuntu-latest | |
needs: [determine-sympy-version] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.11" | |
- name: Download the wheel, if necessary | |
if: needs.determine-sympy-version.outputs.should_download == 'True' | |
uses: actions/download-artifact@v4 | |
with: | |
name: sympy-wheel-${{ github.run_id }} | |
path: custom_wheels | |
merge-multiple: true | |
- name: Install the dependencies | |
run: | | |
python -m pip install -r requirements.txt | |
- name: Build the JupyterLite site | |
run: | | |
jupyter lite build | |
- name: Add custom index.html (live.sympy.org landing page) and static/ files | |
run: | | |
./generateindex.py | |
- name: Add CNAME file containing live.sympy.org | |
run: | | |
echo "live.sympy.org" > ./_output/CNAME | |
- name: Upload (dist) | |
uses: actions/upload-artifact@v4 | |
with: | |
name: jupyterlite-demo-dist-${{ github.run_number }} | |
path: ./_output | |
if-no-files-found: error | |
deploy: | |
if: github.ref == 'refs/heads/main' | |
needs: [build-jupyterlite] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2.3.1 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: jupyterlite-demo-dist-${{ github.run_number }} | |
path: ./dist | |
merge-multiple: true | |
- name: Deploy | |
uses: JamesIves/github-pages-deploy-action@4.1.3 | |
with: | |
branch: gh-pages | |
folder: dist |