Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
smzelek committed Aug 7, 2024
1 parent 7260b04 commit 6c61324
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ inputs:
description: 'Set this to determine the number of days to retain the uploaded artifact [1-90](defaults to 90).'
default: 90
runs:
using: 'node16'
using: 'node20'
main: 'dist/index.js'
4 changes: 2 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export function getClient(ctx: AppflowContext) {
baseURL,
timeout: 5000,
responseType: 'json',
headers: {
headers: {
Authorization: `Bearer ${token}`,
// Format adopted from standard defined here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent
'User-Agent': 'AppflowBuildAction/1.0.3'
'User-Agent': 'AppflowBuildAction/1.0.3',
},
});
}
22 changes: 7 additions & 15 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as core from '@actions/core';
import * as artifact from '@actions/artifact';
import { getClient } from './client';
import { runWithContext } from './run';

async function run(): Promise<void> {
Expand All @@ -9,8 +8,8 @@ async function run(): Promise<void> {
error: core.error,
print: core.info,
};
const artifactName = core.getInput('upload-artifact');
try {
const artifactName = core.getInput('upload-artifact');
const retentionDays = parseInt(core.getInput('artifact-retention-days'));
const pathToArtifact = await runWithContext({
logger,
Expand All @@ -28,25 +27,18 @@ async function run(): Promise<void> {
});
if (pathToArtifact && artifactName) {
core.info('Attempting to upload generated artifacts.');
const artifactClient = artifact.create();
const uploadResult = await artifactClient.uploadArtifact(
const artifactClient = new artifact.DefaultArtifactClient();
await artifactClient.uploadArtifact(
artifactName,
[pathToArtifact],
process.env.HOME as string,
{ retentionDays }
);
uploadResult.failedItems.forEach(item =>
core.warning(`Failed to upload artifact ${item}`)
);
core.info(`Uploaded artifact ${uploadResult.artifactName}`);
}
} catch (error) {
if (error.response) {
try {
core.error(JSON.stringify(error.response.data, null, 2));
} catch (e) {}
core.info(`Uploaded artifact ${artifactName}`);
}
core.setFailed(error.message);
} catch (err: unknown) {
core.error(`Failed to upload artifact ${artifactName}: ${err}`);
core.setFailed(`${err}`);
}
}

Expand Down

0 comments on commit 6c61324

Please sign in to comment.