@samitouri / QOS-React-2 / commits / 030dae2f4c

[DiffTrain] Fix null artifactsUrl and add more logging (#25768)

Log more info on the status of the process_artifacts_combined job to help with debugging, and exit with exitcode 1 if anything goes wrong Test plan: Ran the workflow [successfully](https://github.com/facebook/react/actions/runs/3595185062)

lauren committed Dec 1, 2022 at 11:08 UTC 030dae2f4c22a86258b4dace3c9ab6b8b44a0d33
1 file changed +42 -22
.github/workflows/commit_artifacts.yml
+42 -22
@@ -48,20 +48,36 @@ jobs:
48 ref: context.sha
49 });
50 for (const status of res.data) {
51 - if (
52 - status.context === 'ci/circleci: process_artifacts_combined' &&
53 - status.state === 'success'
54 - ) {
55 - // The status does not include a build ID, but we can extract it
56 - // from the URL. I couldn't find a better way to do this.
57 - const ciBuildId = /\/facebook\/react\/([0-9]+)/.exec(
58 - status.target_url,
59 - )[1];
60 - console.log(`CircleCI build id found: ${ciBuildId}`);
61 - if (Number.parseInt(ciBuildId, 10) + '' === ciBuildId) {
62 - artifactsUrl =
63 - `https://circleci.com/api/v1.1/project/github/facebook/react/${ciBuildId}/artifacts`;
64 - break spinloop;
51 + if (/process_artifacts_combined/.test(status.context)) {
52 + switch (status.state) {
53 + case 'pending': {
54 + console.log(`${status.context} is still pending`);
55 + break;
56 + }
57 + case 'failure':
58 + case 'error': {
59 + throw new Error(`${status.context} has failed or errored`);
60 + }
61 + case 'success': {
62 + // The status does not include a build ID, but we can extract it
63 + // from the URL. I couldn't find a better way to do this.
64 + const ciBuildId = /\/facebook\/react\/([0-9]+)/.exec(
65 + status.target_url,
66 + )[1];
67 + console.log(`CircleCI build id found: ${ciBuildId}`);
68 + if (Number.parseInt(ciBuildId, 10) + '' === ciBuildId) {
69 + artifactsUrl =
70 + `https://circleci.com/api/v1.1/project/github/facebook/react/${ciBuildId}/artifacts`;
71 + break spinloop;
72 + } else {
73 + throw new Error(`${ciBuildId} isn't a number`);
74 + }
75 + break;
76 + }
77 + default: {
78 + throw new Error(`Unhandled status state: ${status.state}`);
79 + break;
80 + }
81 }
82 }
83 }
@@ -69,15 +85,19 @@ jobs:
85 console.log("Sleeping for 60s...");
86 await sleep(60_000);
87 }
72 - const res = await fetch(artifactsUrl);
73 - const data = await res.json();
74 - for (const artifact of data) {
75 - if (artifact.path === 'build.tgz') {
76 - console.log(`Downloading and unzipping ${artifact.url}`);
77 - await execHelper(
78 - `curl -L ${artifact.url} | tar -xvz`
79 - );
88 + if (artifactsUrl != null) {
89 + const res = await fetch(artifactsUrl);
90 + const data = await res.json();
91 + for (const artifact of data) {
92 + if (artifact.path === 'build.tgz') {
93 + console.log(`Downloading and unzipping ${artifact.url}`);
94 + await execHelper(
95 + `curl -L ${artifact.url} | tar -xvz`
96 + );
97 + }
98 }
99 + } else {
100 + process.exitCode = 1;
101 }
102 - name: Move relevant files into compiled
103 run: |