Files
OrcaSlicer/.github/workflows/check_gcode_comment.yml
T
Hanif Koh 49252d14b7 Post the Sliced G-code Comparison on Pull Requests With the check-gcode Label
check_gcode_comment.yml runs when a pull request's Build all run or a
check-gcode label run completes, finds the open pull requests from that
branch, and posts the report of the newest finished build on each one
that has the label. check_gcode_label.yml only wakes it when the label
is added after the build finished; it needs no token and runs nothing.
Neither uses pull_request_target, which GitHub blocks by default in
public repositories.

Runs are kept only when their head repository and branch are the pull
request's, and the artifact must name the pull request, so another fork
at the same commit cannot have its report posted. A run waiting for
approval counts as not finished. The comment is kept when unchanged,
edited in place when only the commit or the baseline moved, and
replaced otherwise. The report appears only inside a fence nothing in
it can close, errors print their type and HTTP status only, and the
step cannot leave a red check.
2026-11-28 22:08:48 +08:00

56 lines
2.2 KiB
YAML

name: Post sliced G-code comparison
# Posts the comparison that the Slice check of build_all.yml wrote into its gcode-fingerprints
# artifact, on an open pull request with the check-gcode label. Woken by both workflows below,
# whichever finishes last; scripts/ci_check_gcode.py then starts from each pull request's
# current head.
#
# Its token can write, so it never checks out, unpacks or runs anything from a pull request.
# The artifact is read in memory, and its text only appears inside a fence in the comment.
#
# The names in 'workflows' must match the 'name' fields of build_all.yml and
# check_gcode_label.yml exactly.
on:
workflow_run:
workflows: ["Build all", "check-gcode label"]
types:
- completed
permissions:
actions: read
contents: read
pull-requests: write
# Needed to delete outdated bot comments through the issues/comments endpoint.
issues: write
# One handler at a time per source branch, so two wakes cannot race delete-and-post.
concurrency:
group: ${{ github.workflow }}-${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: false
jobs:
post_comment:
name: Post the comparison comment
runs-on: ubuntu-24.04
timeout-minutes: 10
# A label workflow run for any other label is skipped and has nothing to wake.
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion != 'skipped' }}
steps:
- name: Checkout the scripts from the default branch
uses: actions/checkout@v7
with:
sparse-checkout: |
scripts/ci_check_gcode.py
scripts/gcode_fingerprint.py
sparse-checkout-cone-mode: false
persist-credentials: false
- name: Update the comment
# A failure would leave a red check on the pull request, which blocks pr-merge-bot.
continue-on-error: true
env:
GH_TOKEN: ${{ github.token }}
HEAD_REPO: ${{ github.event.workflow_run.head_repository.full_name }}
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
run: python3 scripts/ci_check_gcode.py comment --repo "$GITHUB_REPOSITORY" --head-repo "$HEAD_REPO" --head-branch "$HEAD_BRANCH"