diff --git a/.github/workflows/binder-badge.yml b/.github/workflows/binder-badge.yml index db5382e42..214efab45 100644 --- a/.github/workflows/binder-badge.yml +++ b/.github/workflows/binder-badge.yml @@ -4,30 +4,41 @@ name: AddBinderBadge on: push: pull_request_target: - # since we're using nbgitpuller, only create the badge when PR opened types: [opened] - paths: - - 'examples/*' + jobs: add-badge: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - - name: Checkout PR - uses: actions/checkout@v2 + # - name: Checkout PR + # uses: actions/checkout@v2 + # - name: print vars + # run: | + # echo ${{ github.head_ref}} + # echo ${{ github.ref}} + # echo ${{ github.base_ref}} + # echo ${GITHUB_REF#refs/heads/} + # - name: get branch name + # run: | + # echo ${GITHUB_REF#refs/heads/} + # export GIT_BRANCH=$(echo ${GITHUB_REF#refs/heads/}) + # echo $GIT_BRANCH - name: Comment on PR with Binder link uses: actions/github-script@v5 - env: - BRANCH_NAME: ${{ github.event.pull_request.head.ref }} - CONTENT_REPO: ${{github.event.pull_request.head.repo.full_name}} with: github-token: ${{secrets.GITHUB_TOKEN}} script: | - var BRANCH_NAME = process.env.BRANCH_NAME; + console.log(context) + var BRANCH_NAME = process.env.GITHUB_REF.replace("refs/heads", ""); var CONTENT_REPO = process.env.CONTENT_REPO; github.rest.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/icesat2py/icepyx/main?urlpath=git-pull%3Frepo%3Dhttps%253A%252F%252Fgithub.com%252F${CONTENT_REPO}%26urlpath%3Dlab%252Ftree%252Ficepyx%252Fexamples%252F%26branch%3D${BRANCH_NAME}) :point_left: Launch a binder notebook on this branch` - }) \ No newline at end of file + body: `[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/${CONTENT_REPO}/${BRANCH_NAME}?labpath=examples) :point_left: Launch a binder notebook on this branch` + }) + # NOTE: Setting the vars as env vars is required to make them available within the Comment on PR step + env: + GITHUB_REF: ${{ github.ref }} + CONTENT_REPO: ${{ github.repository }} \ No newline at end of file