Check environment for updates #21
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: Check environment for updates | |
on: | |
schedule: | |
- cron: "0 6 15 * *" | |
workflow_dispatch: | |
defaults: | |
run: | |
shell: bash -el {0} | |
jobs: | |
check: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Cache conda | |
uses: actions/cache@v3 | |
env: | |
# Increase this value to reset cache if .binder/environment.yml has not changed | |
CACHE_NUMBER: 0 | |
with: | |
path: ~/conda_pkgs_dir | |
key: | |
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('.binder/environment.yml') }} | |
- uses: conda-incubator/setup-miniconda@v2 | |
with: | |
mamba-version: ">=1.4.0" | |
# Defaults is added automatically | |
channels: conda-forge | |
channel-priority: "strict" | |
activate-environment: jupyterlab-demo | |
environment-file: .binder/environment.yml | |
# The following option is blocking the environment resolution (newer versions are not found) | |
# use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly! | |
- run: | | |
# FIXME First invoke r task as it changes the environment | |
# invoke r --env-name=jupyterlab-demo | |
# Check for updates in the final environment with r installed | |
invoke update | |
- name: Create a PR optionally | |
shell: bash | |
env: | |
GITHUB_USER: ${{ secrets.GITHUB_USER }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
set -eux | |
if [[ ! -z "$(git status --porcelain .binder/environment.yml)" ]]; then | |
export SHA=$(git rev-parse --short HEAD) | |
export BRANCH_NAME=new-updates-${SHA} | |
git checkout -b "${BRANCH_NAME}" | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
git add .binder/environment.yml | |
git commit -m "Update environment" | |
git push --set-upstream origin "${BRANCH_NAME}" | |
gh pr create -B "master" -t "New update available at ${SHA}" -b "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/jupyterlab/jupyterlab-demo/${BRANCH_NAME}?urlpath=lab) :point_left: Launch a Binder on branch _${BRANCH_NAME}_" | |
fi |