Skip to content

Pre-process example notebooks #116

Pre-process example notebooks

Pre-process example notebooks #116

name: Pre-process example notebooks
on:
workflow_dispatch:
inputs:
pr_number:
description: 'Update the cache for PR#: (leave blank if not a PR)'
required: false
default: ""
type: string
schedule:
- cron: 0 0 * * * # 1/day at midnight UTC
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ inputs.pr_number || github.ref || github.run_id }}
cancel-in-progress: true
jobs:
preprocess:
runs-on: ubuntu-latest
steps:
- name: Choose deployment branch
shell: bash -l {0}
run: |
if [[ ${{ github.event_name }} != "workflow_dispatch" ]]; then
echo "DEPLOY_BRANCH=_cookbook_data_$GITHUB_REF_NAME" >> "$GITHUB_ENV"
elif [[ "${{ inputs.pr_number }}" == "" ]]; then
echo "DEPLOY_BRANCH=_cookbook_data_$GITHUB_REF_NAME" >> "$GITHUB_ENV"
else
echo "DEPLOY_BRANCH=_cookbook_data_PR${{ inputs.pr_number }}" >> "$GITHUB_ENV"
fi
- name: Report dispatch to PR
if: github.event_name == 'workflow_dispatch' && inputs.pr_number != ''
uses: thollander/actions-comment-pull-request@v2
with:
pr_number: ${{ inputs.pr_number }}
message: >
A workflow has been dispatched to regenerate the cookbook cache for this PR.
- Run ID: [${{ github.run_id }}]
- Triggering actor: ${{ github.triggering_actor }}
- Target branch: ${{ github.ref_name }}
- Deployment branch: ${{ env.DEPLOY_BRANCH }}
[${{ github.run_id }}]: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
- name: Create check
if: github.event_name == 'workflow_dispatch' && inputs.pr_number != ''
id: create-check
uses: actions/github-script@v6
with:
script: |
const created_run = await github.request(
'POST /repos/{owner}/{repo}/check-runs',
{
owner: context.repo.owner,
repo: context.repo.repo,
name: '${{ github.job }}',
head_sha: '${{ github.sha }}',
details_url: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}',
status: 'in_progress',
started_at: new Date().toISOString(),
output: {
title: 'Regenerate example notebook cache',
summary: 'Results and progress: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}',
text: ''
},
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
}
)
return created_run.data.id
- uses: actions/checkout@v3
- name: Install Conda environment
uses: mamba-org/setup-micromamba@v1
with:
environment-file: devtools/conda-envs/examples_env.yml
- name: Pre-process and execute notebooks
shell: bash -l {0}
run: |
python source/_ext/proc_examples.py --prefix=deploy/ --cache-branch=${DEPLOY_BRANCH}
- name: Deploy cache
shell: bash -l {0}
run: |
cd deploy
git config --global user.name github-actions
git config --global user.email [email protected]
git config --global init.defaultBranch main
# Create an empty repository so we don't have to fetch (guaranteeing atomicity)
git init .
git remote add origin "https://github-actions:${{ github.token }}@github.com/${{ github.repository }}.git"
# Commit the deployment and force push to the deploy branch
git add .
git commit -m "Deploy pre-processed notebook cache"
git push --force origin HEAD:$DEPLOY_BRANCH
- name: Trigger RTD build
# RTD doesn't offer a way to manually trigger builds in PRs, so we'll just do this for other builds
if: github.event_name == 'schedule' || github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.pr_number == '')
shell: bash -l {0}
run: |
curl -X POST -d "branches=$GITHUB_REF_NAME" -d "token=${{ secrets.RTD_WEBHOOK_TOKEN }}" https://readthedocs.org/api/v2/webhook/openff-docs/243876/
- name: Report status to PR
if: always() && github.event_name == 'workflow_dispatch' && inputs.pr_number != ''
uses: thollander/actions-comment-pull-request@v2
with:
pr_number: ${{ inputs.pr_number }}
message: >
A workflow dispatched to regenerate the cookbook cache for this PR has just finished.
- Run ID: [${{ github.run_id }}]
- Triggering actor: ${{ github.triggering_actor }}
- Target branch: ${{ github.ref_name }}
- Deployment branch: ${{ env.DEPLOY_BRANCH }}
- Status: **${{ job.status }}**
If the workflow was successful, changes will only be visible in the ReadTheDocs
preview after it has been [rebuilt].
[${{ github.run_id }}]: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
[rebuilt]: https://readthedocs.org/projects/openff-docs/builds/
- name: Update check
if: always() && github.event_name == 'workflow_dispatch' && inputs.pr_number != ''
uses: actions/github-script@v6
with:
script: |
await github.request(
'PATCH /repos/{owner}/{repo}/check-runs/{check_run_id}',
{
owner: context.repo.owner,
repo: context.repo.repo,
check_run_id: ${{ steps.create-check.outputs.result }},
status: 'completed',
conclusion: '${{ job.status }}',
completed_at: new Date().toISOString(),
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
}
)