Skip to content

Commit fecfb01

Browse files
committed
Migrate TS types
1 parent e52ba25 commit fecfb01

File tree

4 files changed

+1032
-74
lines changed

4 files changed

+1032
-74
lines changed

src/manageArtifacts.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import * as core from '@actions/core';
1010
import { VariableDetail, VariableStatus } from './types/variableStatus';
1111
import { WORKDIR } from './config';
1212
import rimraf from 'rimraf';
13-
import { ArtifactClient, UploadOptions } from '@actions/artifact';
14-
import { UploadResponse } from '@actions/artifact/lib/internal/upload-response';
13+
import { ArtifactClient } from '@actions/artifact';
14+
import { UploadInputs } from './types/upload-artifact/upload-inputs';
1515

1616
// eslint-disable-next-line @typescript-eslint/no-var-requires
1717
const artifact = require('@actions/artifact');
@@ -45,10 +45,11 @@ const defineVariableOperation = (variable: string): VariableStatus => {
4545

4646
const storeArtifact = async (variables: VariableDetail[], failIfNotFound: boolean): Promise<void> => {
4747
const client: ArtifactClient = artifact.create();
48-
const artifactOptions: UploadOptions = {
48+
const artifactOptions: Partial<UploadInputs> = {
4949
retentionDays: 1, // Only keep artifacts 1 day to avoid reach limit: https://github.com/actions/toolkit/blob/c861dd8859fe5294289fcada363ce9bc71e9d260/packages/artifact/src/internal/upload-options.ts#L1
5050
};
51-
const artifactsUploadPromises: Promise<UploadResponse>[] = [];
51+
// Used to be able to use type "UploadResponse" but it's not exported by the lib in v2 anymore
52+
const artifactsUploadPromises: Promise<any>[] = [];
5253

5354
rimraf.sync(WORKDIR);
5455
mkdirSync(WORKDIR);
@@ -83,6 +84,7 @@ const retrieveArtifact = async (variables: VariableDetail[], failIfNotFound: boo
8384
for (const variable of variables) {
8485
try {
8586
const file = join(WORKDIR, `${variable.key}.txt`);
87+
// @ts-ignore
8688
await client.downloadArtifact(variable.key);
8789
variable.value = readFileSync(file, { encoding: 'utf8' }).toString();
8890
core.exportVariable(variable.key, variable.value);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* eslint-disable no-unused-vars */
2+
export enum Inputs {
3+
Name = 'name',
4+
Path = 'path',
5+
IfNoFilesFound = 'if-no-files-found',
6+
RetentionDays = 'retention-days',
7+
CompressionLevel = 'compression-level',
8+
Overwrite = 'overwrite',
9+
IncludeHiddenFiles = 'include-hidden-files'
10+
}
11+
12+
export enum NoFileOptions {
13+
/**
14+
* Default. Output a warning but do not fail the action
15+
*/
16+
warn = 'warn',
17+
18+
/**
19+
* Fail the action with an error message
20+
*/
21+
error = 'error',
22+
23+
/**
24+
* Do not output any warnings or errors, the action does not fail
25+
*/
26+
ignore = 'ignore'
27+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { NoFileOptions } from "./constants"
2+
3+
/**
4+
* Copied from https://github.com/actions/upload-artifact/blob/65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08/src/upload/upload-inputs.ts#L22
5+
*/
6+
export interface UploadInputs {
7+
/**
8+
* The name of the artifact that will be uploaded
9+
*/
10+
artifactName: string
11+
12+
/**
13+
* The search path used to describe what to upload as part of the artifact
14+
*/
15+
searchPath: string
16+
17+
/**
18+
* The desired behavior if no files are found with the provided search path
19+
*/
20+
ifNoFilesFound: NoFileOptions
21+
22+
/**
23+
* Duration after which artifact will expire in days
24+
*/
25+
retentionDays: number
26+
27+
/**
28+
* The level of compression for Zlib to be applied to the artifact archive.
29+
*/
30+
compressionLevel?: number
31+
32+
/**
33+
* Whether or not to replace an existing artifact with the same name
34+
*/
35+
overwrite: boolean
36+
37+
/**
38+
* Whether or not to include hidden files in the artifact
39+
*/
40+
includeHiddenFiles: boolean
41+
}

0 commit comments

Comments
 (0)