Skip to content

Commit

Permalink
add additional parameter for controlling fallback sha
Browse files Browse the repository at this point in the history
  • Loading branch information
gabbersepp committed Sep 23, 2024
1 parent 2a8ccfe commit 072976a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ If your workflow runs are expected to contain no-longer existing commit SHAs (e.
| `workflow` | Workflow name to look for. | "" |
| `job` | Job name to look for. | "" |
| `verify` | Verify workflow commit SHA against list of SHAs in repository | `false` |
| `fallbackToEarliestSha` | If SHA of last successful commit can not be determined, use earliest (true) or triggering sha (false) | `false` |


### Action outputs
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ inputs:
description: 'Verify SHA of workflow run commit against list of commit SHAs in repository'
required: false
default: 'false'
fallbackToEarliestSha:
description: 'If SHA of last successful commit can not be determined, use earliest (true) or triggering sha (false)'
required: false
default: 'false'
outputs:
sha:
description: 'Sha of the workflow-run matching the requirements.'
Expand Down
8 changes: 5 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28976,7 +28976,8 @@ function run() {
branch: core.getInput("branch"),
workflow: core.getInput("workflow"),
job: core.getInput("job"),
verify: core.getInput("verify") === "true" ? true : false
verify: core.getInput("verify") === "true" ? true : false,
fallbackToEarliestSha: core.getInput("fallbackToEarliestSha") === "true" ? true : false
};
const octokit = github.getOctokit(inputs.token);
const repository = process.env.GITHUB_REPOSITORY;
Expand Down Expand Up @@ -29039,8 +29040,9 @@ function run() {
core.info(`No previous runs found for branch ${inputs.branch}.`);
}
if (!sha) {
core.warning(`Unable to determine SHA of last successful commit (possibly outside the window of ${runs.length} runs). Using earliest SHA available and run id for current commit.`);
sha = lastSha;
core.warning(`Unable to determine SHA of last successful commit (possibly outside the window of ${runs.length} runs).
Using ${inputs.fallbackToEarliestSha ? "earliest available" : "triggering"} SHA and run id for current commit.`);
sha = inputs.fallbackToEarliestSha ? lastSha : triggeringSha;
runId = parseInt(process.env.GITHUB_RUN_ID);
}
core.setOutput('sha', sha);
Expand Down
8 changes: 5 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ async function run(): Promise<void> {
branch: core.getInput("branch"),
workflow: core.getInput("workflow"),
job: core.getInput("job"),
verify: core.getInput("verify") === "true" ? true : false
verify: core.getInput("verify") === "true" ? true : false,
fallbackToEarliestSha: core.getInput("fallbackToEarliestSha") === "true" ? true : false
};

const octokit = github.getOctokit(inputs.token);
Expand Down Expand Up @@ -113,8 +114,9 @@ async function run(): Promise<void> {
}

if (!sha) {
core.warning(`Unable to determine SHA of last successful commit (possibly outside the window of ${runs.length} runs). Using earliest SHA available and run id for current commit.`);
sha = lastSha;
core.warning(`Unable to determine SHA of last successful commit (possibly outside the window of ${runs.length} runs).
Using ${inputs.fallbackToEarliestSha ? "earliest available" : "triggering" } SHA and run id for current commit.`);
sha = inputs.fallbackToEarliestSha ? lastSha : triggeringSha;
runId = parseInt(process.env.GITHUB_RUN_ID as string);
}

Expand Down

0 comments on commit 072976a

Please sign in to comment.