Skip to content

Commit bb420d9

Browse files
committed
fix ci
1 parent 99b4b76 commit bb420d9

2 files changed

Lines changed: 78 additions & 23 deletions

File tree

.github/workflows/check-rendered-specs.yml

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,51 @@ jobs:
6868
- name: Check for drift
6969
id: check
7070
continue-on-error: true # Non-blocking while the feature stabilizes
71+
env:
72+
SPECS_DIR: ${{ steps.specs-dir.outputs.path }}
73+
run: |
74+
python .github/workflows/scripts/check_rendered_specs.py \
75+
--specs-dir "$SPECS_DIR" \
76+
--report render-check-report.json \
77+
--patch rendered-specs.patch
78+
79+
- name: Upload fix patch
80+
id: upload-patch
81+
if: hashFiles('rendered-specs.patch') != ''
82+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
83+
with:
84+
path: rendered-specs.patch
85+
archive: false
86+
87+
# Also upload as a zipped artifact so `gh run download` works.
88+
# The non-zipped upload above is for browser preview/download, but
89+
# `gh run download` doesn't support non-zipped artifacts yet.
90+
# See: https://github.com/cli/cli/issues/13012
91+
- name: Upload fix patch (for gh cli)
92+
if: hashFiles('rendered-specs.patch') != ''
93+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
94+
with:
95+
name: rendered-specs-patch
96+
path: rendered-specs.patch
97+
98+
- name: Post PR comment
99+
if: always()
100+
continue-on-error: true
71101
env:
72102
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73103
PR_REPO: ${{ github.repository }}
74104
PR_NUMBER: ${{ github.event.pull_request.number }}
75105
SPECS_DIR: ${{ steps.specs-dir.outputs.path }}
76-
ARTIFACTS_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
106+
PATCH_URL: ${{ steps.upload-patch.outputs.artifact-url }}
107+
RUN_ID: ${{ github.run_id }}
77108
run: |
78109
python .github/workflows/scripts/check_rendered_specs.py \
79110
--specs-dir "$SPECS_DIR" \
80111
--repo "$PR_REPO" \
81112
--pr "$PR_NUMBER" \
82113
--report render-check-report.json \
83-
--patch rendered-specs.patch \
84-
--artifacts-url "$ARTIFACTS_URL"
114+
--artifacts-url "$PATCH_URL" \
115+
--run-id "$RUN_ID"
85116
86117
- name: Upload render output
87118
if: always()
@@ -91,10 +122,3 @@ jobs:
91122
path: |
92123
render-output.json
93124
render-check-report.json
94-
95-
- name: Upload fix patch
96-
if: hashFiles('rendered-specs.patch') != ''
97-
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
98-
with:
99-
path: rendered-specs.patch
100-
archive: false

.github/workflows/scripts/check_rendered_specs.py

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,12 @@ def _render_command(components: list[str], use_all: bool = False) -> str:
222222
return f"azldev component render {' '.join(components)}"
223223

224224

225-
def format_comment(report: dict, artifacts_url: str | None = None) -> str:
225+
def format_comment(
226+
report: dict,
227+
artifacts_url: str | None = None,
228+
run_id: str | None = None,
229+
repo: str | None = None,
230+
) -> str:
226231
content_diffs = report.get("content_diffs", [])
227232
extra_files = report.get("extra_files", [])
228233
missing_files = report.get("missing_files", [])
@@ -265,14 +270,17 @@ def format_comment(report: dict, artifacts_url: str | None = None) -> str:
265270
]
266271

267272
if artifacts_url:
268-
lines.append(
269-
"Or download and apply the fix patch from the "
270-
f"[workflow artifacts]({artifacts_url}#artifacts):"
271-
)
273+
lines.append(f"Or [download the fix patch]({artifacts_url}) and apply it:")
272274
lines.append("")
273-
lines.append(
274-
"```bash\n# Download 'rendered-specs.patch' from the link above, then:\ngit apply rendered-specs.patch\n```"
275-
)
275+
if run_id and repo:
276+
lines.append(
277+
"```bash\n"
278+
f"gh run download {run_id} -R {repo} -n rendered-specs-patch\n"
279+
"git apply rendered-specs.patch\n"
280+
"```"
281+
)
282+
else:
283+
lines.append("```bash\ngit apply rendered-specs.patch\n```")
276284
lines.append("")
277285

278286
lines.extend(
@@ -393,7 +401,12 @@ def generate_patch(
393401
continue
394402
lines = text.splitlines(keepends=True)
395403
n = len(lines)
396-
diff_body = "".join(f"+{line}" if line.endswith("\n") else f"+{line}\n\\ No newline at end of file\n" for line in lines)
404+
diff_body = "".join(
405+
f"+{line}"
406+
if line.endswith("\n")
407+
else f"+{line}\n\\ No newline at end of file\n"
408+
for line in lines
409+
)
397410
parts.append(
398411
f"diff --git a/{path_str} b/{path_str}\n"
399412
f"new file mode 100644\n"
@@ -408,7 +421,8 @@ def generate_patch(
408421
try:
409422
committed_bytes = subprocess.run(
410423
["git", "show", f"HEAD:{path_str}"],
411-
capture_output=True, check=True,
424+
capture_output=True,
425+
check=True,
412426
).stdout
413427
except subprocess.CalledProcessError:
414428
continue
@@ -423,7 +437,12 @@ def generate_patch(
423437
continue
424438
lines = text.splitlines(keepends=True)
425439
n = len(lines)
426-
diff_body = "".join(f"-{line}" if line.endswith("\n") else f"-{line}\n\\ No newline at end of file\n" for line in lines)
440+
diff_body = "".join(
441+
f"-{line}"
442+
if line.endswith("\n")
443+
else f"-{line}\n\\ No newline at end of file\n"
444+
for line in lines
445+
)
427446
parts.append(
428447
f"diff --git a/{path_str} b/{path_str}\n"
429448
f"deleted file mode 100644\n"
@@ -535,6 +554,11 @@ def main() -> int:
535554
default=None,
536555
help="URL to the workflow run artifacts (linked in PR comment)",
537556
)
557+
parser.add_argument(
558+
"--run-id",
559+
default=None,
560+
help="GitHub Actions run ID (for gh run download command in PR comment)",
561+
)
538562
args = parser.parse_args()
539563

540564
if bool(args.repo) != bool(args.pr):
@@ -578,15 +602,22 @@ def main() -> int:
578602
if total == 0:
579603
delete_comment_if_exists(args.repo, args.pr)
580604
else:
581-
body = format_comment(report, artifacts_url=args.artifacts_url)
605+
body = format_comment(
606+
report,
607+
artifacts_url=args.artifacts_url,
608+
run_id=args.run_id,
609+
repo=args.repo,
610+
)
582611
post_or_update_comment(args.repo, args.pr, body)
583612
except (subprocess.CalledProcessError, OSError) as exc:
584613
print(f"Warning: failed to post/update PR comment: {exc}", file=sys.stderr)
585614

586615
# 5. Write to GitHub step summary if available
587616
summary_file = os.environ.get("GITHUB_STEP_SUMMARY")
588617
if summary_file and total > 0:
589-
summary_body = format_comment(report, artifacts_url=args.artifacts_url)
618+
summary_body = format_comment(
619+
report, artifacts_url=args.artifacts_url, run_id=args.run_id, repo=args.repo
620+
)
590621
if len(summary_body) <= MAX_STEP_SUMMARY:
591622
with open(summary_file, "a", encoding="utf-8") as sf:
592623
sf.write(summary_body)

0 commit comments

Comments
 (0)