Skip to content

Commit 8f96dcd

Browse files
committed
ci: refactor set-output logic into scripts/get-prs.py
1 parent cbf2fdd commit 8f96dcd

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

.github/workflows/watch-dependencies.yaml

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,16 @@ jobs:
7676
if: steps.local.outputs.tag != steps.latest.outputs.tag
7777
run: git --no-pager diff --color=always
7878

79-
- name: PR summary
79+
- name: Fetch PR summary
8080
id: prsummary
8181
if: steps.local.outputs.tag != steps.latest.outputs.tag
8282
run: |
8383
pip install PyGithub
84-
85-
# We want to set multiline output, so we rely on this technique:
86-
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
87-
#
88-
eof_randomized=EOF_$RANDOM
89-
echo "prs<<$eof_randomized" >> $GITHUB_OUTPUT
90-
./scripts/get-prs.py ${{matrix.github_repo}} ${{steps.local.outputs.version}} ${{steps.latest.outputs.version}} >> $GITHUB_OUTPUT
91-
echo "$eof_randomized" >> $GITHUB_OUTPUT
84+
./scripts/get-prs.py \
85+
${{matrix.github_repo}} \
86+
${{steps.local.outputs.version}} \
87+
${{steps.latest.outputs.version}} \
88+
--write-github-actions-output=prs
9289
env:
9390
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9491

@@ -208,19 +205,16 @@ jobs:
208205
- name: git diff
209206
run: git --no-pager diff --color=always
210207

211-
- name: PR summary
208+
- name: Fetch PR summary
212209
id: prsummary
213210
if: matrix.github_repo && (steps.local.outputs.version != steps.latest.outputs.version)
214211
run: |
215212
pip install PyGithub
216-
217-
# We want to set multiline output, so we rely on this technique:
218-
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
219-
#
220-
eof_randomized=EOF_$RANDOM
221-
echo "prs<<$eof_randomized" >> $GITHUB_OUTPUT
222-
./scripts/get-prs.py ${{matrix.github_repo}} ${{steps.local.outputs.version}} ${{steps.latest.outputs.version}} >> $GITHUB_OUTPUT
223-
echo "$eof_randomized" >> $GITHUB_OUTPUT
213+
./scripts/get-prs.py \
214+
${{matrix.github_repo}} \
215+
${{steps.local.outputs.version}} \
216+
${{steps.latest.outputs.version}} \
217+
--write-github-actions-output=prs
224218
env:
225219
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
226220

scripts/get-prs.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
import os
33
import re
4+
import uuid
45
from argparse import ArgumentParser
56

67
import github
@@ -29,6 +30,10 @@ def extract_gitref(s):
2930
parser.add_argument("repo", help="The repository in format user/repo")
3031
parser.add_argument("start", help="commit or image/chart version from which to start")
3132
parser.add_argument("end", help="commit or image/chart version to which to end")
33+
parser.add_argument(
34+
"--write-github-actions-output",
35+
help="Name of a GitHub Action's output variable to write to",
36+
)
3237
parser.add_argument(
3338
"--max-commits",
3439
type=int,
@@ -60,4 +65,16 @@ def extract_gitref(s):
6065
]
6166

6267
md = ["# PRs"] + pr_summaries + ["", f"{r.html_url}/compare/{start}...{end}"]
63-
print("\n".join(md))
68+
md = "\n".join(md)
69+
70+
if args.write_github_actions_output:
71+
# GitHub Actions docs on setting a output variable with a multiline string:
72+
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
73+
#
74+
eof_marker = str(uuid.uuid4()).replace("-", "_")
75+
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
76+
print(f"{args.write_github_actions_output}<<{eof_marker}", file=f)
77+
print(md, file=f)
78+
print(eof_marker, file=f)
79+
else:
80+
print(md)

0 commit comments

Comments
 (0)