@ronaldphilipsen/local-action 0.0.0-stage → 7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.checkov.yml +3 -0
- package/.env.example +379 -0
- package/.github/codeql/codeql-config.yml +7 -0
- package/.github/copilot-instructions.md +79 -0
- package/.github/dependabot.yml +32 -0
- package/.github/workflows/codeql-analysis.yml +53 -0
- package/.github/workflows/continuous-delivery.yml +93 -0
- package/.github/workflows/continuous-integration.yml +382 -0
- package/.github/workflows/linter.yml +47 -0
- package/.github/workflows/release.yaml +100 -0
- package/.github/workflows/version-check.yml +44 -0
- package/.grype.yml +151 -0
- package/.markdown-lint.yml +7 -0
- package/.mega-linter.yml +188 -0
- package/.node-version +1 -0
- package/.prettierignore +4 -0
- package/.prettierrc.yml +14 -0
- package/.vscode/launch.json +15 -0
- package/.vscode/mcp.json +9 -0
- package/.vscode/settings.json +15 -0
- package/.vscode/tasks.json +51 -0
- package/.yaml-lint.yml +10 -0
- package/CHANGELOG.md +75 -0
- package/CODEOWNERS +3 -0
- package/CODE_OF_CONDUCT.md +74 -0
- package/CONTRIBUTING.md +140 -0
- package/LICENSE +21 -0
- package/README.md +277 -2
- package/SECURITY.md +42 -0
- package/SUPPORT.md +19 -0
- package/__fixtures__/@actions/core.ts +14 -0
- package/__fixtures__/@actions/exec.ts +9 -0
- package/__fixtures__/@actions/github.ts +3 -0
- package/__fixtures__/@actions/http-client.ts +9 -0
- package/__fixtures__/@actions/io.ts +9 -0
- package/__fixtures__/@octokit/rest.ts +18 -0
- package/__fixtures__/crypto.ts +7 -0
- package/__fixtures__/fs.ts +27 -0
- package/__fixtures__/javascript/no-export/.env.fixture +2 -0
- package/__fixtures__/javascript/no-export/action.yml +16 -0
- package/__fixtures__/javascript/no-export/node_modules/.gitkeep +0 -0
- package/__fixtures__/javascript/no-export/package.json +12 -0
- package/__fixtures__/javascript/no-export/src/index.js +0 -0
- package/__fixtures__/javascript/no-export/src/main.js +0 -0
- package/__fixtures__/javascript/no-import/.env.fixture +2 -0
- package/__fixtures__/javascript/no-import/action.yml +16 -0
- package/__fixtures__/javascript/no-import/node_modules/.gitkeep +0 -0
- package/__fixtures__/javascript/no-import/package.json +12 -0
- package/__fixtures__/javascript/no-import/src/index.js +3 -0
- package/__fixtures__/javascript/no-import/src/main.js +7 -0
- package/__fixtures__/javascript/success/.env.fixture +2 -0
- package/__fixtures__/javascript/success/action.yml +16 -0
- package/__fixtures__/javascript/success/node_modules/.gitkeep +0 -0
- package/__fixtures__/javascript/success/package.json +12 -0
- package/__fixtures__/javascript/success/post/index.js +3 -0
- package/__fixtures__/javascript/success/post/main.js +13 -0
- package/__fixtures__/javascript/success/pre/index.js +3 -0
- package/__fixtures__/javascript/success/pre/main.js +13 -0
- package/__fixtures__/javascript/success/src/index.js +3 -0
- package/__fixtures__/javascript/success/src/main.js +13 -0
- package/__fixtures__/javascript-esm/no-import/.env.fixture +2 -0
- package/__fixtures__/javascript-esm/no-import/action.yml +16 -0
- package/__fixtures__/javascript-esm/no-import/node_modules/.gitkeep +0 -0
- package/__fixtures__/javascript-esm/no-import/package.json +13 -0
- package/__fixtures__/javascript-esm/no-import/src/index.js +3 -0
- package/__fixtures__/javascript-esm/no-import/src/main.js +7 -0
- package/__fixtures__/javascript-esm/success/.env.fixture +2 -0
- package/__fixtures__/javascript-esm/success/action.yml +16 -0
- package/__fixtures__/javascript-esm/success/node_modules/.gitkeep +0 -0
- package/__fixtures__/javascript-esm/success/package.json +13 -0
- package/__fixtures__/javascript-esm/success/post/index.js +3 -0
- package/__fixtures__/javascript-esm/success/post/main.js +13 -0
- package/__fixtures__/javascript-esm/success/pre/index.js +3 -0
- package/__fixtures__/javascript-esm/success/pre/main.js +13 -0
- package/__fixtures__/javascript-esm/success/src/index.js +3 -0
- package/__fixtures__/javascript-esm/success/src/main.js +13 -0
- package/__fixtures__/path.ts +7 -0
- package/__fixtures__/payloads/issue_opened.json +33 -0
- package/__fixtures__/stream/promises.ts +3 -0
- package/__fixtures__/tsconfig-paths.ts +4 -0
- package/__fixtures__/typescript/no-import/.env.fixture +2 -0
- package/__fixtures__/typescript/no-import/action.yml +16 -0
- package/__fixtures__/typescript/no-import/node_modules/.gitkeep +0 -0
- package/__fixtures__/typescript/no-import/package.json +15 -0
- package/__fixtures__/typescript/no-import/src/index.ts +3 -0
- package/__fixtures__/typescript/no-import/src/main.ts +3 -0
- package/__fixtures__/typescript/no-import/tsconfig.json +20 -0
- package/__fixtures__/typescript/success/.env.fixture +2 -0
- package/__fixtures__/typescript/success/action.yml +16 -0
- package/__fixtures__/typescript/success/node_modules/.gitkeep +0 -0
- package/__fixtures__/typescript/success/package.json +15 -0
- package/__fixtures__/typescript/success/post/index.ts +3 -0
- package/__fixtures__/typescript/success/post/main.ts +9 -0
- package/__fixtures__/typescript/success/pre/index.ts +3 -0
- package/__fixtures__/typescript/success/pre/main.ts +9 -0
- package/__fixtures__/typescript/success/src/index.ts +3 -0
- package/__fixtures__/typescript/success/src/main.ts +9 -0
- package/__fixtures__/typescript/success/tsconfig.json +20 -0
- package/__fixtures__/typescript/success-yaml/.env.fixture +2 -0
- package/__fixtures__/typescript/success-yaml/action.yaml +16 -0
- package/__fixtures__/typescript/success-yaml/node_modules/.gitkeep +0 -0
- package/__fixtures__/typescript/success-yaml/package.json +15 -0
- package/__fixtures__/typescript/success-yaml/post/index.ts +3 -0
- package/__fixtures__/typescript/success-yaml/post/main.ts +9 -0
- package/__fixtures__/typescript/success-yaml/pre/index.ts +3 -0
- package/__fixtures__/typescript/success-yaml/pre/main.ts +9 -0
- package/__fixtures__/typescript/success-yaml/src/index.ts +3 -0
- package/__fixtures__/typescript/success-yaml/src/main.ts +9 -0
- package/__fixtures__/typescript/success-yaml/tsconfig.json +20 -0
- package/__fixtures__/typescript-esm/no-export/.env.fixture +2 -0
- package/__fixtures__/typescript-esm/no-export/action.yml +17 -0
- package/__fixtures__/typescript-esm/no-export/node_modules/.gitkeep +0 -0
- package/__fixtures__/typescript-esm/no-export/package.json +17 -0
- package/__fixtures__/typescript-esm/no-export/src/index.ts +0 -0
- package/__fixtures__/typescript-esm/no-export/src/main.ts +0 -0
- package/__fixtures__/typescript-esm/no-export/tsconfig.json +25 -0
- package/__fixtures__/typescript-esm/no-import/.env.fixture +2 -0
- package/__fixtures__/typescript-esm/no-import/action.yml +17 -0
- package/__fixtures__/typescript-esm/no-import/node_modules/.gitkeep +0 -0
- package/__fixtures__/typescript-esm/no-import/package.json +17 -0
- package/__fixtures__/typescript-esm/no-import/src/index.ts +3 -0
- package/__fixtures__/typescript-esm/no-import/src/main.ts +3 -0
- package/__fixtures__/typescript-esm/no-import/tsconfig.json +25 -0
- package/__fixtures__/typescript-esm/success/.env.fixture +2 -0
- package/__fixtures__/typescript-esm/success/action.yml +17 -0
- package/__fixtures__/typescript-esm/success/node_modules/.gitkeep +0 -0
- package/__fixtures__/typescript-esm/success/package.json +17 -0
- package/__fixtures__/typescript-esm/success/post/index.ts +3 -0
- package/__fixtures__/typescript-esm/success/post/main.ts +9 -0
- package/__fixtures__/typescript-esm/success/pre/index.ts +3 -0
- package/__fixtures__/typescript-esm/success/pre/main.ts +9 -0
- package/__fixtures__/typescript-esm/success/src/index.ts +3 -0
- package/__fixtures__/typescript-esm/success/src/main.ts +9 -0
- package/__fixtures__/typescript-esm/success/tsconfig.json +25 -0
- package/__fixtures__/typescript-esm/tsconfig-comments/.env.fixture +2 -0
- package/__fixtures__/typescript-esm/tsconfig-comments/action.yml +17 -0
- package/__fixtures__/typescript-esm/tsconfig-comments/node_modules/.gitkeep +0 -0
- package/__fixtures__/typescript-esm/tsconfig-comments/package.json +17 -0
- package/__fixtures__/typescript-esm/tsconfig-comments/src/index.ts +3 -0
- package/__fixtures__/typescript-esm/tsconfig-comments/src/main.ts +9 -0
- package/__fixtures__/typescript-esm/tsconfig-comments/tsconfig.json +21 -0
- package/__tests__/command.test.ts +224 -0
- package/__tests__/stubs/artifact/internal/client.test.ts +340 -0
- package/__tests__/stubs/artifact/internal/delete/delete-artifact.test.ts +152 -0
- package/__tests__/stubs/artifact/internal/download/download-artifact.test.ts +119 -0
- package/__tests__/stubs/artifact/internal/find/get-artifact.test.ts +237 -0
- package/__tests__/stubs/artifact/internal/find/list-artifacts.test.ts +218 -0
- package/__tests__/stubs/artifact/internal/find/retry-options.test.ts +54 -0
- package/__tests__/stubs/artifact/internal/shared/config.test.ts +91 -0
- package/__tests__/stubs/artifact/internal/shared/errors.test.ts +38 -0
- package/__tests__/stubs/artifact/internal/shared/user-agent.test.ts +22 -0
- package/__tests__/stubs/artifact/internal/upload/path-and-artifact-name-validation.test.ts +53 -0
- package/__tests__/stubs/artifact/internal/upload/upload-artifact.test.ts +126 -0
- package/__tests__/stubs/artifact/internal/upload/upload-zip-specification.test.ts +49 -0
- package/__tests__/stubs/cache/cache.test.ts +357 -0
- package/__tests__/stubs/cache/errors.test.ts +55 -0
- package/__tests__/stubs/cache/internal/cacheUtils.test.ts +109 -0
- package/__tests__/stubs/cache/internal/constants.test.ts +81 -0
- package/__tests__/stubs/cache/internal/tar.test.ts +129 -0
- package/__tests__/stubs/core/core.test.ts +760 -0
- package/__tests__/stubs/core/path-utils.test.ts +45 -0
- package/__tests__/stubs/core/platform.test.ts +89 -0
- package/__tests__/stubs/core/summary.test.ts +455 -0
- package/__tests__/stubs/env.test.ts +72 -0
- package/__tests__/stubs/github/context.test.ts +73 -0
- package/__tests__/stubs/github/github.test.ts +15 -0
- package/__tests__/stubs/github/internal/utils.test.ts +98 -0
- package/__tests__/stubs/github/utils.test.ts +16 -0
- package/__tests__/utils/config.test.ts +78 -0
- package/__tests__/utils/output.test.ts +32 -0
- package/__tests__/utils/package.test.ts +33 -0
- package/badges/coverage.svg +1 -0
- package/bin/local-action.js +121 -0
- package/docs/create-a-job-summary.md +32 -0
- package/docs/debugging-in-vscode.md +27 -0
- package/docs/img/job-summary.png +0 -0
- package/docs/supported-functionality.md +126 -0
- package/eslint.config.mjs +74 -0
- package/jest.config.ts +41 -0
- package/package.json +93 -4
- package/src/command.ts +171 -0
- package/src/commands/run.ts +616 -0
- package/src/index.ts +21 -0
- package/src/stubs/artifact/artifact.ts +17 -0
- package/src/stubs/artifact/internal/client.ts +400 -0
- package/src/stubs/artifact/internal/delete/delete-artifact.ts +126 -0
- package/src/stubs/artifact/internal/download/download-artifact.ts +309 -0
- package/src/stubs/artifact/internal/find/get-artifact.ts +135 -0
- package/src/stubs/artifact/internal/find/list-artifacts.ts +188 -0
- package/src/stubs/artifact/internal/find/retry-options.ts +57 -0
- package/src/stubs/artifact/internal/shared/config.ts +64 -0
- package/src/stubs/artifact/internal/shared/errors.ts +53 -0
- package/src/stubs/artifact/internal/shared/interfaces.ts +195 -0
- package/src/stubs/artifact/internal/shared/user-agent.ts +13 -0
- package/src/stubs/artifact/internal/upload/path-and-artifact-name-validation.ts +92 -0
- package/src/stubs/artifact/internal/upload/upload-artifact.ts +127 -0
- package/src/stubs/artifact/internal/upload/upload-zip-specification.ts +108 -0
- package/src/stubs/artifact/internal/upload/zip.ts +122 -0
- package/src/stubs/cache/cache.ts +334 -0
- package/src/stubs/cache/errors.ts +31 -0
- package/src/stubs/cache/interfaces.ts +4 -0
- package/src/stubs/cache/internal/cacheUtils.ts +207 -0
- package/src/stubs/cache/internal/constants.ts +45 -0
- package/src/stubs/cache/internal/tar.ts +374 -0
- package/src/stubs/cache/options.ts +91 -0
- package/src/stubs/core/core.ts +743 -0
- package/src/stubs/core/path-utils.ts +39 -0
- package/src/stubs/core/platform.ts +132 -0
- package/src/stubs/core/summary.ts +399 -0
- package/src/stubs/env.ts +40 -0
- package/src/stubs/github/context.ts +94 -0
- package/src/stubs/github/github.ts +29 -0
- package/src/stubs/github/interfaces.ts +52 -0
- package/src/stubs/github/internal/utils.ts +83 -0
- package/src/stubs/github/utils.ts +52 -0
- package/src/types/quibble.d.ts +5 -0
- package/src/types.ts +116 -0
- package/src/utils/config.ts +47 -0
- package/src/utils/output.ts +20 -0
- package/src/utils/package.ts +38 -0
- package/tsconfig.base.json +29 -0
- package/tsconfig.eslint.json +22 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Last Reviewed Commit: https://github.com/actions/toolkit/blob/ee91adfbc4f4d1470e176a8d568c0cbdabaf98e0/packages/artifact/src/internal/client.ts
|
|
3
|
+
* Last Reviewed Date: 2026-01-16
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { warning } from '../../core/core.js'
|
|
7
|
+
import {
|
|
8
|
+
deleteArtifactInternal,
|
|
9
|
+
deleteArtifactPublic
|
|
10
|
+
} from './delete/delete-artifact.js'
|
|
11
|
+
import {
|
|
12
|
+
downloadArtifactInternal,
|
|
13
|
+
downloadArtifactPublic
|
|
14
|
+
} from './download/download-artifact.js'
|
|
15
|
+
import { getArtifactInternal, getArtifactPublic } from './find/get-artifact.js'
|
|
16
|
+
import {
|
|
17
|
+
listArtifactsInternal,
|
|
18
|
+
listArtifactsPublic
|
|
19
|
+
} from './find/list-artifacts.js'
|
|
20
|
+
import { isGhes } from './shared/config.js'
|
|
21
|
+
import { GHESNotSupportedError } from './shared/errors.js'
|
|
22
|
+
import type {
|
|
23
|
+
DeleteArtifactResponse,
|
|
24
|
+
DownloadArtifactOptions,
|
|
25
|
+
DownloadArtifactResponse,
|
|
26
|
+
FindOptions,
|
|
27
|
+
GetArtifactResponse,
|
|
28
|
+
ListArtifactsOptions,
|
|
29
|
+
ListArtifactsResponse,
|
|
30
|
+
UploadArtifactOptions,
|
|
31
|
+
UploadArtifactResponse
|
|
32
|
+
} from './shared/interfaces.js'
|
|
33
|
+
import { uploadArtifact } from './upload/upload-artifact.js'
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Generic interface for the artifact client.
|
|
37
|
+
*/
|
|
38
|
+
export interface ArtifactClient {
|
|
39
|
+
/**
|
|
40
|
+
* Uploads an artifact.
|
|
41
|
+
*
|
|
42
|
+
* @param name Artifact Name
|
|
43
|
+
* @param files File(s) to Upload
|
|
44
|
+
* @param rootDirectory Root Directory
|
|
45
|
+
* @param options Upload Options
|
|
46
|
+
* @returns Upload Artifact Response
|
|
47
|
+
*/
|
|
48
|
+
uploadArtifact(
|
|
49
|
+
name: string,
|
|
50
|
+
files: string[],
|
|
51
|
+
rootDirectory: string,
|
|
52
|
+
options?: UploadArtifactOptions
|
|
53
|
+
): Promise<UploadArtifactResponse>
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* List all artifacts for a workflow run.
|
|
57
|
+
*
|
|
58
|
+
* If `options.findBy` is specified, this will call the public List-Artifacts
|
|
59
|
+
* API which can list from other runs.
|
|
60
|
+
*
|
|
61
|
+
* @param options List Artifact Options
|
|
62
|
+
* @returns List Artifact Response
|
|
63
|
+
*/
|
|
64
|
+
listArtifacts(
|
|
65
|
+
options?: ListArtifactsOptions & FindOptions
|
|
66
|
+
): Promise<ListArtifactsResponse>
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Finds an artifact by name.
|
|
70
|
+
*
|
|
71
|
+
* If there are multiple artifacts with the same name in the same workflow
|
|
72
|
+
* run, this will return the latest. If the artifact is not found, it will
|
|
73
|
+
* throw.
|
|
74
|
+
*
|
|
75
|
+
* If `options.findBy` is specified, this will use the public List Artifacts
|
|
76
|
+
* API with a name filter which can get artifacts from other runs.
|
|
77
|
+
*
|
|
78
|
+
* @param artifactName Artifact Name
|
|
79
|
+
* @param options Get Artifact Options
|
|
80
|
+
* @returns Get Artifact Response
|
|
81
|
+
*/
|
|
82
|
+
getArtifact(
|
|
83
|
+
artifactName: string,
|
|
84
|
+
options?: FindOptions
|
|
85
|
+
): Promise<GetArtifactResponse>
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Downloads an artifact and unzips the content.
|
|
89
|
+
*
|
|
90
|
+
* If `options.findBy` is specified, this will use the public Download
|
|
91
|
+
* Artifact API.
|
|
92
|
+
*
|
|
93
|
+
* @param artifactId Artifact ID
|
|
94
|
+
* @param options Download Artifact Options
|
|
95
|
+
* @returns Download Artifact Response
|
|
96
|
+
*/
|
|
97
|
+
downloadArtifact(
|
|
98
|
+
artifactId: number,
|
|
99
|
+
options?: DownloadArtifactOptions & FindOptions
|
|
100
|
+
): Promise<DownloadArtifactResponse>
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Deletes an artifact.
|
|
104
|
+
*
|
|
105
|
+
* If `options.findBy` is specified, this will use the public Delete Artifact
|
|
106
|
+
* API
|
|
107
|
+
*
|
|
108
|
+
* @param artifactName Artifact Name
|
|
109
|
+
* @param options Delete Artifact Options
|
|
110
|
+
* @returns Delete Artifact Response
|
|
111
|
+
*/
|
|
112
|
+
deleteArtifact(
|
|
113
|
+
artifactName: string,
|
|
114
|
+
options?: FindOptions
|
|
115
|
+
): Promise<DeleteArtifactResponse>
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Default artifact client that is used by the artifact action(s).
|
|
120
|
+
*/
|
|
121
|
+
export class DefaultArtifactClient implements ArtifactClient {
|
|
122
|
+
/**
|
|
123
|
+
* Uploads an artifact.
|
|
124
|
+
*
|
|
125
|
+
* @remarks
|
|
126
|
+
*
|
|
127
|
+
* - Adds a check for required environment variables.
|
|
128
|
+
*
|
|
129
|
+
* @param name Artifact Name
|
|
130
|
+
* @param files File(s) to Upload
|
|
131
|
+
* @param rootDirectory Root Directory
|
|
132
|
+
* @param options Upload Options
|
|
133
|
+
* @returns Upload Artifact Response
|
|
134
|
+
*/
|
|
135
|
+
async uploadArtifact(
|
|
136
|
+
name: string,
|
|
137
|
+
files: string[],
|
|
138
|
+
rootDirectory: string,
|
|
139
|
+
options?: UploadArtifactOptions
|
|
140
|
+
): Promise<UploadArtifactResponse> {
|
|
141
|
+
if (!process.env.LOCAL_ACTION_WORKSPACE)
|
|
142
|
+
throw new Error(
|
|
143
|
+
'LOCAL_ACTION_WORKSPACE must be set when interacting with @actions/artifact!'
|
|
144
|
+
)
|
|
145
|
+
if (!process.env.LOCAL_ACTION_ARTIFACT_PATH)
|
|
146
|
+
throw new Error(
|
|
147
|
+
'LOCAL_ACTION_ARTIFACT_PATH must be set when interacting with @actions/artifact!'
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
if (isGhes()) throw new GHESNotSupportedError()
|
|
152
|
+
|
|
153
|
+
return uploadArtifact(name, files, rootDirectory, options)
|
|
154
|
+
} catch (error) {
|
|
155
|
+
warning(
|
|
156
|
+
`Artifact upload failed with error: ${error}.
|
|
157
|
+
|
|
158
|
+
Errors can be temporary, so please try again and optionally run the action with debug mode enabled for more information.
|
|
159
|
+
|
|
160
|
+
If the error persists, please check whether Actions is operating normally at [https://githubstatus.com](https://www.githubstatus.com).`
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
throw error
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Downloads an artifact and unzips the content.
|
|
169
|
+
*
|
|
170
|
+
* If `options.findBy` is specified, this will use the public Download
|
|
171
|
+
* Artifact API.
|
|
172
|
+
*
|
|
173
|
+
* @remarks
|
|
174
|
+
*
|
|
175
|
+
* - Adds a check for required environment variables.
|
|
176
|
+
*
|
|
177
|
+
* @param artifactId Artifact ID
|
|
178
|
+
* @param options Download Artifact Options
|
|
179
|
+
* @returns Download Artifact Response
|
|
180
|
+
*/
|
|
181
|
+
async downloadArtifact(
|
|
182
|
+
artifactId: number,
|
|
183
|
+
options?: DownloadArtifactOptions & FindOptions
|
|
184
|
+
): Promise<DownloadArtifactResponse> {
|
|
185
|
+
if (!process.env.LOCAL_ACTION_WORKSPACE)
|
|
186
|
+
throw new Error(
|
|
187
|
+
'LOCAL_ACTION_WORKSPACE must be set when interacting with @actions/artifact!'
|
|
188
|
+
)
|
|
189
|
+
if (!process.env.LOCAL_ACTION_ARTIFACT_PATH)
|
|
190
|
+
throw new Error(
|
|
191
|
+
'LOCAL_ACTION_ARTIFACT_PATH must be set when interacting with @actions/artifact!'
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
try {
|
|
195
|
+
if (isGhes()) throw new GHESNotSupportedError()
|
|
196
|
+
|
|
197
|
+
if (options?.findBy) {
|
|
198
|
+
const {
|
|
199
|
+
findBy: { repositoryOwner, repositoryName, token },
|
|
200
|
+
...downloadOptions
|
|
201
|
+
} = options
|
|
202
|
+
|
|
203
|
+
return downloadArtifactPublic(
|
|
204
|
+
artifactId,
|
|
205
|
+
repositoryOwner,
|
|
206
|
+
repositoryName,
|
|
207
|
+
token,
|
|
208
|
+
downloadOptions
|
|
209
|
+
)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return downloadArtifactInternal(artifactId, options)
|
|
213
|
+
} catch (error) {
|
|
214
|
+
warning(
|
|
215
|
+
`Download Artifact failed with error: ${error}.
|
|
216
|
+
|
|
217
|
+
Errors can be temporary, so please try again and optionally run the action with debug mode enabled for more information.
|
|
218
|
+
|
|
219
|
+
If the error persists, please check whether Actions and API requests are operating normally at [https://githubstatus.com](https://www.githubstatus.com).`
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
throw error
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* List all artifacts for a workflow run.
|
|
228
|
+
*
|
|
229
|
+
* If `options.findBy` is specified, this will call the public List-Artifacts
|
|
230
|
+
* API which can list from other runs.
|
|
231
|
+
*
|
|
232
|
+
* @remarks
|
|
233
|
+
*
|
|
234
|
+
* - Adds a check for required environment variables.
|
|
235
|
+
*
|
|
236
|
+
* @param options Extra options that allow for the customization of the list behavior
|
|
237
|
+
* @returns ListArtifactResponse object
|
|
238
|
+
*/
|
|
239
|
+
async listArtifacts(
|
|
240
|
+
options?: ListArtifactsOptions & FindOptions
|
|
241
|
+
): Promise<ListArtifactsResponse> {
|
|
242
|
+
if (!process.env.LOCAL_ACTION_WORKSPACE)
|
|
243
|
+
throw new Error(
|
|
244
|
+
'LOCAL_ACTION_WORKSPACE must be set when interacting with @actions/artifact!'
|
|
245
|
+
)
|
|
246
|
+
if (!process.env.LOCAL_ACTION_ARTIFACT_PATH)
|
|
247
|
+
throw new Error(
|
|
248
|
+
'LOCAL_ACTION_ARTIFACT_PATH must be set when interacting with @actions/artifact!'
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
try {
|
|
252
|
+
if (isGhes()) throw new GHESNotSupportedError()
|
|
253
|
+
|
|
254
|
+
if (options?.findBy) {
|
|
255
|
+
const {
|
|
256
|
+
findBy: { workflowRunId, repositoryOwner, repositoryName, token }
|
|
257
|
+
} = options
|
|
258
|
+
|
|
259
|
+
return listArtifactsPublic(
|
|
260
|
+
workflowRunId,
|
|
261
|
+
repositoryOwner,
|
|
262
|
+
repositoryName,
|
|
263
|
+
token,
|
|
264
|
+
options?.latest
|
|
265
|
+
)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return listArtifactsInternal(options?.latest)
|
|
269
|
+
} catch (error: unknown) {
|
|
270
|
+
warning(
|
|
271
|
+
`Listing Artifacts failed with error: ${error}.
|
|
272
|
+
|
|
273
|
+
Errors can be temporary, so please try again and optionally run the action with debug mode enabled for more information.
|
|
274
|
+
|
|
275
|
+
If the error persists, please check whether Actions and API requests are operating normally at [https://githubstatus.com](https://www.githubstatus.com).`
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
throw error
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Finds an artifact by name.
|
|
284
|
+
*
|
|
285
|
+
* If there are multiple artifacts with the same name in the same workflow
|
|
286
|
+
* run, this will return the latest. If the artifact is not found, it will
|
|
287
|
+
* throw.
|
|
288
|
+
*
|
|
289
|
+
* If `options.findBy` is specified, this will use the public List Artifacts
|
|
290
|
+
* API with a name filter which can get artifacts from other runs.
|
|
291
|
+
*
|
|
292
|
+
* @remarks
|
|
293
|
+
*
|
|
294
|
+
* - Adds a check for required environment variables.
|
|
295
|
+
*
|
|
296
|
+
* @param artifactName Artifact Name
|
|
297
|
+
* @param options Get Artifact Options
|
|
298
|
+
* @returns Get Artifact Response
|
|
299
|
+
*/
|
|
300
|
+
async getArtifact(
|
|
301
|
+
artifactName: string,
|
|
302
|
+
options?: FindOptions
|
|
303
|
+
): Promise<GetArtifactResponse> {
|
|
304
|
+
if (!process.env.LOCAL_ACTION_WORKSPACE)
|
|
305
|
+
throw new Error(
|
|
306
|
+
'LOCAL_ACTION_WORKSPACE must be set when interacting with @actions/artifact!'
|
|
307
|
+
)
|
|
308
|
+
if (!process.env.LOCAL_ACTION_ARTIFACT_PATH)
|
|
309
|
+
throw new Error(
|
|
310
|
+
'LOCAL_ACTION_ARTIFACT_PATH must be set when interacting with @actions/artifact!'
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
try {
|
|
314
|
+
if (isGhes()) throw new GHESNotSupportedError()
|
|
315
|
+
|
|
316
|
+
if (options?.findBy) {
|
|
317
|
+
const {
|
|
318
|
+
findBy: { workflowRunId, repositoryOwner, repositoryName, token }
|
|
319
|
+
} = options
|
|
320
|
+
|
|
321
|
+
return getArtifactPublic(
|
|
322
|
+
artifactName,
|
|
323
|
+
workflowRunId,
|
|
324
|
+
repositoryOwner,
|
|
325
|
+
repositoryName,
|
|
326
|
+
token
|
|
327
|
+
)
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return getArtifactInternal(artifactName)
|
|
331
|
+
} catch (error: unknown) {
|
|
332
|
+
warning(
|
|
333
|
+
`Get Artifact failed with error: ${error}.
|
|
334
|
+
|
|
335
|
+
Errors can be temporary, so please try again and optionally run the action with debug mode enabled for more information.
|
|
336
|
+
|
|
337
|
+
If the error persists, please check whether Actions and API requests are operating normally at [https://githubstatus.com](https://www.githubstatus.com).`
|
|
338
|
+
)
|
|
339
|
+
throw error
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Deletes an artifact.
|
|
345
|
+
*
|
|
346
|
+
* If `options.findBy` is specified, this will use the public Delete Artifact
|
|
347
|
+
* API
|
|
348
|
+
*
|
|
349
|
+
* @remarks
|
|
350
|
+
*
|
|
351
|
+
* - Adds a check for required environment variables.
|
|
352
|
+
*
|
|
353
|
+
* @param artifactName Artifact Name
|
|
354
|
+
* @param options Delete Artifact Options
|
|
355
|
+
* @returns Delete Artifact Response
|
|
356
|
+
*/
|
|
357
|
+
async deleteArtifact(
|
|
358
|
+
artifactName: string,
|
|
359
|
+
options?: FindOptions
|
|
360
|
+
): Promise<DeleteArtifactResponse> {
|
|
361
|
+
if (!process.env.LOCAL_ACTION_WORKSPACE)
|
|
362
|
+
throw new Error(
|
|
363
|
+
'LOCAL_ACTION_WORKSPACE must be set when interacting with @actions/artifact!'
|
|
364
|
+
)
|
|
365
|
+
if (!process.env.LOCAL_ACTION_ARTIFACT_PATH)
|
|
366
|
+
throw new Error(
|
|
367
|
+
'LOCAL_ACTION_ARTIFACT_PATH must be set when interacting with @actions/artifact!'
|
|
368
|
+
)
|
|
369
|
+
|
|
370
|
+
try {
|
|
371
|
+
if (isGhes()) throw new GHESNotSupportedError()
|
|
372
|
+
|
|
373
|
+
if (options?.findBy) {
|
|
374
|
+
const {
|
|
375
|
+
findBy: { repositoryOwner, repositoryName, workflowRunId, token }
|
|
376
|
+
} = options
|
|
377
|
+
|
|
378
|
+
return deleteArtifactPublic(
|
|
379
|
+
artifactName,
|
|
380
|
+
workflowRunId,
|
|
381
|
+
repositoryOwner,
|
|
382
|
+
repositoryName,
|
|
383
|
+
token
|
|
384
|
+
)
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
return deleteArtifactInternal(artifactName)
|
|
388
|
+
} catch (error) {
|
|
389
|
+
warning(
|
|
390
|
+
`Delete Artifact failed with error: ${error}.
|
|
391
|
+
|
|
392
|
+
Errors can be temporary, so please try again and optionally run the action with debug mode enabled for more information.
|
|
393
|
+
|
|
394
|
+
If the error persists, please check whether Actions and API requests are operating normally at [https://githubstatus.com](https://www.githubstatus.com).`
|
|
395
|
+
)
|
|
396
|
+
|
|
397
|
+
throw error
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Last Reviewed Commit: 2f5fb3f92b71b303a20d6b74fbc64dc64f3e32d8
|
|
3
|
+
* Last Reviewed Date: 2026-01-16
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { OctokitOptions } from '@octokit/core'
|
|
7
|
+
import { requestLog } from '@octokit/plugin-request-log'
|
|
8
|
+
import { retry } from '@octokit/plugin-retry'
|
|
9
|
+
import fs from 'fs'
|
|
10
|
+
import path from 'path'
|
|
11
|
+
import { EnvMeta } from '../../../../stubs/env.js'
|
|
12
|
+
import { getOctokit } from '../../../../stubs/github/github.js'
|
|
13
|
+
import * as core from '../../../core/core.js'
|
|
14
|
+
import { defaults as defaultGitHubOptions } from '../../../github/utils.js'
|
|
15
|
+
import { getArtifactPublic } from '../find/get-artifact.js'
|
|
16
|
+
import { getRetryOptions } from '../find/retry-options.js'
|
|
17
|
+
import {
|
|
18
|
+
ArtifactNotFoundError,
|
|
19
|
+
InvalidResponseError
|
|
20
|
+
} from '../shared/errors.js'
|
|
21
|
+
import type { Artifact, DeleteArtifactResponse } from '../shared/interfaces.js'
|
|
22
|
+
import { getUserAgentString } from '../shared/user-agent.js'
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Deletes artifacts from GitHub.
|
|
26
|
+
*
|
|
27
|
+
* @param artifactName Artifact Name
|
|
28
|
+
* @param workflowRunId Workflow Run ID
|
|
29
|
+
* @param repositoryOwner Repository Owner
|
|
30
|
+
* @param repositoryName Repository Name
|
|
31
|
+
* @param token GitHub Token
|
|
32
|
+
* @returns Delete Artifact Response
|
|
33
|
+
*/
|
|
34
|
+
export async function deleteArtifactPublic(
|
|
35
|
+
artifactName: string,
|
|
36
|
+
workflowRunId: number,
|
|
37
|
+
repositoryOwner: string,
|
|
38
|
+
repositoryName: string,
|
|
39
|
+
token: string
|
|
40
|
+
): Promise<DeleteArtifactResponse> {
|
|
41
|
+
const [retryOpts, requestOpts] = getRetryOptions(defaultGitHubOptions)
|
|
42
|
+
|
|
43
|
+
const opts: OctokitOptions = {
|
|
44
|
+
log: undefined,
|
|
45
|
+
userAgent: getUserAgentString(),
|
|
46
|
+
previews: undefined,
|
|
47
|
+
retry: retryOpts,
|
|
48
|
+
request: requestOpts
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const github = getOctokit(token, opts, retry as any, requestLog as any)
|
|
52
|
+
|
|
53
|
+
const getArtifactResp = await getArtifactPublic(
|
|
54
|
+
artifactName,
|
|
55
|
+
workflowRunId,
|
|
56
|
+
repositoryOwner,
|
|
57
|
+
repositoryName,
|
|
58
|
+
token
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
const deleteArtifactResp = await github.rest.actions.deleteArtifact({
|
|
62
|
+
owner: repositoryOwner,
|
|
63
|
+
repo: repositoryName,
|
|
64
|
+
artifact_id: getArtifactResp.artifact.id
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
if (deleteArtifactResp.status !== 204)
|
|
68
|
+
throw new InvalidResponseError(
|
|
69
|
+
`Invalid response from GitHub API: ${deleteArtifactResp.status} (${deleteArtifactResp?.headers?.['x-github-request-id']})`
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
id: getArtifactResp.artifact.id
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
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
|
|
86
|
+
*/
|
|
87
|
+
export async function deleteArtifactInternal(
|
|
88
|
+
artifactName: string
|
|
89
|
+
): Promise<DeleteArtifactResponse> {
|
|
90
|
+
// Check the current list of artifacts for one with a matching name, sorted by
|
|
91
|
+
// most recent (highest ID).
|
|
92
|
+
const artifacts: Artifact[] = EnvMeta.artifacts
|
|
93
|
+
.filter((artifact: Artifact) => artifact.name === artifactName)
|
|
94
|
+
.sort((a, b) => Number(b.id) - Number(a.id))
|
|
95
|
+
|
|
96
|
+
if (artifacts.length === 0)
|
|
97
|
+
throw new ArtifactNotFoundError(
|
|
98
|
+
`Artifact not found for name: ${artifactName}`
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
if (artifacts.length > 1)
|
|
102
|
+
core.debug(
|
|
103
|
+
`More than one artifact found for a single name, returning newest (id: ${artifacts[0].id})`
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
const id = artifacts[0].id
|
|
107
|
+
|
|
108
|
+
// Delete the artifact from the filesystem.
|
|
109
|
+
fs.rmSync(
|
|
110
|
+
path.join(
|
|
111
|
+
process.env.LOCAL_ACTION_ARTIFACT_PATH!,
|
|
112
|
+
`${artifacts[0].name}.zip`
|
|
113
|
+
)
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
// Remove the artifact from the list of artifacts.
|
|
117
|
+
EnvMeta.artifacts = EnvMeta.artifacts.filter(
|
|
118
|
+
(artifact: Artifact) => artifact.id !== id
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
core.info(`Artifact '${artifactName}' (ID: ${id}) deleted`)
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
id
|
|
125
|
+
}
|
|
126
|
+
}
|