trigger-fork-pr-ci
Skill578 starsChanged 8 months agoMITView on GitHub
Trigger Azure Pipelines CI (default mscclpp-ut) for a fork pull request by creating an isolated temporary pr-<N>-<sha>-<nonce> branch at the PR head commit, queueing the pipeline run, canceling active PR merge runs, and removing the temporary branch after completion. Use when asked to trigger mscclpp-ut or other CI pipelines for a fork pull request.
In this repository2 other files it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
- device-code-reviewSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 13
Fork PRs only: Only run this workflow on cross-repository (fork) pull requests.
- Distinctive: line 14
Local Git checkout required: Run from a local Git checkout of the target repository.
- Very specific: line 61
Wait ~10 seconds and check gh api "repos/<owner>/<repo>/commits/<HEAD_SHA>/check-runs?per_page=100" to confirm the pipeline's check runs on …
- Very specific: line 64
Keep refs/heads/<RUN_BRANCH> until <buildId> reaches Completed so all queued matrix jobs can fetch the ref when starting.
- Very specific: line 65
If save_session_automation is available and get_session_automation shows no active conflicting schedule, register a 15-minute check …
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Trigger Fork PR CI
Queue an Azure Pipelines validation run for a fork pull request on an isolated, single-use upstream branch pr-<pr_number>-<short_sha>-<nonce> pointing to the PR's exact head commit so GitHub Check Runs report directly back to that commit, then clean up the temporary branch once the run completes.
Prerequisites and User Responsibility
- Fork PRs only: Only run this workflow on cross-repository (fork) pull requests. Same-repository pull requests should use standard PR triggers or
/azp run. - Local Git checkout required: Run from a local Git checkout of the target repository; stop and ask the user to open a repository workspace if none is available.
- Reviewer responsibility: The user invoking this skill is responsible for reviewing the fork pull request's changes at
HEAD_SHAbefore running upstream CI, and for running manual cleanup (/trigger-fork-pr-ci cleanup <pr_number>) if automated cleanup cannot run or encounters an ambiguous state.
Inputs
pr_number: Pull request number (infer from the active session's tracked PR if omitted).pipeline_name: Optional pipeline definition name. Defaults tomscclpp-ut.cleanup <pr_number>: Allowed for open, closed, or merged PRs. Resolve<owner>/<repo>and<project>(Step 2, without requiring the PR to be open), list refs viagh api --paginate "repos/<owner>/<repo>/git/matching-refs/heads/pr-<pr_number>", and filter strictly to exactrefs/heads/pr-<pr_number>or prefixrefs/heads/pr-<pr_number>-. For each matching<branch_ref>, exhaustively list all builds across every pipeline definition (action: "list",project: "<project>",branchName: "<branch_ref>",queryOrder: "QueueTimeDescending", pagingcontinuationTokenuntilnullwhile omittingdefinitions,top, andrepositoryId), and delete<branch_ref>only when the complete listing succeeds, returns at least one build, and every returned build hasstatus == "Completed"(report any zero-build or ambiguous refs to the user to confirm deletion).
Execution Steps
- Verify fork PR metadata and modified paths (trigger mode only)
- Resolve the target repository (
<owner>/<repo>) from the local Git checkout (gh repo view --json nameWithOwner --jq .nameWithOwner). - Query the pull request in a single call:
gh api repos/<owner>/<repo>/pulls/<pr_number> --jq '{number, state, is_fork: (.head.repo != null and .head.repo.full_name != .base.repo.full_name), base_sha: .base.sha, head_sha: .head.sha}' - Require
state == "open"andis_fork == true(ifis_forkisfalse, stop and tell the user to trigger CI directly on the PR without creating a temporary branch), and record the immutable 40-characterBASE_SHAandHEAD_SHA. - Fetch both immutable commits into the local checkout and list changed paths with rename detection disabled:
git fetch --no-tags origin <BASE_SHA> <HEAD_SHA> git --no-pager diff --no-renames --name-only <BASE_SHA>...<HEAD_SHA> - Pre-trigger confirmation (bound to
HEAD_SHA): If any changed path touches CI, build, container, or deployment inputs (.azure-pipelines/,.github/,.devcontainer/,cmake/,docker/,test/deploy/,tools/, any root or nested**/CMakeLists.txt,*.cmake,**/Makefile,pyproject.toml,setup.py,setup.cfg,python/requirements*.txt, or*.sh/*.sh.in), inspectgit --no-pager diff --no-renames <BASE_SHA>...<HEAD_SHA>first and ask the user for explicit confirmation bound toHEAD_SHAbefore creating a branch or queueing a build. Never reuse confirmation granted for a differentHEAD_SHA.
- Resolve the target repository (
- Resolve the Azure DevOps project and pipeline ID dynamically
- Load the Azure DevOps pipeline tools via
tool_search_toolif deferred (azure-devops-pipelines_definition,azure-devops-pipelines_build,azure-devops-pipelines_write). - Query
gh pr view <pr_number> --repo <owner>/<repo> --json statusCheckRollup(works for open, closed, or merged PRs) and extract the Azure DevOps<project>identifier from an existing pipelinedetailsUrl(or fall back to CI badge URLs inREADME.md/azure-devops-core_list_projects). - For trigger requests, look up
<pipeline_id>viaazure-devops-pipelines_definition(action: "list",project: "<project>",name: "<pipeline_name>",repositoryId: "<owner>/<repo>",repositoryType: "GitHub").
- Load the Azure DevOps pipeline tools via
- Create an isolated temporary branch and queue the pipeline
- Generate a fresh, single-use branch name
RUN_BRANCH="pr-<pr_number>-<HEAD_SHA_8>-<6_hex_nonce>"(never reuse or force-update an existing branch) pointing directly toHEAD_SHAwithout creating a merge commit or rebase:gh api -X POST repos/<owner>/<repo>/git/refs -f ref="refs/heads/<RUN_BRANCH>" -f sha="<HEAD_SHA>" - Queue the build via
azure-devops-pipelines_write:action:"run_pipeline"project:"<project>"pipelineId:<pipeline_id>resources:{ "repositories": { "self": { "refName": "refs/heads/<RUN_BRANCH>", "version": "<HEAD_SHA>" } } }
- If
run_pipelineerrors or times out after the ref was created, checkazure-devops-pipelines_build(action: "list",project: "<project>",branchName: "refs/heads/<RUN_BRANCH>"): if a build was created, adopt itsbuildIdand continue; deleterefs/heads/<RUN_BRANCH>immediately only when that listing succeeds and returns zero builds (otherwise leave the ref intact and ask the user to reconcile viacleanup <pr_number>).
- Generate a fresh, single-use branch name
- Cancel active fork merge runs
refs/pull/<pr_number>/mergeruns are automatically queued by GitHub PR webhooks for fork PRs, where they fail due to fork restrictions and hold CI runners.- Exhaustively list runs on
refs/pull/<pr_number>/mergefor<pipeline_id>viaazure-devops-pipelines_build(action: "list",project: "<project>",definitions: [<pipeline_id>],branchName: "refs/pull/<pr_number>/merge",queryOrder: "QueueTimeDescending", pagingcontinuationTokenuntilnullwithoutrepositoryId), and intentionally cancel everyNotStartedorInProgressmerge run regardless of commit SHA viaazure-devops-pipelines_write(action: "update_build_stage",project: "<project>",buildId: <old_build_id>,stageName: "__default",status: "Cancel"; if a pipeline defines explicitstages:in.azure-pipelines/*.ymlinstead of an implicit__defaultstage, cancel each declared stage name—or use build-levelaz pipelines build cancel --build-id <old_build_id>when Azure CLI is authenticated).
- Verify GitHub Check Runs
- Wait ~10 seconds and check
gh api "repos/<owner>/<repo>/commits/<HEAD_SHA>/check-runs?per_page=100"to confirm the pipeline's check runs onHEAD_SHAreference the newbuildId.
- Wait ~10 seconds and check
- Clean up
<RUN_BRANCH>after completion- Keep
refs/heads/<RUN_BRANCH>until<buildId>reachesCompletedso all queued matrix jobs can fetch the ref when starting. - If
save_session_automationis available andget_session_automationshows no active conflicting schedule, register a 15-minute check (interval: "minutes",every_minutes: 15) whose prompt:- Queries
azure-devops-pipelines_build(action: "list",project: "<project>",buildIds: [<buildId>]). If this call fails orstatus != "Completed", waits for the next check. - Once
status == "Completed", deletes the dedicatedrefs/heads/<RUN_BRANCH>viagh api -X DELETE repos/<owner>/<repo>/git/refs/heads/<RUN_BRANCH>(treating404as already clean), clears the schedule viasave_session_automation(clear=true), and reports the final result of<buildId>.
- Queries
- Otherwise — if
save_session_automationis unavailable orget_session_automationalready has a conflicting schedule (do not overwrite an existing schedule) — remind the user to run/trigger-fork-pr-ci cleanup <pr_number>once the build finishes.
- Keep
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

