Skip to content

Commit

Permalink
added more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Bullrich committed Aug 2, 2024
1 parent d1fce34 commit 90293ce
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions log/src/github/artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class ArtifactManager {
) { }

async getPreviousArtifact(repo: Repo): Promise<string | null> {
this.logger.info("Looking for previous artifact");
const workflows = await this.api.rest.actions.listRepoWorkflows(repo);

const workflow = workflows.data.workflows.find(w => w.path.includes(process.env.WORKFLOW_FILENAME ?? ""));
Expand All @@ -19,6 +20,8 @@ export class ArtifactManager {
return null;
}

this.logger.info(`Found workflow for ${workflow.name}`);

const runs = await this.api.rest.actions.listWorkflowRuns({
...repo,
workflow_id: workflow.id,
Expand All @@ -32,25 +35,29 @@ export class ArtifactManager {
}

for (const run of runs.data.workflow_runs) {
this.logger.info(`Searching for artifact in ${run.name}: ${run.id}`);
const artifacts = await this.api.rest.actions.listWorkflowRunArtifacts({
...repo,
run_id: run.id
});

const artifact = artifacts.data.artifacts.find(artifact => artifact.name === artifactName);

if (artifact) {
const response = await this.api.rest.actions.downloadArtifact({
...repo,
artifact_id: artifact.id,
archive_format: "zip"
});
await writeFile(artifactName, Buffer.from(response.data as string));
execSync(`unzip -o ${artifactName} -d ./logs`);
if (!artifact) {
this.logger.info(`Found no artifact in ${run.name}: ${run.id}`);
return null;
}

const response = await this.api.rest.actions.downloadArtifact({
...repo,
artifact_id: artifact.id,
archive_format: "zip"
});
await writeFile(artifactName, Buffer.from(response.data as string));
execSync(`unzip -o ${artifactName} -d ./logs`);

this.logger.info("Artifact downloaded correctly");
this.logger.info("Artifact downloaded correctly");

}
return `./logs/${artifactName}`;
}
return null;
Expand Down

0 comments on commit 90293ce

Please sign in to comment.