diff --git a/.github/workflows/watch-dependencies.yaml b/.github/workflows/watch-dependencies.yaml index 0992232cd..a15531184 100644 --- a/.github/workflows/watch-dependencies.yaml +++ b/.github/workflows/watch-dependencies.yaml @@ -76,6 +76,18 @@ jobs: if: steps.local.outputs.tag != steps.latest.outputs.tag run: git --no-pager diff --color=always + - name: PR summary + id: prsummary + if: steps.local.outputs.tag != steps.latest.outputs.tag + # Needs to be a single line string + # https://trstringer.com/github-actions-multiline-strings/#option-1---string-substitution + run: | + pip install PyGithub + PR_LIST=$(./scripts/get-prs.py ${{matrix.repository}} ${{steps.local.outputs.tag}} ${{steps.latest.outputs.tag}} --github-action-escape) + echo "::set-output name=prs::$PR_LIST" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # ref: https://github.com/peter-evans/create-pull-request - name: Create a PR uses: peter-evans/create-pull-request@v4.1.1 @@ -93,6 +105,8 @@ jobs: body: | Updates mybinder to depend on the `${{ matrix.registry }}/${{ matrix.repository }}` image version `${{ steps.latest.outputs.tag }}` from version `${{ steps.local.outputs.tag }}`. + ${{ steps.prsummary.outputs.prs }} + ## Related - Source code: ${{ matrix.source_url }} @@ -119,30 +133,35 @@ jobs: chart_dep_app_changelog_url: "https://github.com/jupyterhub/binderhub/blob/master/CHANGES.md" chart_dep_source_url: "https://github.com/jupyterhub/binderhub/tree/master/helm-chart" chart_dep_devel_flag: "--devel" + github_repo: jupyterhub/binderhub - chart_dep_name: ingress-nginx chart_dep_chart_changelog_url: "https://github.com/kubernetes/ingress-nginx/tree/main/charts/ingress-nginx#upgrading-chart" chart_dep_app_changelog_url: "https://github.com/kubernetes/ingress-nginx/blob/master/Changelog.md" chart_dep_source_url: "https://github.com/kubernetes/ingress-nginx/tree/master/charts/ingress-nginx" chart_dep_devel_flag: "" + github_repo: "" - chart_dep_name: prometheus chart_dep_chart_changelog_url: "https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus#upgrading-chart" chart_dep_app_changelog_url: "https://github.com/prometheus/prometheus/blob/master/CHANGELOG.md" chart_dep_source_url: https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus chart_dep_devel_flag: "" + github_repo: "" - chart_dep_name: grafana chart_dep_chart_changelog_url: "https://github.com/grafana/helm-charts/tree/main/charts/grafana#upgrading-an-existing-release-to-a-new-major-version" chart_dep_app_changelog_url: "https://github.com/grafana/grafana/blob/master/CHANGELOG.md" chart_dep_source_url: "https://github.com/grafana/helm-charts/tree/main/charts/grafana" chart_dep_devel_flag: "" + github_repo: "" - chart_dep_name: cryptnono chart_dep_chart_changelog_url: "" chart_dep_app_changelog_url: "" chart_dep_source_url: "https://github.com/yuvipanda/cryptnono/" chart_dep_devel_flag: "--devel" + github_repo: "" steps: - uses: actions/checkout@v3 @@ -185,6 +204,18 @@ jobs: - name: git diff run: git --no-pager diff --color=always + - name: PR summary + id: prsummary + if: matrix.github_repo && (steps.local.outputs.version != steps.latest.outputs.version) + # Needs to be a single line string + # https://trstringer.com/github-actions-multiline-strings/#option-1---string-substitution + run: | + pip install PyGithub + PR_LIST=$(./scripts/get-prs.py ${{matrix.github_repo}} ${{steps.local.outputs.version}} ${{steps.latest.outputs.version}} --github-action-escape) + echo "::set-output name=prs::$PR_LIST" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # ref: https://github.com/peter-evans/create-pull-request - name: Create a PR uses: peter-evans/create-pull-request@v4.1.1 @@ -207,6 +238,8 @@ jobs: Chart.yaml's version | `${{ steps.local.outputs.version }}` | `${{ steps.latest.outputs.version }}` Chart.yaml's appVersion | `${{ steps.local.outputs.appVersion }}` | `${{ steps.latest.outputs.appVersion }}` + ${{ steps.prsummary.outputs.prs }} + ## Related - Chart source code: ${{ matrix.chart_dep_source_url }} diff --git a/scripts/get-prs.py b/scripts/get-prs.py new file mode 100755 index 000000000..3079894d8 --- /dev/null +++ b/scripts/get-prs.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python +import os +import re +from argparse import ArgumentParser + +import github + + +def extract_gitref(s): + """ + Extract git ref from a container registry tag or Helm chart version + + Examples: + - 2022.02.0 -> 2022.02.0 + - 2022.02.0-90.g0345a86 -> 0345a86 + - 0.2.0 -> 0.2.0 + - 0.2.0-n1011.hb49edf6 -> b49edf6 + - 0.2.0-0.dev.git.2752.h3450e52 -> 3450e52 + """ + m = re.match(r"[\d\.]+-[\w\.]+[gh]([0-9a-f]+)", s) + if m: + return m.group(1) + return s + + +token = os.getenv("GITHUB_TOKEN") + +parser = ArgumentParser(description="Summarise PRs from a repo") +parser.add_argument("repo", help="The repository in format user/repo") +parser.add_argument("start", help="commit or image/chart version from which to start") +parser.add_argument("end", help="commit or image/chart version to which to end") +parser.add_argument( + "--github-action-escape", + action="store_true", + help="Escape output for GitHub Action", +) +parser.add_argument( + "--max-commits", + type=int, + default=100, + help="Maximum number of commits to check", +) + +args = parser.parse_args() + +gh = github.Github(token) +r = gh.get_repo(args.repo) + +start = extract_gitref(args.start) +end = extract_gitref(args.end) + +prs = set() +git_compare = r.compare(start, end) +commits = list(git_compare.commits) +if len(commits) > args.max_commits: + pr_summaries = [ + f"{len(commits)} commits between {start} and {end}, not searching for PRs" + ] +else: + for c in commits: + prs.update(c.get_pulls()) + pr_summaries = [ + f"- [#{pr.number}]({pr.html_url}) {pr.title}" + for pr in sorted(prs, key=lambda pr: pr.number) + ] + +md = ["# PRs"] + pr_summaries + ["", f"{r.html_url}/compare/{start}...{end}"] +if args.github_action_escape: + print("%0A".join(md)) +else: + print("\n".join(md))