Compare commits

...

4 Commits

Author SHA1 Message Date
Daniel Kennedy
d5c7beebb0 Clarify naming 2026-02-25 15:34:02 -05:00
Daniel Kennedy
518025b753 Add unit tests 2026-02-25 15:32:46 -05:00
Daniel Kennedy
3a2b6d4c85 Fix some issues with the cleanup 2026-02-25 15:25:26 -05:00
Daniel Kennedy
bdabba390d Use script v8 2026-02-25 15:19:28 -05:00
3 changed files with 74 additions and 21 deletions

View File

@@ -10,6 +10,10 @@ on:
paths-ignore:
- '**.md'
permissions:
contents: read
actions: write
jobs:
build:
name: Build
@@ -391,27 +395,20 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node 24
uses: actions/setup-node@v4
with:
node-version: 24.x
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Delete test artifacts
uses: actions/github-script@v7
uses: actions/github-script@v8
with:
script: |
const artifactClient = require('@actions/artifact');
const artifact = artifactClient.default || artifactClient;
const {artifacts} = await artifact.listArtifacts({latest: true});
const keep = ['report.html'];
const owner = context.repo.owner;
const repo = context.repo.repo;
const runId = context.runId;
const {data: {artifacts}} = await github.rest.actions.listWorkflowRunArtifacts({
owner,
repo,
run_id: runId
});
for (const a of artifacts) {
if (keep.includes(a.name)) {
@@ -419,10 +416,13 @@ jobs:
continue;
}
try {
await artifact.deleteArtifact(a.name);
await github.rest.actions.deleteArtifact({
owner,
repo,
artifact_id: a.id
});
console.log(`Deleted artifact '${a.name}'`);
} catch (err) {
console.log(`Could not delete artifact '${a.name}': ${err.message}`);
}
}

View File

@@ -274,4 +274,57 @@ describe('upload', () => {
`Skipping deletion of '${fixtures.artifactName}', it does not exist`
)
})
test('passes skipArchive when archive is false', async () => {
mockInputs({
[Inputs.Archive]: false
})
mockFindFilesToUpload.mockResolvedValue({
filesToUpload: [fixtures.filesToUpload[0]],
rootDirectory: fixtures.rootDirectory
})
await run()
expect(artifact.default.uploadArtifact).toHaveBeenCalledWith(
fixtures.artifactName,
[fixtures.filesToUpload[0]],
fixtures.rootDirectory,
{compressionLevel: 6, skipArchive: true}
)
})
test('does not pass skipArchive when archive is true', async () => {
mockInputs({
[Inputs.Archive]: true
})
mockFindFilesToUpload.mockResolvedValue({
filesToUpload: [fixtures.filesToUpload[0]],
rootDirectory: fixtures.rootDirectory
})
await run()
expect(artifact.default.uploadArtifact).toHaveBeenCalledWith(
fixtures.artifactName,
[fixtures.filesToUpload[0]],
fixtures.rootDirectory,
{compressionLevel: 6}
)
})
test('fails when archive is false and multiple files are provided', async () => {
mockInputs({
[Inputs.Archive]: false
})
await run()
expect(core.setFailed).toHaveBeenCalledWith(
`When 'archive' is set to false, only a single file can be uploaded. Found ${fixtures.filesToUpload.length} files to upload.`
)
expect(artifact.default.uploadArtifact).not.toHaveBeenCalled()
})
})

View File

@@ -3,7 +3,7 @@ description: 'Upload a build artifact that can be used by subsequent workflow st
author: 'GitHub'
inputs:
name:
description: 'Artifact name. If the "archive" input is `false`, the name of the file uploaded will be the artifact name.'
description: 'Artifact name. If the `archive` input is `false`, the name of the file uploaded will be the artifact name.'
default: 'artifact'
path:
description: 'A file, directory or wildcard pattern that describes what to upload.'
@@ -49,7 +49,7 @@ inputs:
description: >
If true, the artifact will be archived (zipped) before uploading.
If false, the artifact will be uploaded as-is without archiving.
When archive is false, only a single file can be uploaded. The name of the file will be used as the artifact name.
When `archive` is `false`, only a single file can be uploaded. The name of the file will be used as the artifact name (ignoring the `name` parameter).
default: 'true'
outputs: