Skip to content

Commit e88ec1a

Browse files
committed
Review @actions/artifact latest version
1 parent a7e615a commit e88ec1a

16 files changed

+392
-168
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ actions can be run directly on your workstation.
1717
The following table tracks the versions of the GitHub Actions Toolkit that are
1818
currently implemented by this tool.
1919

20-
| Package | Version |
21-
| ------------------- | -------- |
22-
| `@actions/artifact` | `2.2.0` |
23-
| `@actions/core` | `1.11.1` |
20+
| Package | Version |
21+
| ---------------------------------------------------------------------- | -------- |
22+
| [`@actions/artifact`](https://www.npmjs.com/package/@actions/artifact) | `2.3.2` |
23+
| `@actions/core` | `1.11.1` |
2424

2525
## Changelog
2626

src/stubs/artifact/artifact.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
2-
* @github/local-action Modified
2+
* Last Reviewed Commit: https://github.com/actions/toolkit/blob/930c89072712a3aac52d74b23338f00bb0cfcb24/packages/artifact/src/artifact.ts
33
*/
4-
54
import {
65
type ArtifactClient,
76
DefaultArtifactClient

src/stubs/artifact/internal/client.ts

Lines changed: 112 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* Last Reviewed Commit: https://github.com/actions/toolkit/blob/930c89072712a3aac52d74b23338f00bb0cfcb24/packages/artifact/src/internal/client.ts
3+
*/
14
import { warning } from '../../core/core.js'
25
import {
36
deleteArtifactInternal,
@@ -28,18 +31,18 @@ import type {
2831
import { uploadArtifact } from './upload/upload-artifact.js'
2932

3033
/**
31-
* @github/local-action Unmodified
34+
* Generic interface for the artifact client.
3235
*/
3336
/* istanbul ignore next */
3437
export interface ArtifactClient {
3538
/**
3639
* Uploads an artifact.
3740
*
38-
* @param name The name of the artifact, required
39-
* @param files A list of absolute or relative paths that denote what files should be uploaded
40-
* @param rootDirectory An absolute or relative file path that denotes the root parent directory of the files being uploaded
41-
* @param options Extra options for customizing the upload behavior
42-
* @returns single UploadArtifactResponse object
41+
* @param name Artifact Name
42+
* @param files File(s) to Upload
43+
* @param rootDirectory Root Directory
44+
* @param options Upload Options
45+
* @returns Upload Artifact Response
4346
*/
4447
uploadArtifact(
4548
name: string,
@@ -49,32 +52,31 @@ export interface ArtifactClient {
4952
): Promise<UploadArtifactResponse>
5053

5154
/**
52-
* Lists all artifacts that are part of the current workflow run.
53-
* This function will return at most 1000 artifacts per workflow run.
55+
* List all artifacts for a workflow run.
5456
*
55-
* If `options.findBy` is specified, this will call the public List-Artifacts API which can list from other runs.
56-
* https://docs.github.com/en/rest/actions/artifacts?apiVersion=2022-11-28#list-workflow-run-artifacts
57+
* If `options.findBy` is specified, this will call the public List-Artifacts
58+
* API which can list from other runs.
5759
*
58-
* @param options Extra options that allow for the customization of the list behavior
59-
* @returns ListArtifactResponse object
60+
* @param options List Artifact Options
61+
* @returns List Artifact Response
6062
*/
6163
listArtifacts(
6264
options?: ListArtifactsOptions & FindOptions
6365
): Promise<ListArtifactsResponse>
6466

6567
/**
6668
* Finds an artifact by name.
67-
* If there are multiple artifacts with the same name in the same workflow run, this will return the latest.
68-
* If the artifact is not found, it will throw.
6969
*
70-
* If `options.findBy` is specified, this will use the public List Artifacts API with a name filter which can get artifacts from other runs.
71-
* https://docs.github.com/en/rest/actions/artifacts?apiVersion=2022-11-28#list-workflow-run-artifacts
72-
* `@actions/artifact` v2+ does not allow for creating multiple artifacts with the same name in the same workflow run.
73-
* It is possible to have multiple artifacts with the same name in the same workflow run by using old versions of upload-artifact (v1,v2 and v3), @actions/artifact < v2 or it is a rerun.
74-
* If there are multiple artifacts with the same name in the same workflow run this function will return the first artifact that matches the name.
70+
* If there are multiple artifacts with the same name in the same workflow
71+
* run, this will return the latest. If the artifact is not found, it will
72+
* throw.
73+
*
74+
* If `options.findBy` is specified, this will use the public List Artifacts
75+
* API with a name filter which can get artifacts from other runs.
7576
*
76-
* @param artifactName The name of the artifact to find
77-
* @param options Extra options that allow for the customization of the get behavior
77+
* @param artifactName Artifact Name
78+
* @param options Get Artifact Options
79+
* @returns Get Artifact Response
7880
*/
7981
getArtifact(
8082
artifactName: string,
@@ -84,25 +86,27 @@ export interface ArtifactClient {
8486
/**
8587
* Downloads an artifact and unzips the content.
8688
*
87-
* If `options.findBy` is specified, this will use the public Download Artifact API https://docs.github.com/en/rest/actions/artifacts?apiVersion=2022-11-28#download-an-artifact
89+
* If `options.findBy` is specified, this will use the public Download
90+
* Artifact API.
8891
*
89-
* @param artifactId The id of the artifact to download
90-
* @param options Extra options that allow for the customization of the download behavior
91-
* @returns single DownloadArtifactResponse object
92+
* @param artifactId Artifact ID
93+
* @param options Download Artifact Options
94+
* @returns Download Artifact Response
9295
*/
9396
downloadArtifact(
9497
artifactId: number,
9598
options?: DownloadArtifactOptions & FindOptions
9699
): Promise<DownloadArtifactResponse>
97100

98101
/**
99-
* Delete an Artifact
102+
* Deletes an artifact.
100103
*
101-
* If `options.findBy` is specified, this will use the public Delete Artifact API https://docs.github.com/en/rest/actions/artifacts?apiVersion=2022-11-28#delete-an-artifact
104+
* If `options.findBy` is specified, this will use the public Delete Artifact
105+
* API
102106
*
103-
* @param artifactName The name of the artifact to delete
104-
* @param options Extra options that allow for the customization of the delete behavior
105-
* @returns single DeleteArtifactResponse object
107+
* @param artifactName Artifact Name
108+
* @param options Delete Artifact Options
109+
* @returns Delete Artifact Response
106110
*/
107111
deleteArtifact(
108112
artifactName: string,
@@ -111,9 +115,22 @@ export interface ArtifactClient {
111115
}
112116

113117
/**
114-
* @github/local-action Modified
118+
* Default artifact client that is used by the artifact action(s).
115119
*/
116120
export class DefaultArtifactClient implements ArtifactClient {
121+
/**
122+
* Uploads an artifact.
123+
*
124+
* @remarks
125+
*
126+
* - Adds a check for the LOCAL_ACTION_ARTIFACT_PATH variable.
127+
*
128+
* @param name Artifact Name
129+
* @param files File(s) to Upload
130+
* @param rootDirectory Root Directory
131+
* @param options Upload Options
132+
* @returns Upload Artifact Response
133+
*/
117134
async uploadArtifact(
118135
name: string,
119136
files: string[],
@@ -126,9 +143,7 @@ export class DefaultArtifactClient implements ArtifactClient {
126143
)
127144

128145
try {
129-
if (isGhes()) {
130-
throw new GHESNotSupportedError()
131-
}
146+
if (isGhes()) throw new GHESNotSupportedError()
132147

133148
return uploadArtifact(name, files, rootDirectory, options)
134149
} catch (error) {
@@ -144,6 +159,20 @@ If the error persists, please check whether Actions is operating normally at [ht
144159
}
145160
}
146161

162+
/**
163+
* Downloads an artifact and unzips the content.
164+
*
165+
* If `options.findBy` is specified, this will use the public Download
166+
* Artifact API.
167+
*
168+
* @remarks
169+
*
170+
* - Adds a check for the LOCAL_ACTION_ARTIFACT_PATH variable.
171+
*
172+
* @param artifactId Artifact ID
173+
* @param options Download Artifact Options
174+
* @returns Download Artifact Response
175+
*/
147176
async downloadArtifact(
148177
artifactId: number,
149178
options?: DownloadArtifactOptions & FindOptions
@@ -154,9 +183,7 @@ If the error persists, please check whether Actions is operating normally at [ht
154183
)
155184

156185
try {
157-
if (isGhes()) {
158-
throw new GHESNotSupportedError()
159-
}
186+
if (isGhes()) throw new GHESNotSupportedError()
160187

161188
if (options?.findBy) {
162189
const {
@@ -187,6 +214,19 @@ If the error persists, please check whether Actions and API requests are operati
187214
}
188215
}
189216

217+
/**
218+
* List all artifacts for a workflow run.
219+
*
220+
* If `options.findBy` is specified, this will call the public List-Artifacts
221+
* API which can list from other runs.
222+
*
223+
* @remarks
224+
*
225+
* - Adds a check for the LOCAL_ACTION_ARTIFACT_PATH variable.
226+
*
227+
* @param options Extra options that allow for the customization of the list behavior
228+
* @returns ListArtifactResponse object
229+
*/
190230
async listArtifacts(
191231
options?: ListArtifactsOptions & FindOptions
192232
): Promise<ListArtifactsResponse> {
@@ -196,9 +236,7 @@ If the error persists, please check whether Actions and API requests are operati
196236
)
197237

198238
try {
199-
if (isGhes()) {
200-
throw new GHESNotSupportedError()
201-
}
239+
if (isGhes()) throw new GHESNotSupportedError()
202240

203241
if (options?.findBy) {
204242
const {
@@ -228,6 +266,24 @@ If the error persists, please check whether Actions and API requests are operati
228266
}
229267
}
230268

269+
/**
270+
* Finds an artifact by name.
271+
*
272+
* If there are multiple artifacts with the same name in the same workflow
273+
* run, this will return the latest. If the artifact is not found, it will
274+
* throw.
275+
*
276+
* If `options.findBy` is specified, this will use the public List Artifacts
277+
* API with a name filter which can get artifacts from other runs.
278+
*
279+
* @remarks
280+
*
281+
* - Adds a check for the LOCAL_ACTION_ARTIFACT_PATH variable.
282+
*
283+
* @param artifactName Artifact Name
284+
* @param options Get Artifact Options
285+
* @returns Get Artifact Response
286+
*/
231287
async getArtifact(
232288
artifactName: string,
233289
options?: FindOptions
@@ -238,9 +294,7 @@ If the error persists, please check whether Actions and API requests are operati
238294
)
239295

240296
try {
241-
if (isGhes()) {
242-
throw new GHESNotSupportedError()
243-
}
297+
if (isGhes()) throw new GHESNotSupportedError()
244298

245299
if (options?.findBy) {
246300
const {
@@ -269,6 +323,20 @@ If the error persists, please check whether Actions and API requests are operati
269323
}
270324
}
271325

326+
/**
327+
* Deletes an artifact.
328+
*
329+
* If `options.findBy` is specified, this will use the public Delete Artifact
330+
* API
331+
*
332+
* @remarks
333+
*
334+
* - Adds a check for the LOCAL_ACTION_ARTIFACT_PATH variable.
335+
*
336+
* @param artifactName Artifact Name
337+
* @param options Delete Artifact Options
338+
* @returns Delete Artifact Response
339+
*/
272340
async deleteArtifact(
273341
artifactName: string,
274342
options?: FindOptions
@@ -279,9 +347,7 @@ If the error persists, please check whether Actions and API requests are operati
279347
)
280348

281349
try {
282-
if (isGhes()) {
283-
throw new GHESNotSupportedError()
284-
}
350+
if (isGhes()) throw new GHESNotSupportedError()
285351

286352
if (options?.findBy) {
287353
const {

src/stubs/artifact/internal/delete/delete-artifact.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* Last Reviewed Commit: https://github.com/actions/toolkit/blob/930c89072712a3aac52d74b23338f00bb0cfcb24/packages/artifact/src/internal/delete/delete-artifact.ts
3+
*/
14
import type { OctokitOptions } from '@octokit/core'
25
import { requestLog } from '@octokit/plugin-request-log'
36
import { retry } from '@octokit/plugin-retry'
@@ -17,7 +20,14 @@ import type { Artifact, DeleteArtifactResponse } from '../shared/interfaces.js'
1720
import { getUserAgentString } from '../shared/user-agent.js'
1821

1922
/**
20-
* @github/local-action Unmodified
23+
* Deletes artifacts from GitHub.
24+
*
25+
* @param artifactName Artifact Name
26+
* @param workflowRunId Workflow Run ID
27+
* @param repositoryOwner Repository Owner
28+
* @param repositoryName Repository Name
29+
* @param token GitHub Token
30+
* @returns Delete Artifact Response
2131
*/
2232
/* istanbul ignore next */
2333
export async function deleteArtifactPublic(
@@ -39,6 +49,7 @@ export async function deleteArtifactPublic(
3949

4050
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4151
const github = getOctokit(token, opts, retry as any, requestLog as any)
52+
4253
const getArtifactResp = await getArtifactPublic(
4354
artifactName,
4455
workflowRunId,
@@ -53,19 +64,25 @@ export async function deleteArtifactPublic(
5364
artifact_id: getArtifactResp.artifact.id
5465
})
5566

56-
if (deleteArtifactResp.status !== 204) {
67+
if (deleteArtifactResp.status !== 204)
5768
throw new InvalidResponseError(
5869
`Invalid response from GitHub API: ${deleteArtifactResp.status} (${deleteArtifactResp?.headers?.['x-github-request-id']})`
5970
)
60-
}
6171

6272
return {
6373
id: getArtifactResp.artifact.id
6474
}
6575
}
6676

6777
/**
68-
* @github/local-action Modified
78+
* Deletes an artifact that is part of this workflow run.
79+
*
80+
* @remarks
81+
*
82+
* - Deletes the artifact from the filesystem based on the environment metadata.
83+
*
84+
* @param artifactName Artifact Name
85+
* @returns Delete Artifact Response
6986
*/
7087
export async function deleteArtifactInternal(
7188
artifactName: string

0 commit comments

Comments
 (0)