Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add artifactRetentionDays option #128

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,24 @@ 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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the rest of the docs I'm now thinking this default: undefined isn't necessary. Thoughts?


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
3 changes: 2 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ 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'),
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 })
}