Skip to content

Commit 867e4d3

Browse files
authored
Merge pull request #2417 from consideRatio/pr/second-attempt-on-fixing-set-output
ci: attempt to fix set-output again
2 parents a850eef + 8f96dcd commit 867e4d3

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

.github/workflows/watch-dependencies.yaml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +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
82-
# Needs to be a single line string
83-
# https://trstringer.com/github-actions-multiline-strings/#option-1---string-substitution
8482
run: |
8583
pip install PyGithub
86-
PR_LIST=$(./scripts/get-prs.py ${{matrix.repository}} ${{steps.local.outputs.tag}} ${{steps.latest.outputs.tag}} --github-action-escape)
87-
echo "prs=$PR_LIST" >> $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
8889
env:
8990
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9091

@@ -204,15 +205,16 @@ jobs:
204205
- name: git diff
205206
run: git --no-pager diff --color=always
206207

207-
- name: PR summary
208+
- name: Fetch PR summary
208209
id: prsummary
209210
if: matrix.github_repo && (steps.local.outputs.version != steps.latest.outputs.version)
210-
# Needs to be a single line string
211-
# https://trstringer.com/github-actions-multiline-strings/#option-1---string-substitution
212211
run: |
213212
pip install PyGithub
214-
PR_LIST=$(./scripts/get-prs.py ${{matrix.github_repo}} ${{steps.local.outputs.version}} ${{steps.latest.outputs.version}} --github-action-escape)
215-
echo "prs=$PR_LIST" >> $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
216218
env:
217219
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
218220

scripts/get-prs.py

Lines changed: 15 additions & 6 deletions
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
@@ -30,9 +31,8 @@ def extract_gitref(s):
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")
3233
parser.add_argument(
33-
"--github-action-escape",
34-
action="store_true",
35-
help="Escape output for GitHub Action",
34+
"--write-github-actions-output",
35+
help="Name of a GitHub Action's output variable to write to",
3636
)
3737
parser.add_argument(
3838
"--max-commits",
@@ -65,7 +65,16 @@ def extract_gitref(s):
6565
]
6666

6767
md = ["# PRs"] + pr_summaries + ["", f"{r.html_url}/compare/{start}...{end}"]
68-
if args.github_action_escape:
69-
print("%0A".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)
7079
else:
71-
print("\n".join(md))
80+
print(md)

0 commit comments

Comments
 (0)