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
on: | |
pull_request_target: | |
types: [opened] | |
paths: | |
- '**.ipynb' | |
jobs: | |
notebook-preview: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/github-script@v6 | |
name: Add notebook Colab link | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const pr = context.payload.pull_request; | |
const filesChanged = await github.rest.pulls.listFiles({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: pr.number, | |
}); | |
let comment = `<img width="200" alt="Colab" src="https://colab.research.google.com/assets/colab-badge.svg"> \n ### Test notebook(s) in this PR in Google Colab:\n`; | |
for (const file of filesChanged.data) { | |
if (file.filename.endsWith(".ipynb")) { | |
const notebookPath = file.filename; | |
const colabLink = `https://colab.research.google.com/github/${context.repo.owner}/${context.repo.repo}/blob/${pr.head.ref}/${notebookPath}`; | |
comment += `\n - [${notebookPath}](${colabLink})\n`; | |
} | |
} | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: comment, | |
}); |