@@ -87,11 +87,51 @@ async function getArtifact(workflowRunId, artifactName) {
8787 return artifact ;
8888}
8989
90+ async function processArtifact ( artifact , releaseChannel ) {
91+ // Download and extract artifact
92+ const cwd = join ( __dirname , '..' , '..' , '..' ) ;
93+ await exec ( `rm -rf ./build` , { cwd} ) ;
94+ await exec (
95+ `curl -L ${ GITHUB_HEADERS } ${ artifact . archive_download_url } \
96+ > a.zip && unzip a.zip -d . && rm a.zip build2.tgz && tar -xvzf build.tgz && rm build.tgz` ,
97+ {
98+ cwd,
99+ }
100+ ) ;
101+
102+ // Copy to staging directory
103+ // TODO: Consider staging the release in a different directory from the CI
104+ // build artifacts: `./build/node_modules` -> `./staged-releases`
105+ if ( ! existsSync ( join ( cwd , 'build' ) ) ) {
106+ await exec ( `mkdir ./build` , { cwd} ) ;
107+ } else {
108+ await exec ( `rm -rf ./build/node_modules` , { cwd} ) ;
109+ }
110+ let sourceDir ;
111+ // TODO: Rename release channel to `next`
112+ if ( releaseChannel === 'stable' ) {
113+ sourceDir = 'oss-stable' ;
114+ } else if ( releaseChannel === 'experimental' ) {
115+ sourceDir = 'oss-experimental' ;
116+ } else if ( releaseChannel === 'rc' ) {
117+ sourceDir = 'oss-stable-rc' ;
118+ } else if ( releaseChannel === 'latest' ) {
119+ sourceDir = 'oss-stable-semver' ;
120+ } else {
121+ console . error ( 'Internal error: Invalid release channel: ' + releaseChannel ) ;
122+ process . exit ( releaseChannel ) ;
123+ }
124+ await exec ( `cp -r ./build/${ sourceDir } ./build/node_modules` , {
125+ cwd,
126+ } ) ;
127+ }
128+
90129async function downloadArtifactsFromGitHub ( commit , releaseChannel ) {
91- const workflowRun = await getWorkflowRun ( commit ) ;
130+ let workflowRun ;
92131 let retries = 0 ;
93132 // wait up to 10 mins for build to finish: 10 * 60 * 1_000) / 30_000 = 20
94133 while ( retries < 20 ) {
134+ workflowRun = await getWorkflowRun ( commit ) ;
95135 if ( typeof workflowRun . status === 'string' ) {
96136 switch ( workflowRun . status ) {
97137 case 'queued' :
@@ -108,49 +148,11 @@ async function downloadArtifactsFromGitHub(commit, releaseChannel) {
108148 workflowRun . id ,
109149 'artifacts_combined'
110150 ) ;
111-
112- // Download and extract artifact
113- const cwd = join ( __dirname , '..' , '..' , '..' ) ;
114- await exec ( `rm -rf ./build` , { cwd} ) ;
115- await exec (
116- `curl -L ${ GITHUB_HEADERS } ${ artifact . archive_download_url } \
117- > a.zip && unzip a.zip -d . && rm a.zip build2.tgz && tar -xvzf build.tgz && rm build.tgz` ,
118- {
119- cwd,
120- }
121- ) ;
122-
123- // Copy to staging directory
124- // TODO: Consider staging the release in a different directory from the CI
125- // build artifacts: `./build/node_modules` -> `./staged-releases`
126- if ( ! existsSync ( join ( cwd , 'build' ) ) ) {
127- await exec ( `mkdir ./build` , { cwd} ) ;
128- } else {
129- await exec ( `rm -rf ./build/node_modules` , { cwd} ) ;
130- }
131- let sourceDir ;
132- // TODO: Rename release channel to `next`
133- if ( releaseChannel === 'stable' ) {
134- sourceDir = 'oss-stable' ;
135- } else if ( releaseChannel === 'experimental' ) {
136- sourceDir = 'oss-experimental' ;
137- } else if ( releaseChannel === 'rc' ) {
138- sourceDir = 'oss-stable-rc' ;
139- } else if ( releaseChannel === 'latest' ) {
140- sourceDir = 'oss-stable-semver' ;
141- } else {
142- console . error (
143- 'Internal error: Invalid release channel: ' + releaseChannel
144- ) ;
145- process . exit ( releaseChannel ) ;
146- }
147- await exec ( `cp -r ./build/${ sourceDir } ./build/node_modules` , {
148- cwd,
149- } ) ;
151+ await processArtifact ( artifact , releaseChannel ) ;
150152 return ;
151153 } else {
152154 console . log (
153- theme `{error Could not download build for ${ commit } from GitHub as its conclusion was: ${ workflowRun . conclusion } }`
155+ theme `{error Could not download build as its conclusion was: ${ workflowRun . conclusion } }`
154156 ) ;
155157 process . exit ( 1 ) ;
156158 }
@@ -163,11 +165,18 @@ async function downloadArtifactsFromGitHub(commit, releaseChannel) {
163165 process . exit ( 1 ) ;
164166 }
165167 }
168+ } else {
169+ retries ++ ;
170+ console . log (
171+ theme `{error Expected workflow run status to be a string, got: ${ workflowRun . status } . Retrying...}`
172+ ) ;
166173 }
167174 }
168175
169176 console . log (
170- theme `{error Could not download build for ${ commit } from GitHub as it timed out}`
177+ theme `{error Could not download build from GitHub. Last workflow run: }
178+
179+ ${ workflowRun != null ? JSON . stringify ( workflowRun , null , '\t' ) : workflowRun } `
171180 ) ;
172181 process . exit ( 1 ) ;
173182}
0 commit comments