Skip to content

Commit 0c1d731

Browse files
add more try catch
1 parent f841458 commit 0c1d731

File tree

4 files changed

+50
-36
lines changed

4 files changed

+50
-36
lines changed

.github/workflows/integration-test-workflow.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,3 @@ jobs:
6666
HEAD_SHA=$(echo $(git rev-parse HEAD))
6767
node -e "if(process.env.NX_BASE == '${BASE_SHA}') console.log('Base set correctly'); else { throw new Error('Base not set correctly!');}"
6868
node -e "if(process.env.NX_HEAD == '${HEAD_SHA}') console.log('Head set correctly'); else { throw new Error('Head not set correctly!');}"
69-
70-
- name: Verify workflow-id
71-
if: ${{ inputs.workflow-id != '' }}
72-
run: |
73-
echo "NX_BASE: $NX_BASE"
74-
echo "NX_HEAD: $NX_HEAD"
75-
echo "NX_WORKFLOW_ID: $NX_WORKFLOW_ID"

.github/workflows/test-integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ jobs:
2424
working-directory: integration-test
2525
main-branch-name: ${{ github.event_name == 'pull_request' && github.base_ref || github.ref_name }}
2626
runs-on: ${{ matrix.runs-on }}
27-
workflow-id: ${{ github.workflow }}
27+
workflow-id: test-integration.yml

dist/index.js

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65004,21 +65004,26 @@ function findSuccessfulCommit(workflow_id, run_id, owner, repo, branch, lastSucc
6500465004
}
6500565005
}
6500665006
// fetch all workflow runs on a given repo/branch/workflow with push and success
65007-
const shas = yield octokit
65008-
.request(`GET /repos/${owner}/${repo}/actions/workflows/${workflow_id}/runs`, {
65009-
owner,
65010-
repo,
65011-
// on some workflow runs we do not have branch property
65012-
branch: lastSuccessfulEvent === 'push' ||
65013-
lastSuccessfulEvent === 'workflow_dispatch'
65014-
? branch
65015-
: undefined,
65016-
workflow_id,
65017-
event: lastSuccessfulEvent,
65018-
status: 'success',
65019-
})
65020-
.then(({ data: { workflow_runs } }) => workflow_runs.map((run) => run.head_sha));
65021-
return yield findExistingCommit(octokit, branch, shas);
65007+
try {
65008+
const response = yield octokit.request(`GET /repos/${owner}/${repo}/actions/workflows/${workflow_id}/runs`, {
65009+
owner,
65010+
repo,
65011+
// on some workflow runs we do not have branch property
65012+
branch: lastSuccessfulEvent === 'push' ||
65013+
lastSuccessfulEvent === 'workflow_dispatch'
65014+
? branch
65015+
: undefined,
65016+
workflow_id,
65017+
event: lastSuccessfulEvent,
65018+
status: 'success',
65019+
});
65020+
const shas = response.data.workflow_runs.map((run) => run.head_sha);
65021+
return yield findExistingCommit(octokit, branch, shas);
65022+
}
65023+
catch (e) {
65024+
console.error('Error fetching workflow runs', e);
65025+
throw e;
65026+
}
6502265027
});
6502365028
}
6502465029
function findMergeBaseRef() {
@@ -65046,8 +65051,14 @@ function findMergeQueueBranch() {
6504665051
process.stdout.write('\n');
6504765052
process.stdout.write(`Found PR #${pull_number} from merge queue branch\n`);
6504865053
const octokit = new ProxifiedClient();
65049-
const result = yield octokit.request(`GET /repos/${owner}/${repo}/pulls/${pull_number}`, { owner, repo, pull_number: +pull_number });
65050-
return result.data.head.ref;
65054+
try {
65055+
const result = yield octokit.request(`GET /repos/${owner}/${repo}/pulls/${pull_number}`, { owner, repo, pull_number: +pull_number });
65056+
return result.data.head.ref;
65057+
}
65058+
catch (e) {
65059+
console.error('Error fetching merge queue branch', e);
65060+
throw e;
65061+
}
6505165062
});
6505265063
}
6505365064
/**

find-successful-workflow.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ async function findSuccessfulCommit(
187187
}
188188
}
189189
// fetch all workflow runs on a given repo/branch/workflow with push and success
190-
const shas = await octokit
191-
.request(
190+
try {
191+
const response = await octokit.request(
192192
`GET /repos/${owner}/${repo}/actions/workflows/${workflow_id}/runs`,
193193
{
194194
owner,
@@ -203,12 +203,16 @@ async function findSuccessfulCommit(
203203
event: lastSuccessfulEvent,
204204
status: 'success',
205205
},
206-
)
207-
.then(({ data: { workflow_runs } }) =>
208-
workflow_runs.map((run: { head_sha: any }) => run.head_sha),
206+
);
207+
const shas = response.data.workflow_runs.map(
208+
(run: { head_sha: any }) => run.head_sha,
209209
);
210210

211-
return await findExistingCommit(octokit, branch, shas);
211+
return await findExistingCommit(octokit, branch, shas);
212+
} catch (e) {
213+
console.error('Error fetching workflow runs', e);
214+
throw e;
215+
}
212216
}
213217

214218
async function findMergeBaseRef(): Promise<string> {
@@ -236,11 +240,17 @@ async function findMergeQueueBranch(): Promise<string> {
236240
process.stdout.write('\n');
237241
process.stdout.write(`Found PR #${pull_number} from merge queue branch\n`);
238242
const octokit = new ProxifiedClient();
239-
const result = await octokit.request(
240-
`GET /repos/${owner}/${repo}/pulls/${pull_number}`,
241-
{ owner, repo, pull_number: +pull_number },
242-
);
243-
return result.data.head.ref;
243+
244+
try {
245+
const result = await octokit.request(
246+
`GET /repos/${owner}/${repo}/pulls/${pull_number}`,
247+
{ owner, repo, pull_number: +pull_number },
248+
);
249+
return result.data.head.ref;
250+
} catch (e) {
251+
console.error('Error fetching merge queue branch', e);
252+
throw e;
253+
}
244254
}
245255

246256
/**

0 commit comments

Comments
 (0)