Skip to content

Commit 40c027a

Browse files
fix: normalize workflow_id env and use try/catch
1 parent e2e6dc8 commit 40c027a

File tree

3 files changed

+36
-24
lines changed

3 files changed

+36
-24
lines changed

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ runs:
4747
error_on_no_successful_workflow: ${{ inputs.error-on-no-successful-workflow }}
4848
last_successful_event: ${{ inputs.last-successful-event }}
4949
working_directory: ${{ inputs.working-directory }}
50-
working_id: ${{ inputs.workflow-id }}
50+
workflow_id: ${{ inputs.workflow-id }}
5151
fallback_sha: ${{ inputs.fallback-sha }}
52-
run: node "$GITHUB_ACTION_PATH/dist/index.js" "$gh_token" "$main_branch_name" "$error_on_no_successful_workflow" "$last_successful_event" "$working_directory" "$working_id" "$fallback_sha"
52+
run: node "$GITHUB_ACTION_PATH/dist/index.js" "$gh_token" "$main_branch_name" "$error_on_no_successful_workflow" "$last_successful_event" "$working_directory" "$workflow_id" "$fallback_sha"
5353

5454
- name: Log base and head SHAs used for nx affected
5555
shell: bash

dist/index.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64987,16 +64987,21 @@ function findSuccessfulCommit(workflow_id, run_id, owner, repo, branch, lastSucc
6498764987
return __awaiter(this, void 0, void 0, function* () {
6498864988
const octokit = new ProxifiedClient();
6498964989
if (!workflow_id) {
64990-
workflow_id = yield octokit
64991-
.request(`GET /repos/${owner}/${repo}/actions/runs/${run_id}`, {
64992-
owner,
64993-
repo,
64994-
branch,
64995-
run_id,
64996-
})
64997-
.then(({ data: { workflow_id } }) => workflow_id);
64998-
process.stdout.write('\n');
64999-
process.stdout.write(`Workflow Id not provided. Using workflow '${workflow_id}'\n`);
64990+
try {
64991+
const response = yield octokit.request(`GET /repos/${owner}/${repo}/actions/runs/${run_id}`, {
64992+
owner,
64993+
repo,
64994+
branch,
64995+
run_id,
64996+
});
64997+
workflow_id = response.data.workflow_id;
64998+
process.stdout.write('\n');
64999+
process.stdout.write(`Workflow Id not provided. Using workflow '${workflow_id}'\n`);
65000+
}
65001+
catch (e) {
65002+
console.error('Error fetching workflow id', e);
65003+
throw e;
65004+
}
6500065005
}
6500165006
// fetch all workflow runs on a given repo/branch/workflow with push and success
6500265007
const shas = yield octokit

find-successful-workflow.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,25 @@ async function findSuccessfulCommit(
166166
): Promise<string | undefined> {
167167
const octokit = new ProxifiedClient();
168168
if (!workflow_id) {
169-
workflow_id = await octokit
170-
.request(`GET /repos/${owner}/${repo}/actions/runs/${run_id}`, {
171-
owner,
172-
repo,
173-
branch,
174-
run_id,
175-
})
176-
.then(({ data: { workflow_id } }) => workflow_id);
177-
process.stdout.write('\n');
178-
process.stdout.write(
179-
`Workflow Id not provided. Using workflow '${workflow_id}'\n`,
180-
);
169+
try {
170+
const response = await octokit.request(
171+
`GET /repos/${owner}/${repo}/actions/runs/${run_id}`,
172+
{
173+
owner,
174+
repo,
175+
branch,
176+
run_id,
177+
},
178+
);
179+
workflow_id = response.data.workflow_id;
180+
process.stdout.write('\n');
181+
process.stdout.write(
182+
`Workflow Id not provided. Using workflow '${workflow_id}'\n`,
183+
);
184+
} catch (e) {
185+
console.error('Error fetching workflow id', e);
186+
throw e;
187+
}
181188
}
182189
// fetch all workflow runs on a given repo/branch/workflow with push and success
183190
const shas = await octokit

0 commit comments

Comments
 (0)