Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 46 additions & 7 deletions .github/workflows/breakage-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,34 @@ on:
# skipped, and a `concurrency` of the caller would still cancel the run in progress. The
# group starts with a name of its own: it must differ from every group of a caller.
# `group` keeps apart the suites called by one caller workflow.
# A run started by label-dispatch.yml (a `workflow_dispatch` with the input `pr`) is a
# run of that pull request: same group, same cancellation.
concurrency:
group: ctactions-breakage-suite-${{ github.workflow }}-${{ inputs.group }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
group: ctactions-breakage-suite-${{ github.workflow }}-${{ inputs.group }}-${{ github.event.pull_request.number || github.event.inputs.pr || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && github.event.inputs.pr != '') }}

jobs:
# A run started by label-dispatch.yml shows as a commit status (pr-status.yml).
status-start:
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.pr != '' }}
permissions:
statuses: write
uses: control-toolbox/CTActions/.github/workflows/pr-status.yml@main
with:
context: Breakage / ${{ inputs.group }}
phase: start

status-end:
needs: [changes, carry-baseline, plan, break, report]
if: ${{ always() && github.event_name == 'workflow_dispatch' && github.event.inputs.pr != '' }}
permissions:
statuses: write
uses: control-toolbox/CTActions/.github/workflows/pr-status.yml@main
with:
context: Breakage / ${{ inputs.group }}
phase: end
results: ${{ toJSON(needs.*.result) }}

# Whether the suite runs (docs/workflows/guard.md): no on a pull request that is not open;
# on a push to main, yes unless the merged pull request carries the label
# `ci on main: changes only` (docs/workflows/ci-on-main.md); yes otherwise. When it does
Expand Down Expand Up @@ -273,12 +296,27 @@ jobs:
pattern: breakage-cell-${{ inputs.group }}-*
merge-multiple: true

# The pull request of this run: the event's on a `pull_request`, the input `pr` on a
# dispatch from label-dispatch.yml, none on a push, a manual run or the cron.
- name: Pull request
id: pr
env:
GH_TOKEN: ${{ github.token }}
NUMBER: ${{ github.event.pull_request.number || github.event.inputs.pr }}
run: |
[ -n "$NUMBER" ] || exit 0
{
echo "number=$NUMBER"
gh api "repos/$GITHUB_REPOSITORY/pulls/$NUMBER" \
--jq '"base_sha=\(.base.sha)", "fork=\(.head.repo.fork // false)"'
} >> "$GITHUB_OUTPUT"

# On a PR: the run of this workflow on the base commit, outside a PR (push or dispatch)
- name: Baseline
if: github.event_name == 'pull_request'
if: steps.pr.outputs.number != ''
env:
GH_TOKEN: ${{ github.token }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
BASE_SHA: ${{ steps.pr.outputs.base_sha }}
WORKFLOW_REF: ${{ github.workflow_ref }}
GROUP: ${{ inputs.group }}
run: |
Expand All @@ -297,7 +335,7 @@ jobs:
TARGETS: ${{ needs.plan.outputs.targets }}
VERSIONS: ${{ inputs.versions }}
GROUP: ${{ inputs.group }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
BASE_SHA: ${{ steps.pr.outputs.base_sha }}
SHA: ${{ github.event.pull_request.head.sha || github.sha }}
run: |
expected=$(( $(jq length <<< "$TARGETS") * $(jq length <<< "$VERSIONS") ))
Expand All @@ -322,14 +360,15 @@ jobs:
# Not on a pull request from a fork: its token is read-only and the comment would
# fail the job (and hide the verdict below). The report is in the run's summary.
- name: Comment on the PR
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork != true
if: steps.pr.outputs.number != '' && steps.pr.outputs.fork != 'true'
uses: actions/github-script@v9
env:
MARKER: <!-- ct-breakage:${{ inputs.group }} -->
PR: ${{ steps.pr.outputs.number }}
with:
script: |
const body = require('fs').readFileSync('out/summary.md', 'utf8')
const issue_number = context.payload.pull_request.number
const issue_number = Number(process.env.PR)
const comments = await github.paginate(github.rest.issues.listComments,
{ owner: context.repo.owner, repo: context.repo.repo, issue_number })
const mine = comments.find(c => c.body && c.body.startsWith(process.env.MARKER))
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/breakage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ on:
# skipped, and a `concurrency` of the caller would still cancel the run in progress. The
# group starts with a name of its own: it must differ from every group of a caller.
# The inputs keep apart the packages called by one caller workflow.
# A run started by label-dispatch.yml (a `workflow_dispatch` with the input `pr`) is a
# run of that pull request: same group, same cancellation.
concurrency:
group: ctactions-breakage-${{ github.workflow }}-${{ inputs.pkgname }}-${{ inputs.pkgpath }}-${{ inputs.pkgbreak }}-${{ inputs.pkgversion }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
group: ctactions-breakage-${{ github.workflow }}-${{ inputs.pkgname }}-${{ inputs.pkgpath }}-${{ inputs.pkgbreak }}-${{ inputs.pkgversion }}-${{ github.event.pull_request.number || github.event.inputs.pr || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && github.event.inputs.pr != '') }}

jobs:
break:
Expand Down Expand Up @@ -217,12 +219,14 @@ jobs:
- name: Comment on PR
if: github.event.pull_request.head.repo.fork != true
uses: actions/github-script@v9
env:
PR: ${{ github.event.pull_request.number || github.event.inputs.pr }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs')
const msg = fs.readFileSync('breakage/summary.md', 'utf8')
const prNumber = context.payload.pull_request?.number
const prNumber = Number(process.env.PR)
if (!prNumber) {
console.log("No PR number found.")
return
Expand Down
27 changes: 25 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,34 @@ on:
# group starts with a name of its own: it must differ from every group of a caller.
# `runner_type` and `runs_on` keep apart the calls of one caller workflow (the GitHub, kkt
# and occidata runners of one `CI.yml`, which also reach this workflow through ci-gpu.yml).
# A run started by label-dispatch.yml (a `workflow_dispatch` with the input `pr`) is a
# run of that pull request: same group, same cancellation.
concurrency:
group: ctactions-ci-${{ github.workflow }}-${{ inputs.runner_type }}-${{ inputs.runs_on }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
group: ctactions-ci-${{ github.workflow }}-${{ inputs.runner_type }}-${{ inputs.runs_on }}-${{ github.event.pull_request.number || github.event.inputs.pr || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && github.event.inputs.pr != '') }}

jobs:
# A run started by label-dispatch.yml shows as a commit status (pr-status.yml).
status-start:
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.pr != '' }}
permissions:
statuses: write
uses: control-toolbox/CTActions/.github/workflows/pr-status.yml@main
with:
context: CI / ${{ github.event.inputs.target }}
phase: start

status-end:
needs: [changes, test]
if: ${{ always() && github.event_name == 'workflow_dispatch' && github.event.inputs.pr != '' }}
permissions:
statuses: write
uses: control-toolbox/CTActions/.github/workflows/pr-status.yml@main
with:
context: CI / ${{ github.event.inputs.target }}
phase: end
results: ${{ toJSON(needs.*.result) }}

# Whether the jobs below run (docs/workflows/guard.md): no on a pull request that is not
# open; on a push to main, yes unless the merged pull request carries the label
# `ci on main: changes only` (docs/workflows/ci-on-main.md); yes otherwise.
Expand Down
46 changes: 39 additions & 7 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,35 @@ on:
# not in the caller: a label that changes nothing creates a run whose calling job is
# skipped, and a `concurrency` of the caller would still cancel the run in progress. The
# group starts with a name of its own: it must differ from every group of a caller.
# A run started by label-dispatch.yml (a `workflow_dispatch` with the input `pr`) is a
# run of that pull request: same group, same cancellation.
concurrency:
group: ctactions-documentation-${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
group: ctactions-documentation-${{ github.workflow }}-${{ github.event.pull_request.number || github.event.inputs.pr || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && github.event.inputs.pr != '') }}

jobs:
# A run started by label-dispatch.yml shows as a commit status (pr-status.yml).
status-start:
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.pr != '' }}
permissions:
statuses: write
uses: control-toolbox/CTActions/.github/workflows/pr-status.yml@main
with:
context: Documentation
phase: start

status-end:
needs: [changes, build]
if: ${{ always() && github.event_name == 'workflow_dispatch' && github.event.inputs.pr != '' }}
permissions:
statuses: write
uses: control-toolbox/CTActions/.github/workflows/pr-status.yml@main
with:
context: Documentation
phase: end
results: ${{ toJSON(needs.*.result) }}
preview_pr: ${{ github.event.inputs.preview == 'true' && github.event.inputs.pr || '' }}

# Whether the jobs below run (docs/workflows/guard.md): no on a pull request that is not
# open; on a push to main, yes unless the merged pull request carries the label
# `ci on main: changes only` (docs/workflows/ci-on-main.md); yes otherwise.
Expand Down Expand Up @@ -118,15 +142,23 @@ jobs:
# PR previews are opt-in: `DOCUMENTER_PUSH_PREVIEW` is "true" only on a PR carrying
# the `documentation push preview` label, "false" otherwise. A caller's make.jl reads
# it as `push_preview = get(ENV, "DOCUMENTER_PUSH_PREVIEW", "false") == "true"`.
# Inside a reusable workflow `github.event` is the caller's event, so the PR's labels
# are visible here. A make.jl that still hardcodes `push_preview` ignores it.
# Inside a reusable workflow `github.event` is the caller's event: the PR's labels
# are visible here on a `pull_request`, and on a `workflow_dispatch` from
# label-dispatch.yml the inputs `pr` and `preview` say the same. A make.jl that
# still hardcodes `push_preview` ignores it.
# Documenter takes a build for a preview only on `GITHUB_EVENT_NAME=pull_request` and
# `GITHUB_REF=refs/pull/<n>/merge`; a dispatched run has neither, so the build is told.
- name: Build and deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
DOCUMENTER_PUSH_PREVIEW: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'documentation push preview') }}
DOCUMENTER_PUSH_PREVIEW: ${{ (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'documentation push preview')) || (github.event_name == 'workflow_dispatch' && github.event.inputs.pr != '' && github.event.inputs.preview == 'true') }}
DISPATCH_PR: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.pr || '' }}
GKSwstype: 100
run: |
if [ -n "$DISPATCH_PR" ]; then
export GITHUB_EVENT_NAME=pull_request GITHUB_REF="refs/pull/$DISPATCH_PR/merge"
fi
julia --project=docs/ -e 'ENV["GKSwstype"]="nul"; include("docs/make.jl")'
echo "📂 Listing docs/build/assets:"
ls -R docs/build/assets || true
Expand All @@ -145,7 +177,7 @@ jobs:
# `build` ran.
if: >
!cancelled() && needs.build.result == 'success' &&
inputs.gpu_runner == 'auto' && github.event_name != 'pull_request'
inputs.gpu_runner == 'auto' && github.event_name != 'pull_request' && !github.event.inputs.pr
uses: control-toolbox/CTActions/.github/workflows/select-gpu-runner.yml@main
secrets:
CT_RUNNERS_CLIENT_ID: ${{ secrets.CT_RUNNERS_CLIENT_ID }}
Expand All @@ -157,7 +189,7 @@ jobs:
needs: [build, select-gpu]
if: >
always() && needs.build.result == 'success' &&
inputs.gpu_runner != '' && github.event_name != 'pull_request' &&
inputs.gpu_runner != '' && github.event_name != 'pull_request' && !github.event.inputs.pr &&
(inputs.gpu_runner != 'auto' || needs.select-gpu.result == 'success')
runs-on: ${{ fromJSON(inputs.gpu_runner == 'auto' && needs.select-gpu.outputs.runs_on_labels || inputs.gpu_runner) }}
timeout-minutes: ${{ inputs.gpu_timeout_minutes }}
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/label-dispatch-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Label dispatch tests

# Self-test of label-dispatch.yml (docs/workflows/label-dispatch.md): the tests of its
# mapping label -> workflow (scripts/label-dispatch/test.sh).

on:
pull_request:
paths:
- '.github/workflows/label-dispatch.yml'
- '.github/workflows/label-dispatch-tests.yml'
- 'scripts/label-dispatch/**'
push:
branches: [main]
paths:
- '.github/workflows/label-dispatch.yml'
- '.github/workflows/label-dispatch-tests.yml'
- 'scripts/label-dispatch/**'
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v7
- run: bash scripts/label-dispatch/test.sh
83 changes: 83 additions & 0 deletions .github/workflows/label-dispatch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Label dispatch

# Starts, for a label added to a pull request, the workflow of that label, and only that
# one (docs/workflows/label-dispatch.md). The heavy workflows of a package (CI,
# Documentation, Breakage) do not listen to `pull_request`: a label is not a filter of that
# event, so every label would create a run of each of them, and the latest run, all jobs
# skipped, would hide on the pull request page the one still running. They listen to
# `workflow_dispatch`, and this workflow dispatches them:
#
# - `labeled`: the workflow of the label just added; a label that starts nothing, nothing;
# - `synchronize`, `reopened`: the workflow of every label the pull request carries.
#
# A run started by a label is never cancelled by another label. A new push cancels the run
# of the same workflow and the same pull request (docs/workflows/superseded-runs.md).
# The mapping label -> workflow is scripts/label-dispatch/plan.sh. Each dispatched workflow
# declares the inputs it is given: `pr` always, `target` (CI, Breakage), `preview`
# (Documentation).
#
# Not for a pull request that is not open, nor for one from a fork: a fork's branch cannot
# be dispatched and its token is read-only. The job says so in its summary.

on:
workflow_call:
inputs:
ctactions_ref:
description: 'Ref of CTActions whose script is used (main; a branch to test a change)'
required: false
type: string
default: main

jobs:
dispatch:
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
actions: write # gh workflow run
env:
DISPATCHABLE: ${{ github.event.pull_request.state == 'open' && github.event.pull_request.head.repo.full_name == github.repository }}
steps:
- name: Not dispatched
if: env.DISPATCHABLE != 'true'
run: |
echo "Not dispatched, the pull request is not open or its branch is in a fork." >> "$GITHUB_STEP_SUMMARY"

- uses: actions/checkout@v7
if: env.DISPATCHABLE == 'true'
with:
repository: control-toolbox/CTActions
ref: ${{ inputs.ctactions_ref }}
path: .ctactions
sparse-checkout: scripts/label-dispatch

- name: Dispatch
if: env.DISPATCHABLE == 'true'
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }} # no git repository in the workspace
ACTION: ${{ github.event.action }}
LABEL: ${{ github.event.label.name }}
LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }}
PR: ${{ github.event.pull_request.number }}
REF: ${{ github.event.pull_request.head.ref }}
run: |
plan=$(bash .ctactions/scripts/label-dispatch/plan.sh)
if [ -z "$plan" ]; then
echo "Nothing to dispatch for \`$ACTION\` ${LABEL:+(label \`$LABEL\`)}." >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
status=0
echo "Dispatched on \`$REF\` for #$PR:" >> "$GITHUB_STEP_SUMMARY"
while read -r file args; do
flags=(-f "pr=$PR")
for kv in $args; do flags+=(-f "$kv"); done
if gh workflow run "$file" --ref "$REF" "${flags[@]}"; then
echo "- \`$file\` $args" >> "$GITHUB_STEP_SUMMARY"
else
echo "::error::could not dispatch $file: does it have a workflow_dispatch trigger with the inputs pr and the ones of the label?"
echo "- ❌ \`$file\` $args" >> "$GITHUB_STEP_SUMMARY"
status=1
fi
done <<< "$plan"
exit $status
Loading
Loading