## Outputs
-| Output | No `sourceRunId` specified | The `sourceRunId` set to `${{ github.event.workflow_run.id }}` |
-|---------------------|-----------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------|
-| `sourceHeadRepo` | Current repository. Format: `owner/repo` | Repository of the run that triggered this `workflow_run`. Format: `owner/repo` |
-| `sourceHeadBranch` | Current branch. | Branch of the run that triggered this `workflow_run`. Might be forked repo, if it is a pull_request. |
-| `sourceHeadSha` | Current commit SHA: `{{ github.sha }}` | Commit sha of the run that triggered this `workflow_run`. |
-| `mergeCommitSha` | Merge commit SHA if PR-triggered event. | Merge commit SHA if PR-triggered event. |
-| `targetCommitSha` | Target commit SHA (merge if present, otherwise source). | Target commit SHA (merge if present, otherwise source). |
-| `pullRequestNumber` | Number of the associated Pull Request (if PR triggered) | Number of the associated Pull Request (if PR triggered) |
-| `pullRequestLabels` | Stringified JSON array of Labels of the associated Pull Request (if PR triggered) | Stringified JSON array of Labels of the associated Pull Request (if PR triggered) |
-| `sourceEvent` | Current event: ``${{ github.event }}`` | Event of the run that triggered this `workflow_run` |
+| Output | No `sourceRunId` specified | The `sourceRunId` set to `${{ github.event.workflow_run.id }}` |
+|----------------------|-------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------|
+| `sourceHeadRepo` | Current repository. Format: `owner/repo` | Repository of the run that triggered this `workflow_run`. Format: `owner/repo` |
+| `sourceHeadBranch` | Current branch. | Branch of the run that triggered this `workflow_run`. Might be forked repo, if it is a pull_request. |
+| `sourceHeadSha` | Current commit SHA: `{{ github.sha }}` | Commit sha of the run that triggered this `workflow_run`. |
+| `mergeCommitSha` | Merge commit SHA if PR-triggered event. | Merge commit SHA if PR-triggered event. |
+| `targetCommitSha` | Target commit SHA (merge if present, otherwise source). | Target commit SHA (merge if present, otherwise source). |
+| `pullRequestNumber` | Number of the associated Pull Request (if PR triggered) | Number of the associated Pull Request (if PR triggered) |
+| `pullRequestLabels` | Stringified JSON array of Labels of the associated Pull Request (if PR triggered) | Stringified JSON array of Labels of the associated Pull Request (if PR triggered) |
+| `targetBranch` | Target branch of the pull request or target branch for push | Target branch of the pull request or target branch for push |
+| `sourceEvent` | Current event: ``${{ github.event }}`` | Event of the run that triggered this `workflow_run` |
# Examples
targetCommitSha: ${{ steps.workflow-run-info.outputs.targetCommitSha }}
pullRequestNumber: ${{ steps.workflow-run-info.outputs.pullRequestNumber }}
pullRequestLabels: ${{ steps.workflow-run-info.outputs.pullRequestLabels }}
+ targetBranch: ${{ steps.source-run-info.outputs.targetBranch }}
sourceEvent: ${{ steps.workflow-run-info.outputs.sourceEvent }}
steps:
- name: "Get information about the current run"
targetCommitSha: ${{ steps.source-run-info.outputs.targetCommitSha }}
pullRequestNumber: ${{ steps.source-run-info.outputs.pullRequestNumber }}
pullRequestLabels: ${{ steps.source-run-info.outputs.pullRequestLabels }}
+ targetBranch: ${{ steps.source-run-info.outputs.targetBranch }}
sourceEvent: ${{ steps.source-run-info.outputs.sourceEvent }}
-
steps:
- name: "Get information about the origin 'CI' run"
uses: potiuk/get-workflow-origin@v1_1
for (const pullRequest of pullRequests) {
core.info(`\nComparing: ${pullRequest.number} sha: ${pullRequest.head.sha} with expected: ${headSha}.\n`);
if (pullRequest.head.sha === headSha) {
- core.info(`\nFound PR: ${pullRequest.number}\n`);
+ core.info(`\nFound PR: ${pullRequest.number}. ` +
+ `Url: https://api.github.com/repos/${owner}/${repo}/pulls/${pullRequest.number}\n`);
return pullRequest;
}
}
run_id: runId
});
const sourceRun = reply.data;
+ core.debug(JSON.stringify(reply.data));
core.info(`Source workflow: Head repo: ${sourceRun.head_repository.full_name}, ` +
`Head branch: ${sourceRun.head_branch} ` +
`Event: ${sourceRun.event}, Head sha: ${sourceRun.head_sha}, url: ${sourceRun.url}`);
reply.data.event,
reply.data.head_sha,
pullRequest ? pullRequest.merge_commit_sha : '',
+ pullRequest ? pullRequest.base.ref : reply.data.head_branch,
pullRequest
];
});
const eventName = getRequiredEnv('GITHUB_EVENT_NAME');
const sourceRunId = parseInt(core.getInput('sourceRunId')) || selfRunId;
const [owner, repo] = repository.split('/');
- // core.info(`\nPayload: ${JSON.stringify(github.context.payload)}\n`)
+ core.debug(`\nPayload: ${JSON.stringify(github.context.payload)}\n`);
core.info(`\nGetting workflow id for source run id: ${sourceRunId}, owner: ${owner}, repo: ${repo}\n`);
const sourceWorkflowId = yield getWorkflowId(octokit, sourceRunId, owner, repo);
core.info(`Repository: ${repository}, Owner: ${owner}, Repo: ${repo}, ` +
`Event name: ${eventName},` +
`sourceWorkflowId: ${sourceWorkflowId}, sourceRunId: ${sourceRunId}, selfRunId: ${selfRunId}, `);
- const [headRepo, headBranch, sourceEventName, headSha, mergeCommitSha, pullRequest] = yield getOrigin(octokit, sourceRunId, owner, repo);
+ const [headRepo, headBranch, sourceEventName, headSha, mergeCommitSha, targetBranch, pullRequest] = yield getOrigin(octokit, sourceRunId, owner, repo);
verboseOutput('sourceHeadRepo', headRepo);
verboseOutput('sourceHeadBranch', headBranch);
verboseOutput('sourceHeadSha', headSha);
verboseOutput('pullRequestLabels', JSON.stringify(labelNames));
verboseOutput('mergeCommitSha', mergeCommitSha);
verboseOutput('targetCommitSha', pullRequest ? mergeCommitSha : headSha);
+ verboseOutput('targetBranch', targetBranch);
});
}
run()
`\nComparing: ${pullRequest.number} sha: ${pullRequest.head.sha} with expected: ${headSha}.\n`
)
if (pullRequest.head.sha === headSha) {
- core.info(`\nFound PR: ${pullRequest.number}\n`)
+ core.info(
+ `\nFound PR: ${pullRequest.number}. ` +
+ `Url: https://api.github.com/repos/${owner}/${repo}/pulls/${pullRequest.number}\n`
+ )
return pullRequest
}
}
owner: string,
repo: string
): Promise<
- [string, string, string, string, string, rest.PullsListResponseItem | null]
+ [
+ string,
+ string,
+ string,
+ string,
+ string,
+ string,
+ rest.PullsListResponseItem | null
+ ]
> {
const reply = await octokit.actions.getWorkflowRun({
owner,
run_id: runId
})
const sourceRun = reply.data
+ core.debug(JSON.stringify(reply.data))
core.info(
`Source workflow: Head repo: ${sourceRun.head_repository.full_name}, ` +
`Head branch: ${sourceRun.head_branch} ` +
reply.data.event,
reply.data.head_sha,
pullRequest ? pullRequest.merge_commit_sha : '',
+ pullRequest ? pullRequest.base.ref : reply.data.head_branch,
pullRequest
]
}
const sourceRunId = parseInt(core.getInput('sourceRunId')) || selfRunId
const [owner, repo] = repository.split('/')
- // core.info(`\nPayload: ${JSON.stringify(github.context.payload)}\n`)
+ core.debug(`\nPayload: ${JSON.stringify(github.context.payload)}\n`)
core.info(
`\nGetting workflow id for source run id: ${sourceRunId}, owner: ${owner}, repo: ${repo}\n`
sourceEventName,
headSha,
mergeCommitSha,
+ targetBranch,
pullRequest
] = await getOrigin(octokit, sourceRunId, owner, repo)
verboseOutput('pullRequestLabels', JSON.stringify(labelNames))
verboseOutput('mergeCommitSha', mergeCommitSha)
verboseOutput('targetCommitSha', pullRequest ? mergeCommitSha : headSha)
+ verboseOutput('targetBranch', targetBranch)
}
run()