From 77fc524c53bb8e66b28c206abf37bea8696a7c29 Mon Sep 17 00:00:00 2001 From: Brad Adams Date: Mon, 5 Jun 2023 17:22:39 +0200 Subject: [PATCH 1/3] feat: add `artifactRetentionDays` option + Add a new input option for applying a custom `retention-days` to the action artifact + Document new option --- README.md | 10 ++++++++++ action.yml | 2 ++ src/config.js | 1 + src/index.js | 2 +- src/utils/artifacts.js | 9 ++++++--- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5608a8ddb..76aefc3bd 100644 --- a/README.md +++ b/README.md @@ -517,6 +517,16 @@ Upload Lighthouse results as [action artifacts](https://help.github.com/en/actio uploadArtifacts: true ``` +#### `artifactRetentionDays` (default: undefined) + +Number of days the action artifact should be retained for when using `uploadArtifacts`. + +This is based on the [`retention-days`](https://docs.github.com/en/actions/using-workflows/storing-workflow-data-as-artifacts#configuring-a-custom-artifact-retention-period) property from `actions/upload-artifact`, which defaults to 90 days. + +```yml +artifactRetentionDays: 7 +``` + #### `temporaryPublicStorage` (default: false) Upload reports to the [_temporary public storage_](https://github.com/GoogleChrome/lighthouse-ci/blob/master/docs/getting-started.md#collect-lighthouse-results). diff --git a/action.yml b/action.yml index d61e05992..c3efade3f 100644 --- a/action.yml +++ b/action.yml @@ -12,6 +12,8 @@ inputs: artifactName: description: 'Name of the artifact group if using uploadArtifacts. default: lighthouse-results' default: lighthouse-results + artifactRetentionDays: + description: 'Number of days the action artifact should be retained for' temporaryPublicStorage: descripton: 'Opt-in to saving Lighthouse results to temporary public storage' runs: diff --git a/src/config.js b/src/config.js index 66779540c..888f6b702 100644 --- a/src/config.js +++ b/src/config.js @@ -77,6 +77,7 @@ exports.getInput = function getInputArgs() { basicAuthUsername: core.getInput('basicAuthUsername') || 'lighthouse', basicAuthPassword: core.getInput('basicAuthPassword'), artifactName: core.getInput('artifactName'), + artifactRetentionDays: core.getInput('artifactRetentionDays') ? parseInt(core.getInput('artifactRetentionDays'), 10) : undefined, } } diff --git a/src/index.js b/src/index.js index df24771a5..617f10802 100644 --- a/src/index.js +++ b/src/index.js @@ -65,7 +65,7 @@ async function main() { if (input.serverToken || input.temporaryPublicStorage || input.uploadArtifacts) { // upload artifacts as soon as collected if (input.uploadArtifacts) { - await uploadArtifacts(resultsPath, input.artifactName) + await uploadArtifacts(resultsPath, input.artifactName, input.artifactRetentionDays) } if (input.serverToken || input.temporaryPublicStorage) { diff --git a/src/utils/artifacts.js b/src/utils/artifacts.js index ba0364d6b..d62df079c 100644 --- a/src/utils/artifacts.js +++ b/src/utils/artifacts.js @@ -2,10 +2,13 @@ const artifact = require('@actions/artifact') const fs = require('fs').promises const { join } = require('path') -/** @param {string} resultsPath */ -exports.uploadArtifacts = async function uploadArtifacts(resultsPath, artifactName = 'lighthouse-results') { +/** + * @param {string} resultsPath + * @param {number} [retentionDays] + */ +exports.uploadArtifacts = async function uploadArtifacts(resultsPath, artifactName = 'lighthouse-results', retentionDays) { const artifactClient = artifact.create() const fileNames = await fs.readdir(resultsPath) const files = fileNames.map((fileName) => join(resultsPath, fileName)) - return artifactClient.uploadArtifact(artifactName, files, resultsPath, { continueOnError: true }) + return artifactClient.uploadArtifact(artifactName, files, resultsPath, { continueOnError: true, retentionDays }) } From 2c9efca471db7f63f7de572f39b67ba08b975b96 Mon Sep 17 00:00:00 2001 From: Brad Adams Date: Mon, 5 Jun 2023 17:23:03 +0200 Subject: [PATCH 2/3] docs: add `artifactName` option to readme --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 76aefc3bd..606a53eaf 100644 --- a/README.md +++ b/README.md @@ -517,6 +517,14 @@ Upload Lighthouse results as [action artifacts](https://help.github.com/en/actio uploadArtifacts: true ``` +#### `artifactName` (default: lighthouse-results) + +Filename of the action artifact when using `uploadArtifacts`. + +```yml +artifactName: my-custom-name +``` + #### `artifactRetentionDays` (default: undefined) Number of days the action artifact should be retained for when using `uploadArtifacts`. From df0abfebb73da861e806e576cee44b8c71fc118d Mon Sep 17 00:00:00 2001 From: Brad Adams Date: Mon, 5 Jun 2023 17:23:18 +0200 Subject: [PATCH 3/3] chore: remove unnecessary ternary --- src/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.js b/src/config.js index 888f6b702..358d65ec3 100644 --- a/src/config.js +++ b/src/config.js @@ -73,7 +73,7 @@ exports.getInput = function getInputArgs() { serverBaseUrl, serverToken, temporaryPublicStorage, - uploadArtifacts: core.getInput('uploadArtifacts') === 'true' ? true : false, + uploadArtifacts: core.getInput('uploadArtifacts') === 'true', basicAuthUsername: core.getInput('basicAuthUsername') || 'lighthouse', basicAuthPassword: core.getInput('basicAuthPassword'), artifactName: core.getInput('artifactName'),