|
| 1 | +# automatically check for updates to nbviewer |
| 2 | +# adapted from mybinder.org-deploy, under BSD-3-Clause lience |
| 3 | +name: Watch dependencies |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + paths: |
| 8 | + - ".github/workflows/watch-dependencies.yaml" |
| 9 | + schedule: |
| 10 | + # Run daily at 5am (somewhere), ref: https://crontab.guru/#0_5_*_*_* |
| 11 | + - cron: "0 5 * * *" |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +jobs: |
| 15 | + update-nbviewer: |
| 16 | + # Don't schedule runs on forks, but allow the job to execute on push and |
| 17 | + # workflow_dispatch for CI development purposes. |
| 18 | + if: github.repository == 'jupyter/nbviewer.org-deploy' || github.event_name != 'schedule' |
| 19 | + |
| 20 | + runs-on: ubuntu-24.04 |
| 21 | + environment: watch-dependencies |
| 22 | + |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + |
| 26 | + - uses: actions/setup-python@v5 |
| 27 | + with: |
| 28 | + python-version: "3.10" |
| 29 | + |
| 30 | + - name: Get current versions of jupyter/nbviewer |
| 31 | + id: current |
| 32 | + # get the version of the image and chart repo currently being deployed |
| 33 | + run: | |
| 34 | + local_image=$(cat config/nbviewer.yaml | yq e '.image') |
| 35 | + echo "tag=$local_image" >> $GITHUB_OUTPUT |
| 36 | + local_chart=$(cat .github/workflows/cd.yml | yq e '.env.NBVIEWER_VERSION') |
| 37 | + echo "chart=$local_chart" >> $GITHUB_OUTPUT |
| 38 | +
|
| 39 | + - name: Get latest versions jupyter/nbviewer |
| 40 | + id: latest |
| 41 | + # docker tags api sorts by date |
| 42 | + # there is no version information in nbviewer image tags |
| 43 | + run: | |
| 44 | + latest_tag=$( |
| 45 | + curl https://hub.docker.com/v2/repositories/jupyter/nbviewer/tags | jq -r '.results[0].name' |
| 46 | + ) |
| 47 | + echo "tag=jupyter/nbviewer:$latest_tag" >> $GITHUB_OUTPUT |
| 48 | + head=$( |
| 49 | + git ls-remote https://github.com/jupyter/nbviewer HEAD | cut -f1 |
| 50 | + ) |
| 51 | + echo "chart=$head" >> "$GITHUB_OUTPUT" |
| 52 | + echo "short=${head::7}" >> "$GITHUB_OUTPUT" |
| 53 | + |
| 54 | + - name: Update nbviewer image |
| 55 | + if: steps.local.outputs.tag != steps.latest.outputs.tag |
| 56 | + run: sed --in-place 's@${{ steps.local.outputs.tag }}@${{ steps.latest.outputs.tag }}@g' config/nbviewer.yaml |
| 57 | + |
| 58 | + - name: Update nbviewer chart |
| 59 | + if: steps.local.outputs.chart != steps.latest.outputs.chart |
| 60 | + run: sed --in-place 's@${{ steps.local.outputs.chart }}@${{ steps.latest.outputs.chart }}@g' .github/workflows/cd.yml |
| 61 | + |
| 62 | + - name: git diff |
| 63 | + id: git-diff |
| 64 | + run: | |
| 65 | + if git --no-pager diff --color=always --exit-code; then |
| 66 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 67 | + else |
| 68 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 69 | + fi |
| 70 | +
|
| 71 | + - name: Fetch PR summary |
| 72 | + id: prsummary |
| 73 | + if: steps.git-diff.changed |
| 74 | + run: | |
| 75 | + pip install PyGithub |
| 76 | + ./scripts/get-prs.py \ |
| 77 | + jupyter/nbviewer \ |
| 78 | + ${{ steps.local.outputs.chart }} \ |
| 79 | + ${{ steps.latest.outputs.chart }} \ |
| 80 | + --write-github-actions-output=prs |
| 81 | + env: |
| 82 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 83 | + |
| 84 | + # ref: https://github.com/peter-evans/create-pull-request |
| 85 | + - name: Create a PR |
| 86 | + uses: peter-evans/create-pull-request@v7 |
| 87 | + # Don't try open PRs in forks or when the job is triggered by a push to |
| 88 | + # a branch other than the default branch. |
| 89 | + if: github.repository == 'jupyter/nbviewer.org-deploy' && (github.event_name != 'push' || github.ref == 'refs/heads/main') |
| 90 | + with: |
| 91 | + token: "${{ secrets.BOT_PAT }}" |
| 92 | + author: Jupter Bot Account <[email protected]> |
| 93 | + committer: JupterHub Bot Account <[email protected]> |
| 94 | + branch: update-nbviewer |
| 95 | + labels: dependencies |
| 96 | + commit-message: Update nbviewer version to ${{ steps.latest.outputs.short }} |
| 97 | + title: Update nbviewer version to ${{ steps.latest.outputs.short }} |
| 98 | + body: | |
| 99 | + - Updates nbviewer chart to jupyter/nbviewer@${{ steps.latest.outputs.chart }} |
| 100 | + - Update nbviewer image to `${{ steps.latest.outputs.tag }}` |
| 101 | +
|
| 102 | + ${{ steps.prsummary.outputs.prs }} |
| 103 | +
|
| 104 | + ## Related |
| 105 | +
|
| 106 | + - Source code: https://github.com/jupyter/nbviewer |
0 commit comments