Coder Social home page Coder Social logo

trsvchn / colab-badge-action Goto Github PK

View Code? Open in Web Editor NEW
26.0 2.0 5.0 111 KB

Organize your jupyter notebooks with "Open in Colab" badges

License: MIT License

Dockerfile 0.17% Python 99.83%
github-actions action google-colaboratory colab jupyter notebook jupyter-notebook

colab-badge-action's Introduction

Colab Badge GitHub Action

Unit Tests codecov

Adds "Open in Colab" badges to Jupyter Notebooks and Markdown files. Updates badges for renamed or moved notebooks.

Usage

Badge Tag

  • Use {{ badge }} tag to generate a badge for the notebook containing this tag (self-linking). Works only for Jupyter notebooks.

The following options work for both Jupyter and Markdown files (new in v4):

  • Use {{ badge nb_path }} tag to generate a badge for a local notebook nb_path, and insert it to the file containing that tag (tag will be replaced with generated badge code). e.g. {{ badge dir1/dir2/nb.ipynb }}.
  • Use {{ badge /nb_path }} tag to generate a badge for a remote (located in another repo) notebook /nb_path, and insert it to the file containing that tag. e.g. {{ badge /usr2/repo/blob/main/nb.ipynb }}. You can use full link (url) as well: {{ badge https://github.com/usr2/repo/blob/main/nb.ipynb }}.
  • Use {{ badge //drive/nb_id }} tag to generate a badge for google drive notebook, and insert it to the file containing that tag. e.g. {{ badge //drive/abcde }}

Note: repo name and branch name are omitted for local notebooks, for notebooks from another repo only hostname can be ommited. In both cases file extension .ipynb can be omitted.

Add tag

Action will create a badge for you:

With badge

Example Workflow

A workflow file for adding/updating badges for notebooks in a repo:

name: Example Workflow
on: [push]

jobs:
  badges:
    name: Example Badge Job
    runs-on: ubuntu-latest
    steps:
      - name: Checkout first
        id: checkout
        uses: actions/checkout@v2

      - name: Add/Update badges
        id: badges
        uses: trsvchn/colab-badge-action@v4
        with:
          check: "all"
          target_branch: main
          target_repository: user/user-repo
          update: true

      - name: Use your favorite commit&push action here
        uses: action/commit@push
        with: ...

Inputs

Input Description Default
check Check every notebook/markdown: "all" or just modified files from a current commit: "latest". "all"
target_branch Branch that the badge will target. "" (current branch)
target_repository Repo that the badge will target. "" (current repository)
update Update a badge if a piece of information relevant to it has changedL true. With false inserts badges with no further updates (ignores changes). Works only for notebooks. true
verbose Verbose mode. Print some information during execution. false

colab-badge-action's People

Contributors

skearnes avatar trsvchn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

colab-badge-action's Issues

Possible Bug: Branch name changing from branch to `master` and I'm wondering why.

Hello!

It seems that with the default settings, pasted below I am getting an error where the branch name keeps getting switched to master even though I am using the default settings. See image (see below).

Thank you for your help!
Steven

image

name: Badges workflow
on: [workflow_dispatch, push]
jobs:
  build:
    name: Badges Job
    runs-on: ubuntu-latest
    steps:
      - name: Checkout first
        id: checkout
        uses: actions/checkout@v2

      - name: Add/Update badges
        id: badges
        uses: trsvchn/colab-badge-action@v4
        with:
          check: 'all'
          update: true
          verbose: true

      - name: push
        uses: actions-x/commit@v6
        with:
          message: Update Colab badges with GitHub Actions

Commits are not triggering CI actions

When this action adds a commit to a PR for merging into master, this commit is not triggering CI actions that are normally triggered by push and pull_request events that touch master. Any ideas?

Error with set-env command

Error: Unable to process command '::set-env name=MODIFIED_NOTEBOOKS::' successfully.
Error: The `set-env` command is disabled. Please upgrade to using Environment Files or opt into unsecure command execution by setting the `ACTIONS_ALLOW_UNSECURE_COMMANDS` environment variable to `true`. For more information see: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/

Tutorial

Hi,

Finally i found a solution to what i'm looking for after many days.
But couldn't quite understand how this works.
Can you please make a small tutorial or steps how to install and use the 'colab-badge-action'.
Appreciate your help.
Thank you.

Action does not work with `pull_request` events

The pull_request workflow event uses a different value for GITHUB_REF that does not include the branch name (in contrast to the push event); instead, it includes information about the PR, e.g. refs/pull/72/merge. This causes git push to fail with errors like this:

! [remote rejected] HEAD -> refs/pull/72/merge (deny updating a hidden ref)

Bug: Badges do not update in markdown files.

Summary:

Colab badges in Jupyter Notebooks update across branches when merging or pushing, but Colab badges in Markdown files do not update. They will be created just fine, but not updated once created.

Steps to Reproduce

  1. Make a new repo, clone it
  2. Checkout a new branch git checkout -b test
  3. Create a Jupyter notebook file named test at the root of the repository
  4. Make a markdown cell with {{ badge }}.
  5. Create a markdown file: `echo '
  6. Write first line {{ badge test }}
  7. Commit: git commit -am "test"
  8. Push: git push -u origin test
  9. Watch the action complete, hopefully successfully. Confirm that the branch test
    • created a new badge in test.ipynb
    • created a new badge in test.md
    • Note that the paths in both badges respect the current test branch.
  10. Create a pull request with the test branch to the main branch.
  11. Watch the github action do the following:
    - update the badge in test.ipynb
    - Skip updating the badge in test.md <<-- This is the bug.

Note: You can inspect the action since the yaml below creates verbose output and see that

Goes in .github/workflows/colab_badge.yml

name: Badges workflow
on: [push]

jobs:
  build:
    name: Badges Job
    runs-on: ubuntu-latest
    steps:
      - name: Checkout first
        id: checkout
        uses: actions/checkout@v2

      - name: Add/Update badges
        id: badges
        uses: trsvchn/colab-badge-action@v4
        with:
          check: 'all'
          update: true
          verbose: true

      - name: push
        uses: actions-x/commit@v6
        with:
          message: Update Colab badges with GitHub Actions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.