3
3
const { join} = require ( 'path' ) ;
4
4
const theme = require ( '../theme' ) ;
5
5
const { exec} = require ( 'child-process-promise' ) ;
6
- const { existsSync} = require ( 'fs' ) ;
6
+ const { existsSync, readFileSync } = require ( 'fs' ) ;
7
7
const { logPromise} = require ( '../utils' ) ;
8
8
9
9
if ( process . env . GH_TOKEN == null ) {
@@ -80,7 +80,7 @@ async function getArtifact(workflowRunId, artifactName) {
80
80
return artifact ;
81
81
}
82
82
83
- async function processArtifact ( artifact , releaseChannel ) {
83
+ async function processArtifact ( artifact , commit , releaseChannel ) {
84
84
// Download and extract artifact
85
85
const cwd = join ( __dirname , '..' , '..' , '..' ) ;
86
86
await exec ( `rm -rf ./build` , { cwd} ) ;
@@ -117,6 +117,17 @@ async function processArtifact(artifact, releaseChannel) {
117
117
await exec ( `cp -r ./build/${ sourceDir } ./build/node_modules` , {
118
118
cwd,
119
119
} ) ;
120
+
121
+ // Validate artifact
122
+ const buildSha = readFileSync ( './build/COMMIT_SHA' , 'utf8' ) . replace (
123
+ / [ \u0000 - \u001F \u007F - \u009F ] / g,
124
+ ''
125
+ ) ;
126
+ if ( buildSha !== commit ) {
127
+ throw new Error (
128
+ `Requested commit sha does not match downloaded artifact. Expected: ${ commit } , got: ${ buildSha } `
129
+ ) ;
130
+ }
120
131
}
121
132
122
133
async function downloadArtifactsFromGitHub ( commit , releaseChannel ) {
@@ -141,7 +152,7 @@ async function downloadArtifactsFromGitHub(commit, releaseChannel) {
141
152
workflowRun . id ,
142
153
'artifacts_combined'
143
154
) ;
144
- await processArtifact ( artifact , releaseChannel ) ;
155
+ await processArtifact ( artifact , commit , releaseChannel ) ;
145
156
return ;
146
157
} else {
147
158
console . log (
0 commit comments