@@ -19,6 +19,12 @@ const writeJson = async (repoRoot, relativePath, value) =>
1919const getToday = ( ) => new Date ( ) . toISOString ( ) . slice ( 0 , 10 ) ;
2020
2121const isExternalEvidenceLink = ( value ) => / ^ h t t p s ? : \/ \/ / . test ( value ) ;
22+ const githubActionsRunPattern =
23+ / ^ h t t p s : \/ \/ g i t h u b \. c o m \/ [ ^ / ] + \/ [ ^ / ] + \/ a c t i o n s \/ r u n s \/ ( \d + ) (?: \/ .* ) ? $ / ;
24+ const gitCommitPattern = / ^ [ 0 - 9 a - f ] { 6 , 40 } $ / i;
25+
26+ const getGithubActionsRunId = ( value ) =>
27+ value . match ( githubActionsRunPattern ) ?. [ 1 ] ;
2228
2329const pathExists = async ( repoRoot , relativePath ) => {
2430 try {
@@ -82,12 +88,24 @@ const assertRequired = (options) => {
8288 }
8389} ;
8490
91+ const assertWorkflowReference = ( { commit, runUrl } ) => {
92+ if ( ! gitCommitPattern . test ( commit ) ) {
93+ throw new Error ( "--commit must be a short or full git commit SHA" ) ;
94+ }
95+
96+ if ( ! getGithubActionsRunId ( runUrl ) ) {
97+ throw new Error ( "--run-url must be a GitHub Actions run URL" ) ;
98+ }
99+ } ;
100+
85101const assertArtifactEvidenceExists = async ( {
86102 androidArtifact,
87103 iosArtifact,
88- repoRoot
104+ repoRoot,
105+ runUrl
89106} ) => {
90107 const missing = [ ] ;
108+ const runId = getGithubActionsRunId ( runUrl ) ;
91109
92110 for ( const artifact of [ iosArtifact , androidArtifact ] ) {
93111 if (
@@ -105,6 +123,26 @@ const assertArtifactEvidenceExists = async ({
105123 ) } `
106124 ) ;
107125 }
126+
127+ const mismatchedArtifacts = [ iosArtifact , androidArtifact ] . filter (
128+ ( artifact ) => {
129+ if ( ! isExternalEvidenceLink ( artifact ) ) {
130+ return false ;
131+ }
132+
133+ const artifactRunId = getGithubActionsRunId ( artifact ) ;
134+
135+ return artifactRunId && artifactRunId !== runId ;
136+ }
137+ ) ;
138+
139+ if ( mismatchedArtifacts . length > 0 ) {
140+ throw new Error (
141+ `GitHub artifact URLs must belong to ${ runUrl } : ${ mismatchedArtifacts . join (
142+ ", "
143+ ) } `
144+ ) ;
145+ }
108146} ;
109147
110148export const listNativeWorkflowEvidence = async ( {
@@ -136,10 +174,12 @@ export const recordNativeWorkflowEvidence = async ({
136174 runUrl
137175 } ;
138176 assertRequired ( options ) ;
177+ assertWorkflowReference ( { commit, runUrl } ) ;
139178 await assertArtifactEvidenceExists ( {
140179 androidArtifact,
141180 iosArtifact,
142- repoRoot
181+ repoRoot,
182+ runUrl
143183 } ) ;
144184
145185 const manifest = await readJson ( repoRoot , manifestPath ) ;
0 commit comments