Skip to content
This repository was archived by the owner on May 15, 2021. It is now read-only.

Commit 0eaafb7

Browse files
chore: make run id as input value
1 parent 4ed8b8b commit 0eaafb7

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ inputs:
99
description: Secret GitHub API token to use for making API requests.
1010
default: ${{ github.token }}
1111
required: true
12+
TARGET_RUN_ID:
13+
description: Target run id
14+
default: ${{ github.run_id }}
15+
required: true
1216
EXCLUDE_MERGED:
1317
description: Whether to exclude merge push.
1418
required: false

src/process.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import {Context} from '@actions/github/lib/context';
22
import {Octokit} from '@technote-space/github-action-helper/dist/types';
33
import {Logger} from '@technote-space/github-action-log-helper';
44
import {setOutput} from '@actions/core';
5-
import {getRunId, isExcludeContext, getFilteredRun} from './utils/misc';
65
import {cancelWorkflowRun, getWorkflowId, getWorkflowRun, getWorkflowRunCreatedAt, getWorkflowRunNumber, getWorkflowRuns} from './utils/workflow';
6+
import {getTargetRunId, isExcludeContext, getFilteredRun} from './utils/misc';
77

88
export const execute = async(logger: Logger, octokit: Octokit, context: Context): Promise<void> => {
99
if (isExcludeContext(context)) {
@@ -12,10 +12,10 @@ export const execute = async(logger: Logger, octokit: Octokit, context: Context)
1212
return;
1313
}
1414

15-
const runId = getRunId();
15+
const runId = getTargetRunId(context);
1616
logger.info('run id: %d', runId);
1717

18-
const run = await getWorkflowRun(octokit, context);
18+
const run = await getWorkflowRun(runId, octokit, context);
1919
logger.startProcess('run:');
2020
console.log(getFilteredRun(run));
2121
logger.endProcess();

src/utils/misc.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const isExcludeContext = (context: Context): boolean =>
1818
);
1919
export const isNotExcludeRun = (run: ActionsListWorkflowRunsResponseData): boolean => !isExcludeMerged() || !getMergeMessagePrefix().test(run.head_commit.message);
2020

21-
export const getRunId = (): number => Number(process.env.GITHUB_RUN_ID);
21+
export const getTargetRunId = (context: Context): number => /^\d+$/.test(getInput('TARGET_RUN_ID')) ? Number(getInput('TARGET_RUN_ID')) : context.runId;
2222

2323
export const getTargetBranch = async(octokit: Octokit, context: Context): Promise<string | undefined> => {
2424
if (context.payload.pull_request) {

src/utils/workflow.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import {getTargetBranch, isNotExcludeRun} from './misc';
1010
type ActionsGetWorkflowRunResponseData = components['schemas']['workflow-run'];
1111
type ActionsListWorkflowRunsResponseData = components['schemas']['workflow-run'];
1212

13-
export const getWorkflowRun = async(octokit: Octokit, context: Context): Promise<ActionsGetWorkflowRunResponseData> => {
13+
export const getWorkflowRun = async(runId: number, octokit: Octokit, context: Context): Promise<ActionsGetWorkflowRunResponseData> => {
1414
return (await octokit.actions.getWorkflowRun({
1515
owner: context.repo.owner,
1616
repo: context.repo.repo,
17-
'run_id': Number(process.env.GITHUB_RUN_ID),
17+
'run_id': runId,
1818
})).data;
1919
};
2020

0 commit comments

Comments
 (0)