Skip to content

Commit 0b49669

Browse files
committed
ci: post the scheduled conda and Python-version reports to Discussions (#2030)
- cron-conda.yml: `conda-update` writes and uploads a run report (pin notices and warnings, changed files, the build pushed) and a `warning` status for a pin warning; `Refresh the platform pins` keeps its output in a log under `pipefail`. A `discussion` job, alone holding `discussions: write`, adds the tag and upload results and posts it, `push` on `workflow_run` and `scheduled` otherwise, with a report of its own for a failed or cancelled gate. - cron-python-versions.yml: `detect` writes and uploads a report from the plan (tiers moved, notes, audit, why no pull request opens); a `discussion` job posts it as `scheduled`, needing `detect` alone so the `github-release` approval never holds it. - tests/project/test_cron_reports_2030.py: the workflow pins, and each report and post step run with stand-ins; the existing job, output and refresh-step pins follow. - workflows.rst: CI Reports covers both workflows.
1 parent 5636a26 commit 0b49669

7 files changed

Lines changed: 826 additions & 11 deletions

File tree

‎.github/workflows/cron-conda.yml‎

Lines changed: 148 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ concurrency:
2222
group: conda-update-${{ github.event.workflow_run.head_sha || github.ref }}
2323
cancel-in-progress: false
2424

25+
# #2030: one Discussions category holds every report with no pull request to
26+
# comment on, one thread per job; cron-vendor.yml's `discussion` job says more.
27+
env:
28+
REPORT_CATEGORY: CI reports
29+
2530
jobs:
2631
# #1967: the test gate on the schedule, `verdict` on a `workflow_run`;
2732
# shared with Vendor Update and GitHub Pages.
@@ -95,9 +100,13 @@ jobs:
95100
# (#1643). An unreadable package keeps its pin, as does a pin no release
96101
# can move to (#2025) and a pin whose own release has lost a wheel while
97102
# an older one still qualifies (#2028), and each warns, as does a pin past
98-
# its review-by date; none fails the step.
103+
# its review-by date; none fails the step. The log keeps those lines for
104+
# the run report (#2030); `pipefail`, so `tee` cannot hide the script's
105+
# own exit status.
99106
- name: Refresh the platform pins
100-
run: python util/conda_vendor.py --refresh-pins
107+
run: |
108+
set -o pipefail
109+
python util/conda_vendor.py --refresh-pins | tee "$RUNNER_TEMP/platform-pins.log"
101110
102111
- name: Setup Conda Distribution
103112
run: |
@@ -228,6 +237,67 @@ jobs:
228237
echo "PCAPKIT_BUILD=$(cat conda/build)"
229238
} >> "$GITHUB_OUTPUT"
230239
240+
# #2030: the run's outcome for the `discussion` job to post: what the pin
241+
# refresh moved or warned about, the files the run changed, and the build
242+
# it pushed. `status=warning` where a pin warned, which is what needs a
243+
# hand. `continue-on-error` on both, so a report never fails the bump.
244+
- name: Write the run report
245+
id: run-report
246+
if: ${{ !cancelled() }}
247+
continue-on-error: true
248+
env:
249+
FILES_CHANGED: ${{ steps.verify-changed-files.outputs.files_changed }}
250+
CHANGED_FILES: ${{ steps.verify-changed-files.outputs.changed_files }}
251+
PUSH: ${{ steps.push-changes.outcome }}
252+
COMMIT: ${{ steps.push-changes.outputs.commit }}
253+
run: |
254+
pins="$RUNNER_TEMP/platform-pins.log"
255+
if grep -q '^::warning title=Platform pins::' "$pins" 2> /dev/null; then
256+
echo "status=warning" >> "$GITHUB_OUTPUT"
257+
else
258+
echo "status=success" >> "$GITHUB_OUTPUT"
259+
fi
260+
{
261+
echo '### Conda Update'
262+
echo
263+
if [ ! -f "$pins" ]; then
264+
echo '- Platform pins: not refreshed, as the job stopped first'
265+
elif grep -q '^::[a-z]* title=Platform pins::' "$pins"; then
266+
echo '- Platform pins:'
267+
# The workflow command's data escapes, undone; `%25` last.
268+
grep '^::[a-z]* title=Platform pins::' "$pins" |
269+
sed -e 's/^::\([a-z]*\) title=Platform pins::/ - \1: /' \
270+
-e 's/%0D//g' -e 's/%0A/ /g' -e 's/%25/%/g'
271+
else
272+
echo '- Platform pins: none moved, and none warned'
273+
fi
274+
if [ "$FILES_CHANGED" = true ]; then
275+
echo "- Changed: $CHANGED_FILES"
276+
elif [ "$FILES_CHANGED" = false ]; then
277+
echo '- Changed: nothing, so no build was bumped'
278+
fi
279+
# `commit` is written only beside `pushed=true`.
280+
if [ -n "$COMMIT" ]; then
281+
echo "- Pushed: build $(cat conda/build) as $COMMIT"
282+
elif [ "$PUSH" = success ]; then
283+
echo "- Pushed: nothing; Push Changes' notice says why"
284+
elif [ "$PUSH" = failure ]; then
285+
echo '- Pushed: nothing, as Push Changes failed'
286+
elif [ "$FILES_CHANGED" != false ]; then
287+
echo '- Pushed: nothing, as the job stopped first'
288+
fi
289+
} > "$RUNNER_TEMP/conda-report.md"
290+
cat "$RUNNER_TEMP/conda-report.md"
291+
292+
- name: Upload the run report
293+
if: ${{ !cancelled() }}
294+
continue-on-error: true
295+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
296+
with:
297+
name: conda-report
298+
path: ${{ runner.temp }}/conda-report.md
299+
retention-days: 14
300+
231301
outputs:
232302
# Not `files_changed`: see Push Changes above.
233303
CONDA_CHANGED: ${{ steps.push-changes.outputs.pushed }}
@@ -237,6 +307,8 @@ jobs:
237307
PCAPKIT_CONDA_LABEL: ${{ steps.get_version.outputs.PCAPKIT_CONDA_LABEL }}
238308
PCAPKIT_BUILD: ${{ steps.get_version.outputs.PCAPKIT_BUILD }}
239309
PYTHON_CONDA: ${{ steps.python-versions.outputs.conda }}
310+
# #2030: `warning` where a platform pin warned without failing the job.
311+
status: ${{ steps.run-report.outputs.status }}
240312

241313
conda-tag:
242314
# See create-release.yml: "(update)" keeps this apart from the Conda Tag job
@@ -557,3 +629,77 @@ jobs:
557629
omitPrereleaseDuringUpdate: true
558630
tag: "v${{ needs.conda-update.outputs.PCAPKIT_VERSION }}"
559631
token: "${{ secrets.GITHUB_TOKEN }}"
632+
633+
# #2030: posts `conda-update`'s report with the tag and upload results, and a
634+
# short one of its own where `head` failed or was cancelled, as cron-vendor.yml's
635+
# `discussion` job does, whose comment gives the rules. It waits for
636+
# `conda-dist`, so the report says whether the build reached Anaconda.
637+
discussion:
638+
name: Post the conda report
639+
needs: [ head, conda-update, conda-tag, conda-dist ]
640+
if: >-
641+
${{ always() && (needs.conda-update.result != 'skipped' ||
642+
needs.head.result == 'failure' || needs.head.result == 'cancelled') }}
643+
runs-on: ubuntu-latest
644+
timeout-minutes: 10
645+
continue-on-error: true
646+
permissions:
647+
contents: read
648+
discussions: write
649+
steps:
650+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
651+
with:
652+
persist-credentials: false
653+
654+
# A run that never wrote a report uploaded none; the script then warns.
655+
- name: Download the report
656+
if: needs.conda-update.result != 'skipped'
657+
continue-on-error: true
658+
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
659+
with:
660+
name: conda-report
661+
path: report
662+
663+
# As cron-vendor.yml's: a `workflow_run` posts as a push run, the
664+
# schedule every run. A failed tag or upload fails the report too, and a
665+
# green `conda-update` that warned reports `warning`.
666+
- name: Post the report to Discussions
667+
continue-on-error: true
668+
env:
669+
GH_TOKEN: ${{ github.token }}
670+
MODE: ${{ github.event_name == 'workflow_run' && 'push' || 'scheduled' }}
671+
HEAD_RESULT: ${{ needs.head.result }}
672+
UPDATE_RESULT: ${{ needs.conda-update.result }}
673+
UPDATE_STATUS: ${{ needs.conda-update.outputs.status }}
674+
TAG_RESULT: ${{ needs.conda-tag.result }}
675+
DIST_RESULT: ${{ needs.conda-dist.result }}
676+
run: |
677+
if [ "$UPDATE_RESULT" = skipped ]; then
678+
status="$HEAD_RESULT"
679+
mkdir -p report
680+
{
681+
echo '### Conda Update'
682+
echo
683+
echo "- Gate: $HEAD_RESULT, so conda-update did not run and nothing was built or pushed"
684+
} > report/conda-report.md
685+
else
686+
if [ "$UPDATE_RESULT" != success ]; then
687+
status="$UPDATE_RESULT"
688+
elif [ "$TAG_RESULT" = failure ] || [ "$DIST_RESULT" = failure ]; then
689+
status=failure
690+
elif [ "$TAG_RESULT" = cancelled ] || [ "$DIST_RESULT" = cancelled ]; then
691+
status=cancelled
692+
else
693+
status="${UPDATE_STATUS:-success}"
694+
fi
695+
# Both skip unless a build was pushed.
696+
if [ "$TAG_RESULT" != skipped ] && [ -f report/conda-report.md ]; then
697+
{
698+
echo "- Tag: $TAG_RESULT"
699+
echo "- Upload: $DIST_RESULT"
700+
} >> report/conda-report.md
701+
fi
702+
fi
703+
python3 util/discussion_report.py --category "$REPORT_CATEGORY" \
704+
--title 'cron-conda: conda distribution update report' --report report/conda-report.md \
705+
--mode "$MODE" --status "$status"

‎.github/workflows/cron-python-versions.yml‎

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ name: Python Versions
99
#
1010
# `pr` pushes with the release App's token, not GITHUB_TOKEN, whose pushes
1111
# start nothing, so the pull request's own checks run; none of them runs this
12-
# workflow again.
12+
# workflow again. The `discussion` job posts `detect`'s report to this job's
13+
# thread in the Discussions category REPORT_CATEGORY names (#2030); it alone
14+
# holds `discussions: write`, and a report it cannot post is a warning.
1315
on:
1416
schedule:
1517
- cron: '41 5 * * 1' # Mondays at 05:41 UTC
@@ -24,6 +26,11 @@ concurrency:
2426
group: python-versions
2527
cancel-in-progress: false
2628

29+
# #2030: one Discussions category holds every report with no pull request to
30+
# comment on, one thread per job.
31+
env:
32+
REPORT_CATEGORY: CI reports
33+
2734
jobs:
2835
# No secret and a read-only token. The computation reads the network and
2936
# writes only this checkout, and the audit is the repository's own tests.
@@ -37,6 +44,8 @@ jobs:
3744
outputs:
3845
changed: ${{ steps.update.outputs.changed }}
3946
publish: ${{ steps.update.outputs.publish }}
47+
# #2030: `warning` where the run asks for a hand without failing.
48+
status: ${{ steps.run-report.outputs.status }}
4049

4150
steps:
4251
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
@@ -119,6 +128,84 @@ jobs:
119128
echo "::error title=The audit fails on main::the tiers need no change, but the audit fails; see above."
120129
exit 1
121130
131+
# #2030: what the run found, for the `discussion` job to post, from the
132+
# plan `update` wrote: each tier that moved and why, the notes it raised,
133+
# the audit, and what becomes of the proposal. `status=warning` where a
134+
# note asks for a hand edit, the audit of a changed tree failed, or no
135+
# pull request can open. `continue-on-error` on both, so a report never
136+
# fails the run.
137+
- name: Write the run report
138+
id: run-report
139+
if: ${{ !cancelled() }}
140+
continue-on-error: true
141+
env:
142+
UPDATE: ${{ steps.update.outcome }}
143+
CHANGED: ${{ steps.update.outputs.changed }}
144+
PUBLISH: ${{ steps.update.outputs.publish }}
145+
AUDIT: ${{ steps.audit.outcome }}
146+
APP: ${{ vars.RELEASE_APP_CLIENT_ID != '' }}
147+
ON_MAIN: ${{ github.ref == 'refs/heads/main' }}
148+
run: |
149+
python3 - "$RUNNER_TEMP/proposal/plan.json" "$RUNNER_TEMP/python-versions-report.md" <<'PY'
150+
import json, os, pathlib, sys
151+
152+
env = os.environ
153+
source, target = map(pathlib.Path, sys.argv[1:])
154+
plan = json.loads(source.read_text(encoding='utf-8')) if source.is_file() else None
155+
156+
157+
def tier(entry):
158+
if entry is None:
159+
return '--'
160+
name = 'KTLO' if entry['tier'] == 'ktlo' else entry['tier']
161+
return f"{name} on `{entry['runner']}`" if 'runner' in entry else name
162+
163+
164+
lines, warned = ['### Python Versions', ''], False
165+
if plan is None:
166+
lines.append('- Tiers: not computed, as the job stopped first')
167+
else:
168+
moves = [f" - `{c['version']}`: {tier(c['before'])} -> {tier(c['after'])} ({c['reason']})"
169+
for c in plan['changes']]
170+
if plan['latest'][0] != plan['latest'][1]:
171+
moves.append(f" - `latest`: {plan['latest'][0]} -> {plan['latest'][1]}")
172+
lines += ['- Tiers moved:', *moves] if moves else ['- Tiers: unchanged']
173+
if plan['changed_files']:
174+
lines.append('- Regenerated: ' + ', '.join(f'`{path}`' for path in plan['changed_files']))
175+
for kind in ('remove', 'add'):
176+
lines += [f'- Ruleset 23497679, by hand: {kind} `{name}`' for name in plan['required'][kind]]
177+
lines += [f"- {note['kind']}: {note['text']}" for note in plan['notes']]
178+
warned = any(note['kind'] != 'held' for note in plan['notes'])
179+
lines.append(f"- Audit: {env.get('AUDIT') or 'not run'}")
180+
warned = warned or (env.get('CHANGED') == 'true' and env.get('AUDIT') != 'success')
181+
if env.get('UPDATE') != 'success':
182+
lines.append('- Pull request: none, as Recompute the tiers failed')
183+
elif env.get('CHANGED') != 'true':
184+
lines.append('- Pull request: none needed, as nothing changed')
185+
elif env.get('PUBLISH') != 'true':
186+
lines.append('- Pull request: none, as `bot/python-versions` already proposes these tiers')
187+
elif env.get('APP') != 'true':
188+
lines.append('- Pull request: none, as `vars.RELEASE_APP_CLIENT_ID` is unset')
189+
warned = True
190+
elif env.get('ON_MAIN') != 'true':
191+
lines.append('- Pull request: none, as this run is not on `main`')
192+
else:
193+
lines.append('- Pull request: the `pr` job opens or updates it once `github-release` is approved')
194+
target.write_text('\n'.join(lines) + '\n', encoding='utf-8')
195+
with open(env['GITHUB_OUTPUT'], 'a', encoding='utf-8') as file:
196+
file.write(f"status={'warning' if warned else 'success'}\n")
197+
PY
198+
cat "$RUNNER_TEMP/python-versions-report.md"
199+
200+
- name: Upload the run report
201+
if: ${{ !cancelled() }}
202+
continue-on-error: true
203+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
204+
with:
205+
name: python-versions-report
206+
path: ${{ runner.temp }}/python-versions-report.md
207+
retention-days: 14
208+
122209
# The release App's key is a secret of the `github-release` environment,
123210
# which needs the owner's approval, so he is asked only when there is
124211
# something to propose. The token has no `workflows` permission, so it cannot
@@ -168,3 +255,49 @@ jobs:
168255
APP_SLUG: ${{ steps.app.outputs.app-slug }}
169256
APP_BOT_ID: ${{ vars.RELEASE_APP_BOT_ID }}
170257
run: python3 util/update_python_versions.py publish "$RUNNER_TEMP/proposal"
258+
259+
# #2030: posts `detect`'s report, on `always()` so a run failed by the audit
260+
# or the script is posted too. Not after `pr`, which waits on the owner's
261+
# approval of `github-release`; the pull request it opens is its own record.
262+
# util/discussion_report.py writes a warning rather than failing;
263+
# `continue-on-error` covers the rest.
264+
discussion:
265+
name: Post the Python version report
266+
needs: [ detect ]
267+
if: ${{ always() && needs.detect.result != 'skipped' }}
268+
runs-on: ubuntu-latest
269+
timeout-minutes: 10
270+
continue-on-error: true
271+
permissions:
272+
contents: read
273+
discussions: write
274+
275+
steps:
276+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
277+
with:
278+
persist-credentials: false
279+
280+
# A run that never wrote a report uploaded none; the script then warns.
281+
- name: Download the report
282+
continue-on-error: true
283+
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
284+
with:
285+
name: python-versions-report
286+
path: report
287+
288+
# `scheduled` on dispatch too: a manual run is a deliberate report. A
289+
# green `detect` that asked for a hand reports `warning`.
290+
- name: Post the report to Discussions
291+
continue-on-error: true
292+
env:
293+
GH_TOKEN: ${{ github.token }}
294+
DETECT_RESULT: ${{ needs.detect.result }}
295+
DETECT_STATUS: ${{ needs.detect.outputs.status }}
296+
run: |
297+
status="$DETECT_RESULT"
298+
if [ "$DETECT_RESULT" = success ] && [ -n "$DETECT_STATUS" ]; then
299+
status="$DETECT_STATUS"
300+
fi
301+
python3 util/discussion_report.py --category "$REPORT_CATEGORY" \
302+
--title 'cron-python-versions: Python version update report' \
303+
--report report/python-versions-report.md --mode scheduled --status "$status"

0 commit comments

Comments
 (0)