Skip to content

Commit

Permalink
feat: ability to change last successful event (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigomata authored Dec 17, 2021
1 parent f17afe2 commit 11fd0d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ inputs:
default: "false"
workflow-id:
description: "The ID of the workflow to track or name of the file name. E.g. ci.yml. Defaults to current workflow"
last-successful-event:
description: "The type of event to check for the last successful commit corresponding to that workflow-id, E.g. push, pull-request, release etc"
default: "push"

outputs:
base:
Expand All @@ -28,7 +31,7 @@ runs:
- name: Set base and head SHAs used for nx affected
id: setSHAs
shell: bash
run: node ${{ github.action_path }}/dist/index.js ${{ github.token }} ${{ inputs.main-branch-name }} ${{ inputs.error-on-no-successful-workflow }} ${{ inputs.workflow-id }}
run: node ${{ github.action_path }}/dist/index.js ${{ github.token }} ${{ inputs.main-branch-name }} ${{ inputs.error-on-no-successful-workflow }} ${{ inputs.workflow-id }} ${{ inputs.last-successful-event }}

- name: Log base and head SHAs used for nx affected
shell: bash
Expand Down
7 changes: 4 additions & 3 deletions find-successful-workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ process.env.GITHUB_TOKEN = process.argv[2];
const mainBranchName = process.argv[3];
const errorOnNoSuccessfulWorkflow = process.argv[4];
const workflowId = process.argv[5];
const lastSuccessfulEvent = process.argv[6];

let BASE_SHA;
(async () => {
Expand All @@ -17,7 +18,7 @@ let BASE_SHA;
BASE_SHA = execSync(`git merge-base origin/${mainBranchName} HEAD`, { encoding: 'utf-8' });
} else {
try {
BASE_SHA = await findSuccessfulCommit(workflowId, runId, owner, repo, mainBranchName);
BASE_SHA = await findSuccessfulCommit(workflowId, runId, owner, repo, mainBranchName, lastSuccessfulEvent);
} catch (e) {
core.setFailed(e.message);
return;
Expand Down Expand Up @@ -65,7 +66,7 @@ function reportFailure(branchName) {
* @param {string} branch
* @returns
*/
async function findSuccessfulCommit(workflow_id, run_id, owner, repo, branch) {
async function findSuccessfulCommit(workflow_id, run_id, owner, repo, branch, lastSuccessfulEvent) {
const octokit = new Octokit();
if (!workflow_id) {
workflow_id = await octokit.request(`GET /repos/${owner}/${repo}/actions/runs/${run_id}`, {
Expand All @@ -81,7 +82,7 @@ async function findSuccessfulCommit(workflow_id, run_id, owner, repo, branch) {
repo,
branch,
workflow_id,
event: 'push',
event: lastSuccessfulEvent,
status: 'success'
}).then(({ data: { workflow_runs } }) => workflow_runs.map(run => run.head_sha));

Expand Down

0 comments on commit 11fd0d2

Please sign in to comment.