Skip to content

Commit

Permalink
Rewrite the deploy workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
juntyr committed Feb 15, 2025
1 parent 3d1e556 commit a12dde7
Show file tree
Hide file tree
Showing 3 changed files with 297 additions and 158 deletions.
294 changes: 294 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
name: Build and Deploy

on:
push:
branches:
- main
release:
branch: main
types: [released]

jobs:
build-pyodide:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Check the Pyodide version
run: |
echo "PYODIDE_SHA_SHORT=$(git submodule status pyodide | cut -c 2-8)" >> $GITHUB_ENV
- name: Cache the Pyodide build
uses: actions/cache@v4
with:
path: ./pyodide
key: pyodide-${{ github.ref }}-${{ env.PYODIDE_SHA_SHORT }}
restore-keys: |
pyodide-${{ github.ref }}-${{ env.PYODIDE_SHA_SHORT }}
pyodide-${{ github.ref }}
pyodide-refs/heads/main
- name: Ensure that the Pyodide source files are fresh
run: |
cd pyodide
git status
git diff --name-only | xargs git checkout --
git clean -df
echo ======
git status
- name: Cache the Pyodide Docker image
uses: ScribeMD/[email protected]
with:
key: docker-pyodide-${{ hashFiles('pyodide/Dockerfile') }}

- name: Discover the cached Pyodide Docker image
run: echo "PYODIDE_DOCKER_IMAGE=$(docker images climet-eu/pyodide --format '{{.ID}}')" >> $GITHUB_ENV

- name: Build the Pyodide Docker image
if: ${{ env.PYODIDE_DOCKER_IMAGE == '' }}
run: |
cd pyodide
docker build -t climet-eu/pyodide .
echo "PYODIDE_DOCKER_IMAGE=$(docker build . -q)" >> $GITHUB_ENV
- name: Build Pyodide and all required packages
run: |
cd pyodide
./run_docker \
--non-interactive \
PYODIDE_PACKAGES="$(cat ../venv/packages.txt | paste -sd "," -)" \
make
- name: Clean up the Pyodide build
run: |
python tools/clean-dist.py pyodide/dist
cd pyodide
find . -name jupyter-lite.json -delete
find . -name jupyter_lite_config.json -delete
rm -f dist/tsconfig.tsbuildinfo
mkdir -p packages/numpy/build
touch packages/numpy/build/ls-success
ls -d packages/*/build/* | xargs rm -r
- name: Upload the pyodide-lock.json artifact
uses: actions/upload-artifact@v4
with:
name: pyodide-lock.json
path: pyodide/dist/pyodide-lock.json

- name: Upload the Pyodide distribution artifact
uses: actions/upload-artifact@v4
with:
name: pyodide
path: pyodide/dist

- name: Remove the uploaded Pyodide distribution
run: rm -rf pyodide/dist

build-pypa:
runs-on: ubuntu-latest
needs: build-pyodide
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Download the pyodide-lock.json artifact
uses: actions/download-artifact@v4
with:
name: pyodide-lock.json
path: pyodide/dist

- name: Extract the PyPa simple repository API
run: python tools/pypa-simple.py pypa/simple ../../../static/pyodide/

- name: Upload the PyPa repository artifact
uses: actions/upload-artifact@v4
with:
name: pypa
path: pypa

build-lock:
runs-on: ubuntu-latest
needs: [build-pyodide, build-pypa]
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Cache the Pyodide Docker image
uses: ScribeMD/[email protected]
with:
key: docker-pyodide-${{ hashFiles('pyodide/Dockerfile') }}
read-only: true

- name: Discover the cached Pyodide Docker image
run: echo "PYODIDE_DOCKER_IMAGE=$(docker images climet-eu/pyodide --format '{{.ID}}')" >> $GITHUB_ENV

- name: Download the Pyodide distribution artifact
uses: actions/download-artifact@v4
with:
name: pyodide
path: pyodide/dist

- name: Download the PyPa repository artifact
uses: actions/download-artifact@v4
with:
name: pypa
path: pyodide/pypa

- name: Extract the PyPi-enabled pyodide-lock.json
run: |
cp venv/requirements.txt pyodide/my-requirements.txt
cp tools/pypi-lock.mjs pyodide/dist/pypi-lock.mjs
cd pyodide
./run_docker --non-interactive python -m http.server "&" node dist/pypi-lock.mjs my-requirements.txt dist/pypi-pyodide-lock.json
- name: Upload the pypi-pyodide-lock.json artifact
uses: actions/upload-artifact@v4
with:
name: pypi-pyodide-lock.json
path: pyodide/dist/pypi-pyodide-lock.json

check-venv:
runs-on: ubuntu-latest
needs: build-pyodide
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12.7"

- name: Download the pyodide-lock.json artifact
uses: actions/download-artifact@v4
with:
name: pyodide-lock.json
path: pyodide/dist

- name: Extract the requirements from the Pyodide build
run: python tools/requirements.py

- name: Check that the venv requirements are up-to-date
run: |
git diff ./venv/
git diff ./venv --check
- name: Check the requirements.txt file
continue-on-error: ${{ github.event_name != 'release' }}
run: |
python -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
python -m pip install -r venv/requirements.txt --dry-run --ignore-installed
deactivate
rm -rf .venv
- name: Check the validity of the constraints.txt and requirements.in files
continue-on-error: ${{ github.event_name != 'release' }}
run: |
python -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
python -m pip install -r files/constraints.txt -r files/requirements.in --dry-run --ignore-installed
deactivate
rm -rf .venv
build-jupyterlite:
runs-on: ubuntu-latest
needs: build-pyodide
steps:
- name: Checkout the repository
uses: actions/checkout@v4

- name: Install the dependencies
run: |
python -m pip install -r requirements.txt
- name: Prepare the JupyterLite input files
run: |
mkdir -p files
cp ./README.md files/
cp venv/constraints.txt venv/requirements.in venv/requirements.txt files/
mkdir -p static
- name: Download the Pyodide distribution artifact
uses: actions/download-artifact@v4
with:
name: pyodide
path: static/pyodide

- name: Download the pypi-pyodide-lock.json artifact
uses: actions/download-artifact@v4
with:
name: pypi-pyodide-lock.json
path: static/pyodide

- name: Build the JupyterLite site
run: |
jupyter lite build --output-dir staging
cp static/favicons/favicon.ico staging/
find staging/ -name favicon.ico | xargs -L1 cp -f static/favicons/favicon.ico
- name: Download the PyPa repository artifact
uses: actions/download-artifact@v4
with:
name: pypa
path: staging/pypa

- name: Upload the JupyterLite artifact
uses: actions/upload-artifact@v4
with:
name: jupyterlite
path: staging

deploy:
permissions:
contents: write
runs-on: ubuntu-latest
needs: build-jupyterlite
steps:
- name: Get the current branch name
uses: tj-actions/branch-names@v8
id: branch

- name: Compute the current version name
run: echo "CLIMETLAB_VERSION=${{ steps.branch.outputs.current_branch || steps.branch.outputs.tag }}" >> $GITHUB_ENV

- name: Checkout the previous dist branch
uses: actions/checkout@v4
with:
ref: dist
path: dist
continue-on-error: ${{ github.event_name != 'release' }}

- name: Prepare merging the different dist versions
run: |
mkdir -p dist
rm -rf dist/${{ env.CLIMETLAB_VERSION }}
- name: Download the JupyterLite artifact into the dist
uses: actions/download-artifact@v4
with:
name: jupyterlite
path: dist/${{ env.CLIMETLAB_VERSION }}

# - name: Deploy to dist branch
# uses: peaceiris/actions-gh-pages@v4
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# publish_branch: dist
# publish_dir: ./dist
# keep_files: false
# force_orphan: true
Loading

0 comments on commit a12dde7

Please sign in to comment.