Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add binder preview on PR #46

Merged
merged 24 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/binder-on-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# References:
steff456 marked this conversation as resolved.
Show resolved Hide resolved
# This workflow adds a Binder preview URL to new PRs (via a comment on the PR).
# This comment will only be created once, and then it will be updated with
# every new commit
# - https://github.com/jupyterlab/jupyterlab-git/blob/master/.github/workflows/binder-on-pr.yaml
# - https://mybinder.readthedocs.io/en/latest/howto/gh-actions-badges.html
name: Add binder link to PR
on:
push:
branches:
- main
Comment on lines +9 to +11
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand this part. Does this say to run the workflow whenever a commit is pushed to the main branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! With that we will have a working demo that gets deployed in main 🤓

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case., we might want to add a badge in the README file to point to the demo, otherwise, people will not even know this exists unless they look at the PRs

pull_request:
branches:
- main

permissions:
pull-requests: write

jobs:
binder:
runs-on: ubuntu-latest
steps:
- name: comment on PR with Binder link
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
var PR_HEAD_USERREPO = process.env.PR_HEAD_USERREPO;
var PR_HEAD_REF = process.env.PR_HEAD_REF;
const comments = await github.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});

var autogenerated_id = '';
for( var i = 0; i < comments.data.length; i++ ){
var act_comment = comments.data[ i ];
if( act_comment.body.includes( "https://mybinder.org/" ) ){
autogenerated_id = act_comment.id;
}
}

var date = new Date( Date.now() );

if( autogenerated_id === '' ){
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/${PR_HEAD_USERREPO}/${PR_HEAD_REF}?urlpath=lab) :point_left: Launch a binder notebook on branch [${PR_HEAD_USERREPO}/${PR_HEAD_REF}]${PR_HEAD_USERREPO}/${PR_HEAD_REF})`
})
}
else {
github.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: autogenerated_id,
body: `[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/${PR_HEAD_USERREPO}/${PR_HEAD_REF}?urlpath=lab) :point_left: Launch a binder notebook on branch [${PR_HEAD_USERREPO}/${PR_HEAD_REF}](${PR_HEAD_USERREPO}/${PR_HEAD_REF}) \n<sub>Comment updated on ${date.toISOString()}</sub>`,
});
}

env:
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
PR_HEAD_USERREPO: ${{ github.event.pull_request.head.repo.full_name }}
23 changes: 23 additions & 0 deletions binder/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (c) Jupyter Accessibility Team.
# Distributed under the terms of the Modified BSD License.
# a mybinder.org-ready environment for demoing jupyterlab_accessible_themes
# this environment may also be used locally on Linux/MacOS/Windows, e.g.
#
# conda env update --file binder/environment.yml
# conda activate jupyterlab-accessible-themes-demo
#
name: jupyterlab-accessible-themes-demo

channels:
- conda-forge
steff456 marked this conversation as resolved.
Show resolved Hide resolved
- nodefaults

dependencies:
# runtime dependencies
- python >=3.8
- jupyterlab >=3,<4.0.0a0
# labextension build dependencies
- nodejs >=16
- pip
- wheel
# additional packages for demos
58 changes: 58 additions & 0 deletions binder/postBuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env python3
# Copyright (c) Jupyter Accessibility Team.
# Distributed under the terms of the Modified BSD License.

""" Perform a development install of jupyterlab_accessible_themes

On Binder, this will run _after_ the environment has been fully created from
the environment.yml in this directory.

This script should also run locally on Linux/MacOS/Windows:

python3 binder/postBuild
"""
import subprocess
import sys
from pathlib import Path

ROOT = Path.cwd()


def _(*args, **kwargs):
"""Run a command, echoing the args

fails hard if something goes wrong
"""
print("\n\t", " ".join(args), "\n")
return_code = subprocess.call(args, **kwargs)
if return_code != 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it not be best to raise a proper exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was part of the template I used. I think they do it to return the complete stacktrace into the console in case there's an error and not only the error.

print(f"\nERROR, {return_code}: {' '.join(args)}")
sys.exit(return_code)


# verify the environment is self-consistent before even starting
_(sys.executable, "-m", "pip", "check")

# force a clean installation to avoid caching between sessions
# NOTE: This step is necessary, if not it will fail to install again the extension.
_("rm", "-rf", "jupyterlab_accessible_themes/labextensions")
_("rm", "-rf", "jupyterlab_accessible_themes.egg-info")

# install the labextension
_("jlpm", "install")
_("jlpm", "build")
_(sys.executable, "-m", "pip", "install", "-e", ".")
_(sys.executable, "-m", "jupyter", "labextension", "develop", "--overwrite", ".")

# verify the environment the extension didn't break anything
_(sys.executable, "-m", "pip", "check")

# list the extensions
_("jupyter", "server", "extension", "list")

# initially list installed extensions to determine if there are any surprises
_("jupyter", "labextension", "list")


print("JupyterLab with jupyterlab_accessible_themes is ready to run with:\n")
print("\tjupyter lab\n")
14 changes: 14 additions & 0 deletions packages/pitayasmoothie/style/variables.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.