11name : CLA Gate
22
3- # This workflow makes CLA checks work with merge queue entries. Merge groups get
4- # a repository-owned `CLA Gate` commit status on the synthetic queue SHA, while
5- # pull request/status events use this Actions job result based on CLA Assistant's
6- # raw `license/cla` status.
7- #
8- # SECURITY: Pull request runs must still check out trusted base-branch code, not
9- # PR code, before running repository scripts.
3+ # This workflow publishes a repository-owned commit status named `CLA Gate`.
4+ # Make `CLA Gate` required instead of requiring CLA Assistant's raw `license/cla`
5+ # status directly. That lets merge queue entries pass without waiting for CLA
6+ # Assistant to report on the synthetic merge-group SHA, while pull requests still
7+ # mirror the real CLA Assistant result.
108
119on :
12- pull_request :
13- types : [opened, reopened]
1410 status :
1511 merge_group :
1612
1713permissions :
1814 contents : read
19- pull-requests : read
2015 statuses : write
2116
2217jobs :
@@ -42,11 +37,20 @@ jobs:
4237 const { execFileSync } = require("child_process");
4338
4439 function claStatus(args) {
45- const output = execFileSync("cargo", ["ci", "cla-assistant", "status", ...args], {
40+ const command = ["ci", "cla-assistant", "status", ...args];
41+ core.info(`Running cargo ${command.join(" ")}`);
42+ const output = execFileSync("cargo", command, {
4643 encoding: "utf8",
4744 env: process.env,
4845 });
49- return JSON.parse(output);
46+ core.info(`cargo ci output: ${output.trim()}`);
47+ const status = JSON.parse(output);
48+ core.info(
49+ `Resolved license/cla for ${status.sha}: state=${status.state || "missing"} ` +
50+ `description=${status.description || "<none>"} ` +
51+ `target_url=${status.target_url || "<none>"}`
52+ );
53+ return status;
5054 }
5155
5256 async function postStatus({ sha, state, description, targetUrl }) {
6973 let targetSha;
7074 let claStatusArgs;
7175
76+ core.info(
77+ `Handling ${context.eventName} event for workflow SHA ${process.env.GITHUB_SHA}`
78+ );
79+
7280 if (context.eventName === "merge_group") {
81+ core.info(`Merge group SHA is ${process.env.GITHUB_SHA}`);
7382 await postStatus({
7483 sha: process.env.GITHUB_SHA,
7584 state: "success",
@@ -81,28 +90,25 @@ jobs:
8190 if (context.eventName === "status") {
8291 targetSha = context.payload.sha;
8392 claStatusArgs = ["--sha", targetSha];
84- } else if (context.eventName === "pull_request") {
85- const pr = context.payload.pull_request;
86- targetSha = pr.head.sha;
87- claStatusArgs = ["--pr", String(pr.number)];
93+ core.info(
94+ `status event context=${context.payload.context} state=${context.payload.state} sha=${targetSha}`
95+ );
8896 } else {
8997 core.setFailed(`Unsupported event type: ${context.eventName}`);
9098 return;
9199 }
92100
101+ core.info(`Checking license/cla with args: ${claStatusArgs.join(" ")}`);
93102 const status = claStatus(claStatusArgs);
94103
95104 if (!status.state) {
96105 core.info(`No CLA Gate status to publish for ${targetSha}`);
97106 return;
98107 }
99108
100- if (status.state === "success") {
101- core.info(`license/cla is success for ${targetSha}`);
102- return;
103- }
104-
105- const state = status.state || "missing";
106- const description = status.description || "license/cla status is missing";
107- const targetUrl = status.target_url ? ` (${status.target_url})` : "";
108- core.setFailed(`license/cla is ${state}: ${description}${targetUrl}`);
109+ await postStatus({
110+ sha: targetSha,
111+ state: status.state,
112+ description: status.description || undefined,
113+ targetUrl: status.target_url || undefined,
114+ });
0 commit comments