@@ -82,7 +82,7 @@ test("oversized API files fail before any publication", () => {
8282 ) ;
8383} ) ;
8484
85- function publicationFixture ( t , changed ) {
85+ function publicationFixture ( t , changed , apiEnv = { } ) {
8686 const root = mkdtempSync ( join ( tmpdir ( ) , "catalog-publication-api-" ) ) ;
8787 t . after ( ( ) => rmSync ( root , { recursive : true , force : true } ) ) ;
8888 const git = ( ...args ) => execFileSync ( "git" , args , { cwd : root , encoding : "utf8" } ) . trim ( ) ;
@@ -116,11 +116,14 @@ const endpoint = args[1];
116116const method = args[args.indexOf("--method") + 1];
117117const body = args.includes("--input") ? JSON.parse(fs.readFileSync(0, "utf8")) : undefined;
118118fs.appendFileSync(process.env.API_CALLS, JSON.stringify({ endpoint, method, body }) + "\\n");
119- if (endpoint === "graphql" || method === "DELETE") {
119+ if (!process.env.PUBLISH_SUCCESS && ( endpoint === "graphql" || method === "DELETE") ) {
120120 console.error(endpoint === "graphql" ? "commit rejected" : "cleanup rejected");
121121 process.exit(1);
122122}
123- if (endpoint.endsWith("/ref/heads/main")) console.log(process.env.BASE);
123+ if (endpoint === "graphql") console.log("c".repeat(40));
124+ else if (endpoint.includes("/runs?")) console.log(JSON.stringify({ workflow_runs: JSON.parse(process.env.WORKFLOW_RUNS || "[]") }));
125+ else if (endpoint.endsWith("/dispatches") && process.env.DISPATCH_FAIL) process.exit(1);
126+ else if (endpoint.endsWith("/ref/heads/main")) console.log(process.env.BASE);
124127else if (endpoint.includes("/matching-refs/")) console.log("refs/heads/bot/catalog-publish");
125128else if (endpoint.includes("/ref/heads/bot/catalog-publish")) console.log("a".repeat(40));
126129else if (endpoint.includes("/commits/")) console.log("b".repeat(40));
@@ -155,6 +158,7 @@ catch (error) {
155158 GITHUB_REPOSITORY : "test/catalog" ,
156159 GITHUB_RUN_ID : "123" ,
157160 GITHUB_RUN_ATTEMPT : "1" ,
161+ ...apiEnv ,
158162 } ,
159163 stdio : [ "pipe" , "pipe" , "pipe" ] ,
160164 } ,
@@ -213,3 +217,34 @@ test("publication refuses symlinks instead of reading outside the generated arti
213217 symlinkSync ( unrelated , artifact ) ;
214218 assert . throws ( ( ) => catalogChanges ( fixture . root , "HEAD" ) , / E L O O P | s y m b o l i c l i n k / ) ;
215219} ) ;
220+
221+ test ( "publication dispatches every required workflow after updating its branch and PR" , ( t ) => {
222+ const fixture = publicationFixture ( t , true , { PUBLISH_SUCCESS : "1" } ) ;
223+ fixture . run ( ) ;
224+ const calls = fixture . calls ( ) ;
225+ const dispatches = calls . filter ( ( call ) => call . endpoint . endsWith ( "/dispatches" ) ) ;
226+ assert . deepEqual (
227+ dispatches . map ( ( call ) => call . endpoint . split ( "/" ) . at ( - 2 ) ) ,
228+ [ "ci.yml" , "regression.yml" , "windows-render.yml" , "pr-captures.yml" , "codeql.yml" ] ,
229+ ) ;
230+ for ( const call of dispatches ) assert . deepEqual ( call . body , { ref : "bot/catalog-publish" } ) ;
231+ assert . ok (
232+ calls . indexOf ( dispatches [ 0 ] ) >
233+ calls . findIndex ( ( call ) => call . endpoint . endsWith ( "/pulls/42" ) && call . method === "PATCH" ) ,
234+ ) ;
235+ } ) ;
236+
237+ test ( "publication leaves existing successful workflows at the same head alone" , ( t ) => {
238+ const fixture = publicationFixture ( t , true , {
239+ PUBLISH_SUCCESS : "1" ,
240+ WORKFLOW_RUNS : JSON . stringify ( [ { status : "completed" , conclusion : "success" } ] ) ,
241+ } ) ;
242+ fixture . run ( ) ;
243+ assert . equal ( fixture . calls ( ) . filter ( ( call ) => call . endpoint . endsWith ( "/dispatches" ) ) . length , 0 ) ;
244+ } ) ;
245+
246+ test ( "dispatch rejection fails publication and still cleans up the staging branch" , ( t ) => {
247+ const fixture = publicationFixture ( t , true , { PUBLISH_SUCCESS : "1" , DISPATCH_FAIL : "1" } ) ;
248+ assert . throws ( fixture . run ) ;
249+ assert . equal ( fixture . calls ( ) . at ( - 1 ) . method , "DELETE" ) ;
250+ } ) ;
0 commit comments