Skip to content

Commit

Permalink
feat: add artifactRetentionDays option
Browse files Browse the repository at this point in the history
+ Add a new input option for applying a custom `retention-days` to the action artifact
+ Document new option
  • Loading branch information
breadadams committed Jun 5, 2023
1 parent 03becbf commit 77fc524
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 6 additions & 3 deletions src/utils/artifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}

0 comments on commit 77fc524

Please sign in to comment.