Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update main.js #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 28 additions & 33 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,65 @@ const github = require('@actions/github')

async function main() {
try {
const token = core.getInput("github_token", { required: true })
const workflow = core.getInput("workflow", { required: true })
const [owner, repo] = core.getInput("repo", { required: true }).split("/")
const name = core.getInput("name")
let workflowConclusion = core.getInput("workflow_conclusion")
let runID = core.getInput("run_id")
const client = github.getOctokit(token)

const token = core.getInput("github_token") || process.env.GITHUB_TOKEN;
const workflow = core.getInput("workflow", { required: true });
const repo = core.getInput("repo") || process.env.GITHUB_REPOSITORY;
const [owner, repository] = repo.split("/");
const name = core.getInput("name");
let workflowConclusion = core.getInput("workflow_conclusion") || 'success';
let runID = core.getInput("run_id");

const client = github.getOctokit(token);

if (!runID) {
for await (const runs of client.paginate.iterator(client.rest.actions.listWorkflowRuns, {
owner: owner,
repo: repo,
repo: repository,
workflow_id: workflow
}
)) {
})) {
for (const run of runs.data) {
if (workflowConclusion && (workflowConclusion != run.conclusion && workflowConclusion != run.status)) {
continue
continue;
}
runID = run.id
break
runID = run.id;
break;
}
if (runID) {
break
break;
}
}
}

if (!runID) {
throw new Error("no matching workflow run found")
throw new Error("no matching workflow run found");
}

let artifacts = await client.paginate(client.rest.actions.listWorkflowRunArtifacts, {
owner: owner,
repo: repo,
repo: repository,
run_id: runID,
})
});

// One artifact or all if `name` input is not specified.
if (name) {
artifacts = artifacts.filter((artifact) => {
return artifact.name == name
})
artifacts = artifacts.filter((artifact) => artifact.name === name);
}

if (artifacts.length == 0)
throw new Error("no artifacts found")

if (artifacts.length === 0) {
throw new Error("no artifacts found");
}

for (const artifact of artifacts) {
console.log("==> Artifact:", artifact.id)

console.log("==> Deleting artifact:", artifact.id);
await client.rest.actions.deleteArtifact({
owner: owner,
repo: repo,
repo: repository,
artifact_id: artifact.id,
})

});
}

} catch (error) {
core.setFailed(error.message)
core.setFailed(error.message);
}
}

main()

main();