Skip to content

Commit

Permalink
feat: excluded tags as stale refs
Browse files Browse the repository at this point in the history
  • Loading branch information
philprime committed May 5, 2023
1 parent 9366028 commit 470df1e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

17 changes: 13 additions & 4 deletions src/removeStaleWorkflowRuns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ export async function removeStaleWorkflowRuns({
for (const branch of branches) {
core.info(`- ${branch.name}`);
}
const branchNames = new Set(branches.map((branch) => branch.name));
// Fetch all existing tags
const tags = await octokit.paginate(octokit.repos.listTags, {
owner: owner,
repo: repo,
});
core.info(`Found ${tags.length} tags:`);
for (const tag of tags) {
core.info(`- ${tag.name}`);
}
const existingRefs = new Set(branches.map((branch) => branch.name).concat(tags.map((tag) => tag.name)));

// Fetch all workflows
core.info(`Fetching workflows of repo '${owner}/${repo}' ...`);
Expand Down Expand Up @@ -80,7 +89,7 @@ export async function removeStaleWorkflowRuns({
core.info(`Found ${[...runBranches].length} unique branch names in workflow runs`);

// Filter out branches which still exist
const staleBranches = new Set([...runBranches].filter((name) => name !== null && !branchNames.has(name)));
const staleBranches = new Set([...runBranches].filter((name) => name !== null && !existingRefs.has(name)));
const sortedStaleBranchNames = [...staleBranches].sort().flatMap((branch) => branch as string);
if (sortedStaleBranchNames.length === 0) {
core.info('No stale branch names found, continuing with next batch of runs...');
Expand All @@ -96,7 +105,7 @@ export async function removeStaleWorkflowRuns({
for (const [idx, run] of runs.entries()) {
if (staleBranches.has(run.head_branch)) {
core.info(
`(${idx + 1}/${runs.length}) Workflow run #${run.run_number} used stale branch '${
`(${idx + 1}/${runs.length}) Workflow run #${run.run_number} used stale ref '${
run.head_branch
}', deleting it...`,
);
Expand All @@ -112,7 +121,7 @@ export async function removeStaleWorkflowRuns({
counter += 1;
} else {
core.info(
`(${idx + 1}/${runs.length}) Workflow run #${run.run_number} used active branch '${
`(${idx + 1}/${runs.length}) Workflow run #${run.run_number} used active ref '${
run.head_branch
}', skipping it...`,
);
Expand Down

0 comments on commit 470df1e

Please sign in to comment.