diff --git a/action.yml b/action.yml index bfdecf4..1885d78 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/src/client.ts b/src/client.ts index 5ffe38d..4122d2b 100644 --- a/src/client.ts +++ b/src/client.ts @@ -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', }, }); } diff --git a/src/main.ts b/src/main.ts index 398fed7..5ad9c0b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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 { @@ -9,8 +8,8 @@ async function run(): Promise { 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, @@ -28,25 +27,18 @@ async function run(): Promise { }); 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}`); } }