Skip to content

Commit

Permalink
fixes tick bug, sorts results
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrafe committed Oct 1, 2022
1 parent bb44272 commit 7631bdb
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 156 deletions.
182 changes: 97 additions & 85 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

33 changes: 0 additions & 33 deletions src/cache.ts

This file was deleted.

3 changes: 3 additions & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ type RunStep =

type Scope = "all" | "pr-changes" | "changes-since-last-success";

type SortTablesRows = "alphabetic" | "coverage-descending";

export const GITHUB_TOKEN = process.env.INPUT_GITHUB_TOKEN as string;
export const SCOPE = process.env.INPUT_SCOPE as Scope;
export const RUN_STEPS: RunStep[] = (process.env.INPUT_RUN_STEPS || "")
.split(",")
.map((item) => item as RunStep);
export const DEFAULT_BRANCH = process.env.DEFAULT_BRANCH;
export const BASE_SHA = process.env.BASE_SHA;
export const SORT_TABLES: SortTablesRows = "coverage-descending";
31 changes: 31 additions & 0 deletions src/getLastSuccessfulSha.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as core from "@actions/core";
import * as github from "@actions/github";
import { GITHUB_TOKEN } from "./env";

export const getLastSuccessfulSha = async () => {
const octokit = github.getOctokit(GITHUB_TOKEN);
const currentBranch = github.context.ref.replace("refs/heads/", "");

try {
const { data: runs } = await octokit.rest.actions.listWorkflowRuns({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
workflow_id: github.context.workflow,
status: "success",
branch: currentBranch,
});

const headCommits = runs.workflow_runs.map((run) => {
return run.head_commit;
});

const sortedHeadCommits = headCommits.sort(
(a, b) => Number(a!.timestamp) - Number(b!.timestamp)
);

return sortedHeadCommits[0]?.id;
} catch {
core.info("an error happened, no previous successful workflow run found.");
return undefined;
}
};
Loading

0 comments on commit 7631bdb

Please sign in to comment.