1
- import { constants as fsConstants } from "node:fs" ;
2
- import { open as fsOpen , type FileHandle } from "node:fs/promises" ;
3
- import { DefaultArtifactClient as GitHubActionsArtifactClient , type ListArtifactsResponse as GitHubActionsArtifactListResponse , type DownloadArtifactResponse as GitHubActionsArtifactDownloadResponse , type UploadArtifactResponse as GitHubActionsArtifactUploadResponse , type GetArtifactResponse as GitHubActionsArtifactGetResponse } from "@actions/artifact" ;
4
- import { restoreCache as ghactionsCacheRestoreCache , saveCache as ghactionsCacheSaveCache } from "@actions/cache" ;
5
- import { debug as ghactionsDebug , getIDToken as ghactionsGetOpenIDConnectToken } from "@actions/core" ;
6
- import { cacheDir as ghactionsToolCacheCacheDirectory , cacheFile as ghactionsToolCacheCacheFile , downloadTool as ghactionsToolCacheDownloadTool , extract7z as ghactionsToolCacheExtract7z , extractTar as ghactionsToolCacheExtractTar , extractXar as ghactionsToolCacheExtractXar , extractZip as ghactionsToolCacheExtractZip , find as ghactionsToolCacheFind , findAllVersions as ghactionsToolCacheFindAllVersions } from "@actions/tool-cache" ;
7
- const exchangeFileHandle : FileHandle = await fsOpen ( process . argv [ 2 ] , fsConstants . O_RDWR | fsConstants . O_NOFOLLOW ) ;
8
- const input = JSON . parse ( await exchangeFileHandle . readFile ( { encoding : "utf8" } ) ) ;
9
- async function exchangeFileWrite ( data : Record < string , unknown > ) : Promise < void > {
10
- await exchangeFileHandle . truncate ( 0 ) ;
11
- return exchangeFileHandle . writeFile ( JSON . stringify ( data ) , { encoding : "utf8" } ) ;
1
+ import fs from "node:fs" ;
2
+ import ghactionsArtifact from "@actions/artifact" ;
3
+ import ghactionsCache from "@actions/cache" ;
4
+ import ghactionsCore from "@actions/core" ;
5
+ import ghactionsToolCache from "@actions/tool-cache" ;
6
+ const exchangeFilePath : string = process . argv [ 2 ] ;
7
+ const input = JSON . parse ( fs . readFileSync ( exchangeFilePath , { encoding : "utf-8" } ) ) ;
8
+ function exchangeFileWrite ( data : Record < string , unknown > ) : void {
9
+ return fs . writeFileSync ( exchangeFilePath , JSON . stringify ( data ) , { encoding : "utf8" } ) ;
12
10
}
13
- function resolveFail ( reason : string | Error | RangeError | ReferenceError | SyntaxError | TypeError ) : Promise < void > {
11
+ function resolveFail ( reason : string | Error | RangeError | ReferenceError | SyntaxError | TypeError ) : void {
14
12
const output : Record < string , unknown > = {
15
13
isSuccess : false
16
14
} ;
@@ -25,172 +23,173 @@ function resolveFail(reason: string | Error | RangeError | ReferenceError | Synt
25
23
}
26
24
return exchangeFileWrite ( output ) ;
27
25
}
28
- function resolveSuccess ( result : unknown ) : Promise < void > {
26
+ function resolveSuccess ( result : unknown ) : void {
29
27
return exchangeFileWrite ( {
30
28
isSuccess : true ,
31
29
result
32
30
} ) ;
33
31
}
34
- switch ( input . $name ) {
35
- case "debug/fail" :
36
- ghactionsDebug ( input ?. message ?? "" ) ;
37
- await resolveFail ( "This is a fail." ) ;
38
- break ;
39
- case "debug/success" :
40
- ghactionsDebug ( input ?. message ?? "" ) ;
41
- await resolveSuccess ( "This is a success" ) ;
42
- break ;
43
- case "artifact/download" :
44
- try {
45
- const result : GitHubActionsArtifactDownloadResponse = await new GitHubActionsArtifactClient ( ) . downloadArtifact ( input . id , {
46
- findBy : input . findBy ,
47
- path : input . path
48
- } ) ;
49
- await resolveSuccess ( {
50
- path : result . downloadPath
51
- } ) ;
52
- } catch ( error ) {
53
- await resolveFail ( error ) ;
54
- }
55
- break ;
56
- case "artifact/get" :
57
- try {
58
- const result : GitHubActionsArtifactGetResponse = await new GitHubActionsArtifactClient ( ) . getArtifact ( input . name , { findBy : input . findBy } ) ;
59
- await resolveSuccess ( result . artifact ) ;
60
- } catch ( error ) {
61
- await resolveFail ( error ) ;
62
- }
63
- break ;
64
- case "artifact/list" :
65
- try {
66
- const result : GitHubActionsArtifactListResponse = await new GitHubActionsArtifactClient ( ) . listArtifacts ( {
67
- findBy : input . findBy ,
68
- latest : input . latest
69
- } ) ;
70
- await resolveSuccess ( result . artifacts ) ;
71
- } catch ( error ) {
72
- await resolveFail ( error ) ;
73
- }
74
- break ;
75
- case "artifact/upload" :
76
- try {
77
- const result : GitHubActionsArtifactUploadResponse = await new GitHubActionsArtifactClient ( ) . uploadArtifact ( input . name , input . items , input . rootDirectory , {
78
- compressionLevel : input . compressionLevel ,
79
- retentionDays : input . retentionDays
80
- } ) ;
81
- await resolveSuccess ( result ) ;
82
- } catch ( error ) {
83
- await resolveFail ( error ) ;
84
- }
85
- break ;
86
- case "cache/restore" :
87
- try {
88
- const result : string | undefined = await ghactionsCacheRestoreCache ( input . paths , input . primaryKey , input . restoreKeys , {
89
- concurrentBlobDownloads : input . concurrencyBlobDownload ,
90
- downloadConcurrency : input . downloadConcurrency ,
91
- lookupOnly : input . lookup ,
92
- segmentTimeoutInMs : input . segmentTimeout ,
93
- timeoutInMs : input . timeout ,
94
- useAzureSdk : input . useAzureSdk
95
- } ) ;
96
- await resolveSuccess ( result ?? null ) ;
97
- } catch ( error ) {
98
- await resolveFail ( error ) ;
99
- }
100
- break ;
101
- case "cache/save" :
102
- try {
103
- const result : number = await ghactionsCacheSaveCache ( input . paths , input . key , {
104
- uploadChunkSize : input . uploadChunkSize ,
105
- uploadConcurrency : input . uploadConcurrency
106
- } ) ;
107
- await resolveSuccess ( result ) ;
108
- } catch ( error ) {
109
- await resolveFail ( error ) ;
110
- }
111
- break ;
112
- case "open-id-connect/get-token" :
113
- try {
114
- const result : string = await ghactionsGetOpenIDConnectToken ( input . audience ) ;
115
- await resolveSuccess ( result ) ;
116
- } catch ( error ) {
117
- await resolveFail ( error ) ;
118
- }
119
- break ;
120
- case "tool-cache/cache-directory" :
121
- try {
122
- const result : string = await ghactionsToolCacheCacheDirectory ( input . source , input . name , input . version , input . architecture ) ;
123
- await resolveSuccess ( result ) ;
124
- } catch ( error ) {
125
- await resolveFail ( error ) ;
126
- }
127
- break ;
128
- case "tool-cache/cache-file" :
129
- try {
130
- const result : string = await ghactionsToolCacheCacheFile ( input . source , input . target , input . name , input . version , input . architecture ) ;
131
- await resolveSuccess ( result ) ;
132
- } catch ( error ) {
133
- await resolveFail ( error ) ;
134
- }
135
- break ;
136
- case "tool-cache/download-tool" :
137
- try {
138
- const result : string = await ghactionsToolCacheDownloadTool ( input . url , input . destination , input . authorization , input . headers ) ;
139
- await resolveSuccess ( result ) ;
140
- } catch ( error ) {
141
- await resolveFail ( error ) ;
142
- }
143
- break ;
144
- case "tool-cache/extract-7z" :
145
- try {
146
- const result : string = await ghactionsToolCacheExtract7z ( input . file , input . destination , input [ "7zrPath" ] ) ;
147
- await resolveSuccess ( result ) ;
148
- } catch ( error ) {
149
- await resolveFail ( error ) ;
150
- }
151
- break ;
152
- case "tool-cache/extract-tar" :
153
- try {
154
- const result : string = await ghactionsToolCacheExtractTar ( input . file , input . destination , input . flags ) ;
155
- await resolveSuccess ( result ) ;
156
- } catch ( error ) {
157
- await resolveFail ( error ) ;
158
- }
159
- break ;
160
- case "tool-cache/extract-xar" :
161
- try {
162
- const result : string = await ghactionsToolCacheExtractXar ( input . file , input . destination , input . flags ) ;
163
- await resolveSuccess ( result ) ;
164
- } catch ( error ) {
165
- await resolveFail ( error ) ;
166
- }
167
- break ;
168
- case "tool-cache/extract-zip" :
169
- try {
170
- const result : string = await ghactionsToolCacheExtractZip ( input . file , input . destination ) ;
171
- await resolveSuccess ( result ) ;
172
- } catch ( error ) {
173
- await resolveFail ( error ) ;
174
- }
175
- break ;
176
- case "tool-cache/find" :
177
- try {
178
- const result : string = ghactionsToolCacheFind ( input . name , input . version , input . architecture ) ;
179
- await resolveSuccess ( result ) ;
180
- } catch ( error ) {
181
- await resolveFail ( error ) ;
182
- }
183
- break ;
184
- case "tool-cache/find-all-versions" :
185
- try {
186
- const result : string [ ] = ghactionsToolCacheFindAllVersions ( input . name , input . architecture ) ;
187
- await resolveSuccess ( result ) ;
188
- } catch ( error ) {
189
- await resolveFail ( error ) ;
190
- }
191
- break ;
192
- default :
193
- await resolveFail ( `\`${ input . wrapperName } \` is not a valid NodeJS wrapper name! Most likely a mistake made by the contributors, please report this issue.` ) ;
194
- break ;
195
- }
196
- await exchangeFileHandle . close ( ) ;
32
+ ( async ( ) => {
33
+ switch ( input . $name ) {
34
+ case "debug/fail" :
35
+ ghactionsCore . debug ( input ?. message ?? "" ) ;
36
+ resolveFail ( "This is a fail." ) ;
37
+ break ;
38
+ case "debug/success" :
39
+ ghactionsCore . debug ( input ?. message ?? "" ) ;
40
+ resolveSuccess ( "This is a success" ) ;
41
+ break ;
42
+ case "artifact/download" :
43
+ try {
44
+ const result = await ghactionsArtifact . downloadArtifact ( input . id , {
45
+ findBy : input . findBy ,
46
+ path : input . path
47
+ } ) ;
48
+ resolveSuccess ( {
49
+ path : result . downloadPath
50
+ } ) ;
51
+ } catch ( error ) {
52
+ resolveFail ( error ) ;
53
+ }
54
+ break ;
55
+ case "artifact/get" :
56
+ try {
57
+ const result = await ghactionsArtifact . getArtifact ( input . name , { findBy : input . findBy } ) ;
58
+ resolveSuccess ( result . artifact ) ;
59
+ } catch ( error ) {
60
+ resolveFail ( error ) ;
61
+ }
62
+ break ;
63
+ case "artifact/list" :
64
+ try {
65
+ const result = await ghactionsArtifact . listArtifacts ( {
66
+ findBy : input . findBy ,
67
+ latest : input . latest
68
+ } ) ;
69
+ resolveSuccess ( result . artifacts ) ;
70
+ } catch ( error ) {
71
+ resolveFail ( error ) ;
72
+ }
73
+ break ;
74
+ case "artifact/upload" :
75
+ try {
76
+ const result = await ghactionsArtifact . uploadArtifact ( input . name , input . items , input . rootDirectory , {
77
+ compressionLevel : input . compressionLevel ,
78
+ retentionDays : input . retentionDays
79
+ } ) ;
80
+ resolveSuccess ( result ) ;
81
+ } catch ( error ) {
82
+ resolveFail ( error ) ;
83
+ }
84
+ break ;
85
+ case "cache/restore" :
86
+ try {
87
+ const result : string | undefined = await ghactionsCache . restoreCache ( input . paths , input . primaryKey , input . restoreKeys , {
88
+ concurrentBlobDownloads : input . concurrencyBlobDownload ,
89
+ downloadConcurrency : input . downloadConcurrency ,
90
+ lookupOnly : input . lookup ,
91
+ segmentTimeoutInMs : input . segmentTimeout ,
92
+ timeoutInMs : input . timeout ,
93
+ useAzureSdk : input . useAzureSdk
94
+ } ) ;
95
+ resolveSuccess ( result ?? null ) ;
96
+ } catch ( error ) {
97
+ resolveFail ( error ) ;
98
+ }
99
+ break ;
100
+ case "cache/save" :
101
+ try {
102
+ const result : number = await ghactionsCache . saveCache ( input . paths , input . key , {
103
+ uploadChunkSize : input . uploadChunkSize ,
104
+ uploadConcurrency : input . uploadConcurrency
105
+ } ) ;
106
+ resolveSuccess ( result ) ;
107
+ } catch ( error ) {
108
+ resolveFail ( error ) ;
109
+ }
110
+ break ;
111
+ case "open-id-connect/get-token" :
112
+ try {
113
+ const result : string = await ghactionsCore . getIDToken ( input . audience ) ;
114
+ resolveSuccess ( result ) ;
115
+ } catch ( error ) {
116
+ resolveFail ( error ) ;
117
+ }
118
+ break ;
119
+ case "tool-cache/cache-directory" :
120
+ try {
121
+ const result : string = await ghactionsToolCache . cacheDir ( input . source , input . name , input . version , input . architecture ) ;
122
+ resolveSuccess ( result ) ;
123
+ } catch ( error ) {
124
+ resolveFail ( error ) ;
125
+ }
126
+ break ;
127
+ case "tool-cache/cache-file" :
128
+ try {
129
+ const result : string = await ghactionsToolCache . cacheFile ( input . source , input . target , input . name , input . version , input . architecture ) ;
130
+ resolveSuccess ( result ) ;
131
+ } catch ( error ) {
132
+ resolveFail ( error ) ;
133
+ }
134
+ break ;
135
+ case "tool-cache/download-tool" :
136
+ try {
137
+ const result : string = await ghactionsToolCache . downloadTool ( input . url , input . destination , input . authorization , input . headers ) ;
138
+ resolveSuccess ( result ) ;
139
+ } catch ( error ) {
140
+ resolveFail ( error ) ;
141
+ }
142
+ break ;
143
+ case "tool-cache/extract-7z" :
144
+ try {
145
+ const result : string = await ghactionsToolCache . extract7z ( input . file , input . destination , input [ "7zrPath" ] ) ;
146
+ resolveSuccess ( result ) ;
147
+ } catch ( error ) {
148
+ resolveFail ( error ) ;
149
+ }
150
+ break ;
151
+ case "tool-cache/extract-tar" :
152
+ try {
153
+ const result : string = await ghactionsToolCache . extractTar ( input . file , input . destination , input . flags ) ;
154
+ resolveSuccess ( result ) ;
155
+ } catch ( error ) {
156
+ resolveFail ( error ) ;
157
+ }
158
+ break ;
159
+ case "tool-cache/extract-xar" :
160
+ try {
161
+ const result : string = await ghactionsToolCache . extractXar ( input . file , input . destination , input . flags ) ;
162
+ resolveSuccess ( result ) ;
163
+ } catch ( error ) {
164
+ resolveFail ( error ) ;
165
+ }
166
+ break ;
167
+ case "tool-cache/extract-zip" :
168
+ try {
169
+ const result : string = await ghactionsToolCache . extractZip ( input . file , input . destination ) ;
170
+ resolveSuccess ( result ) ;
171
+ } catch ( error ) {
172
+ resolveFail ( error ) ;
173
+ }
174
+ break ;
175
+ case "tool-cache/find" :
176
+ try {
177
+ const result : string = ghactionsToolCache . find ( input . name , input . version , input . architecture ) ;
178
+ resolveSuccess ( result ) ;
179
+ } catch ( error ) {
180
+ resolveFail ( error ) ;
181
+ }
182
+ break ;
183
+ case "tool-cache/find-all-versions" :
184
+ try {
185
+ const result : string [ ] = ghactionsToolCache . findAllVersions ( input . name , input . architecture ) ;
186
+ resolveSuccess ( result ) ;
187
+ } catch ( error ) {
188
+ resolveFail ( error ) ;
189
+ }
190
+ break ;
191
+ default :
192
+ resolveFail ( `\`${ input . wrapperName } \` is not a valid NodeJS wrapper name! Most likely a mistake made by the contributors, please report this issue.` ) ;
193
+ break ;
194
+ }
195
+ } ) ( ) ;
0 commit comments