Skip to content

Bump actions/download-artifact from 1 to 4.1.7 in /.github/workflows #364

Bump actions/download-artifact from 1 to 4.1.7 in /.github/workflows

Bump actions/download-artifact from 1 to 4.1.7 in /.github/workflows #364

name: Continuous Integration
on: [push, pull_request]
jobs:
run:
name: Execute notebook
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
- run: pip3 install --requirement requirements.txt jupyter jupytext
# Work around https://github.com/altair-viz/altair/issues/2794
- run: pip3 uninstall --yes rfc3986-validator
- run: gawk --include inplace --file replace_build_info.awk Loudspeaker_Explorer.md
- run: jupytext --to notebook --execute Loudspeaker_Explorer.md
env:
LOUDSPEAKER_EXPLORER_PRERENDER: true
- uses: actions/upload-artifact@v1
with:
name: Loudspeaker_Explorer
path: Loudspeaker_Explorer.ipynb
colab:
name: Prepare for Colab
needs: run
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
name: Loudspeaker_Explorer
- run: sudo apt-get install jq
- run: |
jq --from-file /dev/stdin Loudspeaker_Explorer/Loudspeaker_Explorer.ipynb > Loudspeaker_Explorer.ipynb <<"EOF"
# Assign IDs to all sections that are missing one so that we can refer to them in the `collapsed_sections` Colab metadata (see below).
(.cells |= reduce range(0; length) as $i (.; .[$i].metadata.id |= (. // "cell-" + ($i | tostring)))) |
# Colab does not recognize the `heading_collapsed` cell metadata from the `collapsible_headings` extension.
# It uses its own way to specify collapsed sections in the notebook metadata. This code converts the former to the latter.
(.metadata.colab.collapsed_sections = [.cells[].metadata | select(.heading_collapsed).id]) |
# This hides all code cells in Colab by setting the cellView metadata attribute to "form".
# Note that for this to work, the code cell needs to contain at least one form element, so we prepend a dummy one.
# (This is hacky, but it is exactly what Colab does when using the "hide code" function. If it's good enough for Colab, it's good enough for us.)
(.cells[] | select(.cell_type == "code")) |= (.metadata.cellView = "form" | .source |= ["#@markdown\n"] + .) |
# Colab expects widget state to be directly under the key in metadata.widgets.
# But in nbconvert output, the widget stated is nested under an intermediate `state` key.
(.metadata.widgets[] |= (. + .state))
EOF
- uses: actions/upload-artifact@v1
with:
name: Loudspeaker_Explorer-colab
path: Loudspeaker_Explorer.ipynb
publish:
name: Publish notebook
needs: colab
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
name: Loudspeaker_Explorer-colab
- run: install --verbose --no-target-directory --mode=0600 /dev/null rendered_repo_deploy_key
- run: echo "$RENDERED_REPO_DEPLOY_KEY" > rendered_repo_deploy_key
env:
RENDERED_REPO_DEPLOY_KEY: ${{ secrets.RenderedRepoDeployKey }}
- run: mkdir -v LoudspeakerExplorer-rendered
- run: git -C LoudspeakerExplorer-rendered init
- run: git -C LoudspeakerExplorer-rendered remote add origin [email protected]:dechamps/LoudspeakerExplorer-rendered.git
- run: git -C LoudspeakerExplorer-rendered config core.sshCommand 'ssh -i ../rendered_repo_deploy_key -v'
- run: git -C LoudspeakerExplorer-rendered fetch origin "$GITHUB_REF" --verbose --depth=1
continue-on-error: true
- run: git -C LoudspeakerExplorer-rendered checkout FETCH_HEAD
continue-on-error: true
- run: mv --verbose Loudspeaker_Explorer-colab/* LoudspeakerExplorer-rendered/
# TODO: this will never delete files. Maybe we should just overwrite the full contents of the destination repo.
- run: git -C LoudspeakerExplorer-rendered add . --verbose
- run: git -C LoudspeakerExplorer-rendered config user.name 'LoudspeakerExplorer Continuous Integration <>'
- run: git -C LoudspeakerExplorer-rendered config user.email ''
- run: |
{
echo "Built from $GITHUB_SHA"
echo
echo "Open this commit in Colab: https://colab.research.google.com/github/dechamps/LoudspeakerExplorer-rendered/blob/ci-$GITHUB_SHA-$GITHUB_RUN_ID/Loudspeaker_Explorer.ipynb"
echo "Source commit: https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA"
echo "Workflow run: https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
echo
for var in GITHUB_WORKFLOW GITHUB_RUN_ID GITHUB_RUN_NUMBER GITHUB_ACTION GITHUB_ACTIONS GITHUB_ACTOR GITHUB_REPOSITORY GITHUB_EVENT_NAME GITHUB_SHA GITHUB_REF GITHUB_HEAD_REF GITHUB_BASE_REF
do
echo "${var}=${!var}"
done
} | git -C LoudspeakerExplorer-rendered commit --file=-
# TODO: this doesn't handle concurrent workflows well, and is prone to race conditions where an older commit could overwrite a more recent one.
# We include the workflow Run ID in the tag to avoid conflicts when the same source commit is published multiple times (e.g. from different branches).
- run: git -C LoudspeakerExplorer-rendered push origin "HEAD:$GITHUB_REF" "HEAD:refs/tags/ci-$GITHUB_SHA-$GITHUB_RUN_ID" --verbose
- run: |
echo "Publish commit: https://github.com/dechamps/LoudspeakerExplorer-rendered/commit/ci-$GITHUB_SHA-$GITHUB_RUN_ID"
- run: |
echo "Open in Colab: https://colab.research.google.com/github/dechamps/LoudspeakerExplorer-rendered/blob/ci-$GITHUB_SHA-$GITHUB_RUN_ID/Loudspeaker_Explorer.ipynb"
binder:
name: Build Binder
runs-on: ubuntu-latest
steps:
- run: curl --silent --show-error --location --user-agent 'LoudspeakerExplorer Continuous Integration https://github.com/dechamps/LoudspeakerExplorer' -- "https://mybinder.org/build/gh/$GITHUB_REPOSITORY/$GITHUB_SHA"
- run: |
echo "Open in Binder: https://mybinder.org/v2/gh/$GITHUB_REPOSITORY/$GITHUB_SHA?filepath=Loudspeaker_Explorer.ipynb"