Skip to content

Commit

Permalink
fix: add missing fallback_sha argument
Browse files Browse the repository at this point in the history
  • Loading branch information
joh-klein committed Jun 12, 2024
1 parent bcc7f3a commit d0adc4e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 15 deletions.
3 changes: 2 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ runs:
last_successful_event: ${{ inputs.last-successful-event }}
working_directory: ${{ inputs.working-directory }}
working_id: ${{ inputs.workflow-id }}
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: ${{ inputs.fallback-sha }}
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"

- name: Log base and head SHAs used for nx affected
shell: bash
Expand Down
58 changes: 44 additions & 14 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37852,6 +37852,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __nccwpck_require__(2186);
const github = __nccwpck_require__(5438);
Expand All @@ -37868,6 +37875,7 @@ const lastSuccessfulEvent = process.argv[5];
const workingDirectory = process.argv[6];
const workflowId = process.argv[7];
const fallbackSHA = process.argv[8];
const lastSuccessfulState = process.argv[9];
const defaultWorkingDirectory = ".";
const ProxifiedClient = action_1.Octokit.plugin(proxyPlugin);
let BASE_SHA;
Expand Down Expand Up @@ -37964,6 +37972,7 @@ function proxyPlugin(octokit) {
* Find last successful workflow run on the repo
*/
function findSuccessfulCommit(workflow_id, run_id, owner, repo, branch, lastSuccessfulEvent) {
var _a, e_1, _b, _c;
return __awaiter(this, void 0, void 0, function* () {
const octokit = new ProxifiedClient();
if (!workflow_id) {
Expand All @@ -37978,22 +37987,43 @@ function findSuccessfulCommit(workflow_id, run_id, owner, repo, branch, lastSucc
process.stdout.write("\n");
process.stdout.write(`Workflow Id not provided. Using workflow '${workflow_id}'\n`);
}
// fetch all workflow runs on a given repo/branch/workflow with push and success
const shas = yield octokit
.request(`GET /repos/${owner}/${repo}/actions/workflows/${workflow_id}/runs`, {
// on some workflow runs we do not have branch property
const branchProperty = lastSuccessfulEvent === "push" ||
lastSuccessfulEvent === "workflow_dispatch"
? branch
: undefined;
const workflowStatesConsideredSuccessful = lastSuccessfulState.split(",");
const iterator = octokit.paginate.iterator(`GET /repos/${owner}/${repo}/actions/workflows/${workflow_id}/runs`, {
owner,
repo,
// on some workflow runs we do not have branch property
branch: lastSuccessfulEvent === "push" ||
lastSuccessfulEvent === "workflow_dispatch"
? branch
: undefined,
branch: branchProperty,
workflow_id,
event: lastSuccessfulEvent,
status: "success",
})
.then(({ data: { workflow_runs } }) => workflow_runs.map((run) => run.head_sha));
return yield findExistingCommit(octokit, branch, shas);
per_page: 100,
});
try {
// iterate through each response
for (var _d = true, iterator_1 = __asyncValues(iterator), iterator_1_1; iterator_1_1 = yield iterator_1.next(), _a = iterator_1_1.done, !_a; _d = true) {
_c = iterator_1_1.value;
_d = false;
const { data: workflow_runs } = _c;
const shas = workflow_runs
.filter((run) => workflowStatesConsideredSuccessful.includes(run.status) ||
workflowStatesConsideredSuccessful.includes(run.conclusion))
.map((run) => run.head_sha);
const firstExistingCommit = yield findExistingCommit(octokit, branch, shas);
if (firstExistingCommit) {
return firstExistingCommit;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (!_d && !_a && (_b = iterator_1.return)) yield _b.call(iterator_1);
}
finally { if (e_1) throw e_1.error; }
}
});
}
function findMergeBaseRef() {
Expand Down Expand Up @@ -38047,13 +38077,13 @@ function commitExists(octokit, branchName, commitSha) {
(0, child_process_1.spawnSync)("git", ["cat-file", "-e", commitSha], {
stdio: ["pipe", "pipe", null],
});
// Check the commit exists in general
// Check if the commit exists in general
yield octokit.request("GET /repos/{owner}/{repo}/commits/{commit_sha}", {
owner,
repo,
commit_sha: commitSha,
});
// Check the commit exists on the expected main branch (it will not in the case of a rebased main branch)
// Check if the commit exists on the expected main branch (it will not in the case of a rebased main branch)
const commits = yield octokit.request("GET /repos/{owner}/{repo}/commits", {
owner,
repo,
Expand Down

0 comments on commit d0adc4e

Please sign in to comment.