@noldova/tools.pipelines.github 0.0.1 → 0.0.3
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/README.md +34 -2
- package/api/index.d.ts +125 -12
- package/api/index.js +1 -0
- package/api/index.js.map +1 -1
- package/models/github-answer.js +22 -2
- package/models/github-answer.js.map +1 -1
- package/package.json +3 -3
- package/resources.js +39 -0
- package/resources.js.map +1 -1
- package/services/github-api.js +63 -0
- package/services/github-api.js.map +1 -0
- package/services/github-packages.js +87 -0
- package/services/github-packages.js.map +1 -0
- package/services/github-tags.js +14 -14
- package/services/github-tags.js.map +1 -1
- package/services/pipelines-program.js +3 -2
- package/services/pipelines-program.js.map +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @noldova/tools.pipelines.github
|
|
2
2
|
|
|
3
3
|
Runs the steps of `@noldova/tools.pipelines` on GitHub Actions.
|
|
4
|
-
This version holds `pipelines`, the command line a workflow calls, with the source, archive, publish, nightly
|
|
4
|
+
This version holds `pipelines`, the command line a workflow calls, with the source, archive, publish, nightly, prune, tag, toolchain, line-endings, unchanged and reproducible steps, and the prune and tag steps' access to GitHub's REST API.
|
|
5
5
|
|
|
6
6
|
## Install
|
|
7
7
|
|
|
@@ -16,7 +16,7 @@ npm install @noldova/tools.pipelines.github
|
|
|
16
16
|
A job installs the package at an exact version, without install scripts, and calls `pipelines` with a step's name and values in the checkout:
|
|
17
17
|
|
|
18
18
|
```yaml
|
|
19
|
-
- run: npm install --global --ignore-scripts @noldova/tools.pipelines.github@0.0.
|
|
19
|
+
- run: npm install --global --ignore-scripts @noldova/tools.pipelines.github@0.0.3
|
|
20
20
|
- run: pipelines source "$VERSION" "$COMMIT"
|
|
21
21
|
- id: nightly
|
|
22
22
|
run: |
|
|
@@ -30,9 +30,15 @@ A job installs the package at an exact version, without install scripts, and cal
|
|
|
30
30
|
| `archive` | `<folder> <version> <commit> <scope>` |
|
|
31
31
|
| `publish` | `<folder> <version> <commit> <scope> <registry> <access>` |
|
|
32
32
|
| `nightly` | `<commit> <registry>` |
|
|
33
|
+
| `prune` | `<version> <commit> <scope> <registry> <keep-versions>` |
|
|
33
34
|
| `tag` | `<version> <commit>` |
|
|
35
|
+
| `toolchain` | `<node-version> [<npm-version>]` |
|
|
36
|
+
| `line-endings` | none |
|
|
37
|
+
| `unchanged` | none |
|
|
38
|
+
| `reproducible` | `<folder>` |
|
|
34
39
|
|
|
35
40
|
`@noldova/tools.pipelines`'s README says what each step checks and does.
|
|
41
|
+
The reproducible step makes its temporary folder in `RUNNER_TEMP`, which the runner empties after each job, cancelled ones included.
|
|
36
42
|
|
|
37
43
|
- A step that succeeds writes its message to standard output and exits with code `0`; an empty message, such as the nightly step's when nothing changed, writes nothing.
|
|
38
44
|
- A step that fails writes its message as one error annotation, which the run's summary shows, and exits with code `1`; so does a first value that names no step, with the usage line of every step.
|
|
@@ -53,6 +59,32 @@ It reads `GITHUB_API_URL` and `GITHUB_REPOSITORY`, which GitHub Actions sets, an
|
|
|
53
59
|
The job needs `permissions: contents: write`.
|
|
54
60
|
The step fails, naming the variable, when one is missing or empty, and with the request, the status and GitHub's message for an answer it doesn't expect, such as a missing permission.
|
|
55
61
|
|
|
62
|
+
### The prune step
|
|
63
|
+
|
|
64
|
+
`pipelines prune <version> <commit> <scope> <registry> <keep-versions>` deletes each package's older release versions on GitHub Packages, `https://npm.pkg.github.com/`, keeping the newest `<keep-versions>`; for any other registry it fails and deletes nothing.
|
|
65
|
+
A package `@<owner>/<name>` is the npm package `<name>` of the organization `<owner>`, so the scope is the organization's.
|
|
66
|
+
It runs in a checkout of the commit, and reads `GITHUB_API_URL`, which GitHub Actions sets, and `GITHUB_TOKEN`, which the workflow passes in; the token needs to delete the packages' versions, and is never written anywhere:
|
|
67
|
+
|
|
68
|
+
```yaml
|
|
69
|
+
- env:
|
|
70
|
+
GITHUB_TOKEN: ${{ github.token }}
|
|
71
|
+
run: pipelines prune "$VERSION" "$COMMIT" @noldova-com https://npm.pkg.github.com/ 5
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The job needs `permissions: packages: write`, and, since the step deletes, an environment whose reviewers approve each run.
|
|
75
|
+
The step fails, naming the variable, when one is missing or empty, and with the request, the status and GitHub's message for an answer it doesn't expect, such as GitHub refusing to delete a package's last version.
|
|
76
|
+
A 404 to a delete counts as a version already deleted only when GitHub's list no longer has it; otherwise the step fails.
|
|
77
|
+
|
|
78
|
+
### When GitHub is briefly unavailable
|
|
79
|
+
|
|
80
|
+
The prune and tag steps send a request again, up to two more times, waiting 5 and then 15 seconds, when GitHub answers 502, 503 or 504, doesn't answer within a minute, or the connection fails.
|
|
81
|
+
A failing answer with a `Retry-After` header of up to 60 seconds is sent again too, after that wait, such as a 403 for a rate limit.
|
|
82
|
+
Any other answer comes back at once, such as a 403 or 404 without that header, or any answer with a longer `Retry-After`.
|
|
83
|
+
The last answer, timeout or failed connection is what the step reports, naming the request.
|
|
84
|
+
These retries count per request, and nothing bounds a step's requests together, so the job's `timeout-minutes` is the bound; since a request can be sent twice, a rerun is safe.
|
|
85
|
+
|
|
86
|
+
A create or delete that GitHub carried out but whose answer was lost is sent again, and is done, not a failure: the tag step finds the tag at the commit after GitHub refuses the second create, and the prune step reports the version as already deleted after a 404 and a new list without it.
|
|
87
|
+
|
|
56
88
|
### From code
|
|
57
89
|
|
|
58
90
|
```ts
|
package/api/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type { IStepOutput, ITagHost, StepResult } from "@noldova/tools.pipelines";
|
|
9
|
+
import type { IRegistryHost, IStepOutput, ITagHost, StepResult } from "@noldova/tools.pipelines";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Writes a step's messages as a GitHub Actions job reads them: a success to
|
|
@@ -66,6 +66,104 @@ export declare class GitHubStepOutput implements IStepOutput {
|
|
|
66
66
|
public writeFailure(message: string): void;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* GitHub Packages' npm registry, `https://npm.pkg.github.com/`, through
|
|
71
|
+
* GitHub's REST API, as the prune step of `@noldova/tools.pipelines` lists
|
|
72
|
+
* and deletes a package's versions.
|
|
73
|
+
*
|
|
74
|
+
* A package `@<owner>/<name>` is the npm package `<name>` of the
|
|
75
|
+
* organization `<owner>`. It reaches the API with two environment
|
|
76
|
+
* variables: `GITHUB_API_URL`, which GitHub Actions sets in a job, such as
|
|
77
|
+
* `https://api.github.com`, and `GITHUB_TOKEN`, a token that may delete the
|
|
78
|
+
* packages, with `packages: write`, which the workflow passes in. It sends
|
|
79
|
+
* the token only to that API and never writes it anywhere.
|
|
80
|
+
*
|
|
81
|
+
* A request GitHub answers 502, 503 or 504, doesn't answer within the
|
|
82
|
+
* timeout, or loses the connection of, is sent again up to two more times,
|
|
83
|
+
* after 5 and then 15 seconds. A failing answer with a `Retry-After` header
|
|
84
|
+
* of up to 60 seconds is too, after that wait; one with a longer
|
|
85
|
+
* `Retry-After` is not, whatever its status. The last answer, timeout or
|
|
86
|
+
* lost connection is what the call gives.
|
|
87
|
+
*/
|
|
88
|
+
export declare class GitHubPackages implements IRegistryHost {
|
|
89
|
+
/**
|
|
90
|
+
* The registry it lists and deletes versions on,
|
|
91
|
+
* `"https://npm.pkg.github.com/"`.
|
|
92
|
+
*/
|
|
93
|
+
public readonly registry: string;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Creates the packages over an environment, which it reads at each call.
|
|
97
|
+
*
|
|
98
|
+
* @param environment The environment variables, such as `process.env`.
|
|
99
|
+
* @param timeoutMilliseconds How long it waits for each answer of the API.
|
|
100
|
+
* Omitted, it waits a minute.
|
|
101
|
+
* @param waitAsync How it waits before sending a request again, given the
|
|
102
|
+
* milliseconds. Omitted, it uses a timer.
|
|
103
|
+
* @param createSignal How it makes the signal that ends each attempt, given
|
|
104
|
+
* the timeout. Omitted, the signal is `AbortSignal.timeout`'s.
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* import { GitHubPackages } from "@noldova/tools.pipelines.github";
|
|
108
|
+
*
|
|
109
|
+
* const packages = new GitHubPackages(process.env);
|
|
110
|
+
* packages.registry; // "https://npm.pkg.github.com/"
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
public constructor(environment: Readonly<Record<string, string | undefined>>, timeoutMilliseconds?: number, waitAsync?: (milliseconds: number) => Promise<void>, createSignal?: (timeoutMilliseconds: number) => AbortSignal);
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Lists every version of a package, reading GitHub's list a hundred at a
|
|
117
|
+
* time, and remembers each version's id for
|
|
118
|
+
* {@link GitHubPackages.deleteVersionAsync}.
|
|
119
|
+
*
|
|
120
|
+
* @param packageName The package's name, `@<owner>/<name>`, such as
|
|
121
|
+
* `@noldova-com/tools.pipelines`.
|
|
122
|
+
* @returns A promise of the versions' texts, or a failed
|
|
123
|
+
* {@link StepResult}: for a name that is not `@<owner>/<name>`; when one
|
|
124
|
+
* of the two environment variables is missing or empty, naming it; or
|
|
125
|
+
* when GitHub answers with another status than 200, such as 404 for a
|
|
126
|
+
* package it doesn't have or can't show, with the request, the status and
|
|
127
|
+
* GitHub's message; or when the last attempt times out or loses its
|
|
128
|
+
* connection, with the request and the reason. It rejects with
|
|
129
|
+
* `JsonException`, from `@noldova/context.json`, for an answer that is not
|
|
130
|
+
* a JSON list of versions, each with a whole-number `id` and a `name` text.
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* import { GitHubPackages } from "@noldova/tools.pipelines.github";
|
|
134
|
+
*
|
|
135
|
+
* const versions = await new GitHubPackages(process.env).readVersionsAsync("@noldova-com/tools.pipelines");
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
public readVersionsAsync(packageName: string): Promise<readonly string[] | StepResult>;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Deletes one version of a package, by the id its last list gave, and
|
|
142
|
+
* lists the package first if it has not yet.
|
|
143
|
+
*
|
|
144
|
+
* @param packageName The package's name, `@<owner>/<name>`.
|
|
145
|
+
* @param version The version's text, as the list gave it.
|
|
146
|
+
* @returns A promise of `true` when GitHub deleted the version, `false`
|
|
147
|
+
* when the list has no such version, or GitHub answers 404 and a new list
|
|
148
|
+
* no longer has it, as after another run or an earlier attempt whose answer
|
|
149
|
+
* was lost deleted it, or a failed
|
|
150
|
+
* {@link StepResult} as {@link GitHubPackages.readVersionsAsync} gives
|
|
151
|
+
* one, when GitHub answers 404 and a new list still has the version, or
|
|
152
|
+
* when GitHub answers the delete with another status than 204, such as
|
|
153
|
+
* when it refuses to delete a package's last version. It rejects as
|
|
154
|
+
* {@link GitHubPackages.readVersionsAsync} does.
|
|
155
|
+
* @example
|
|
156
|
+
* ```ts
|
|
157
|
+
* import { GitHubPackages } from "@noldova/tools.pipelines.github";
|
|
158
|
+
*
|
|
159
|
+
* const packages = new GitHubPackages(process.env);
|
|
160
|
+
* await packages.readVersionsAsync("@noldova-com/tools.pipelines");
|
|
161
|
+
* const deleted = await packages.deleteVersionAsync("@noldova-com/tools.pipelines", "0.0.1");
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
public deleteVersionAsync(packageName: string, version: string): Promise<boolean | StepResult>;
|
|
165
|
+
}
|
|
166
|
+
|
|
69
167
|
/**
|
|
70
168
|
* GitHub's tags, through its REST API, as the tag step of
|
|
71
169
|
* `@noldova/tools.pipelines` reads and creates them.
|
|
@@ -76,6 +174,13 @@ export declare class GitHubStepOutput implements IStepOutput {
|
|
|
76
174
|
* such as `noldova-com/tools`; and `GITHUB_TOKEN`, a token that may write
|
|
77
175
|
* the repository's contents, such as the job's own. It sends the token only
|
|
78
176
|
* to that API and never writes it anywhere.
|
|
177
|
+
*
|
|
178
|
+
* A request GitHub answers 502, 503 or 504, doesn't answer within the
|
|
179
|
+
* timeout, or loses the connection of, is sent again up to two more times,
|
|
180
|
+
* after 5 and then 15 seconds. A failing answer with a `Retry-After` header
|
|
181
|
+
* of up to 60 seconds is too, after that wait; one with a longer
|
|
182
|
+
* `Retry-After` is not, whatever its status. The last answer, timeout or
|
|
183
|
+
* lost connection is what the call gives.
|
|
79
184
|
*/
|
|
80
185
|
export declare class GitHubTags implements ITagHost {
|
|
81
186
|
/**
|
|
@@ -84,6 +189,10 @@ export declare class GitHubTags implements ITagHost {
|
|
|
84
189
|
* @param environment The environment variables, such as `process.env`.
|
|
85
190
|
* @param timeoutMilliseconds How long it waits for each answer of the API.
|
|
86
191
|
* Omitted, it waits a minute.
|
|
192
|
+
* @param waitAsync How it waits before sending a request again, given the
|
|
193
|
+
* milliseconds. Omitted, it uses a timer.
|
|
194
|
+
* @param createSignal How it makes the signal that ends each attempt, given
|
|
195
|
+
* the timeout. Omitted, the signal is `AbortSignal.timeout`'s.
|
|
87
196
|
* @example
|
|
88
197
|
* ```ts
|
|
89
198
|
* import { GitHubTags } from "@noldova/tools.pipelines.github";
|
|
@@ -91,7 +200,7 @@ export declare class GitHubTags implements ITagHost {
|
|
|
91
200
|
* const tags = new GitHubTags(process.env);
|
|
92
201
|
* ```
|
|
93
202
|
*/
|
|
94
|
-
public constructor(environment: Readonly<Record<string, string | undefined>>, timeoutMilliseconds?: number);
|
|
203
|
+
public constructor(environment: Readonly<Record<string, string | undefined>>, timeoutMilliseconds?: number, waitAsync?: (milliseconds: number) => Promise<void>, createSignal?: (timeoutMilliseconds: number) => AbortSignal);
|
|
95
204
|
|
|
96
205
|
/**
|
|
97
206
|
* Reads the commit a tag points to, following an annotated tag to its
|
|
@@ -104,11 +213,13 @@ export declare class GitHubTags implements ITagHost {
|
|
|
104
213
|
* to something other than a commit, such as a tree; or when GitHub answers
|
|
105
214
|
* with another status, with the request, the status and GitHub's message,
|
|
106
215
|
* such as `GitHub answered GET repos/noldova-com/tools/git/ref/tags/v0.0.4
|
|
107
|
-
* with 403: Resource not accessible by integration
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
216
|
+
* with 403: Resource not accessible by integration`; or when the last
|
|
217
|
+
* attempt times out or loses its connection, with the request and the
|
|
218
|
+
* reason, such as `GitHub gave no answer to GET
|
|
219
|
+
* repos/noldova-com/tools/git/ref/tags/v0.0.4: The operation was aborted
|
|
220
|
+
* due to timeout`. It rejects with `JsonException`, from
|
|
221
|
+
* `@noldova/context.json`, for an answer that is not the JSON GitHub
|
|
222
|
+
* documents.
|
|
112
223
|
* @example
|
|
113
224
|
* ```ts
|
|
114
225
|
* import { GitHubTags } from "@noldova/tools.pipelines.github";
|
|
@@ -126,7 +237,8 @@ export declare class GitHubTags implements ITagHost {
|
|
|
126
237
|
* @param commit The commit's full id.
|
|
127
238
|
* @returns A promise of `true` when GitHub created the tag, or `false` when
|
|
128
239
|
* GitHub refuses it as unprocessable, status 422, and reading the tag then
|
|
129
|
-
* finds it, such as one another run made
|
|
240
|
+
* finds it, such as one another run made, or an earlier attempt whose
|
|
241
|
+
* answer was lost. Otherwise it is a failed
|
|
130
242
|
* {@link StepResult}, as {@link GitHubTags.readTagAsync} gives one: with the
|
|
131
243
|
* 422's message when reading finds no tag, and with the read's failure when
|
|
132
244
|
* the read fails. It rejects as {@link GitHubTags.readTagAsync} does.
|
|
@@ -142,10 +254,11 @@ export declare class GitHubTags implements ITagHost {
|
|
|
142
254
|
|
|
143
255
|
/**
|
|
144
256
|
* The `pipelines` command line a GitHub Actions workflow calls: it runs the
|
|
145
|
-
* source, archive, publish, nightly and tag steps of
|
|
146
|
-
* in the current directory, which is the clone
|
|
147
|
-
* folder value is. The
|
|
148
|
-
*
|
|
257
|
+
* source, archive, publish, nightly, prune and tag steps of
|
|
258
|
+
* `@noldova/tools.pipelines` in the current directory, which is the clone
|
|
259
|
+
* the steps check and where a folder value is. The prune step reaches
|
|
260
|
+
* GitHub Packages through {@link GitHubPackages}, and the tag step reaches
|
|
261
|
+
* GitHub through {@link GitHubTags}, each with the process's environment.
|
|
149
262
|
*/
|
|
150
263
|
export declare class PipelinesProgram {
|
|
151
264
|
/**
|
package/api/index.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* This source code is licensed under the license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
export { GitHubPackages } from "../services/github-packages.js";
|
|
8
9
|
export { GitHubStepOutput } from "../services/github-step-output.js";
|
|
9
10
|
export { GitHubTags } from "../services/github-tags.js";
|
|
10
11
|
export { PipelinesProgram } from "../services/pipelines-program.js";
|
package/api/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/noldova.tools.pipelines.github/src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/noldova.tools.pipelines.github/src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC"}
|
package/models/github-answer.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* This source code is licensed under the license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
-
import { JsonReader } from "@noldova/context.json";
|
|
8
|
+
import { JsonException, JsonReader } from "@noldova/context.json";
|
|
9
9
|
import { StepResult } from "@noldova/tools.pipelines";
|
|
10
10
|
import { Resources } from "../resources.js";
|
|
11
11
|
export class GitHubAnswer {
|
|
@@ -14,18 +14,30 @@ export class GitHubAnswer {
|
|
|
14
14
|
status;
|
|
15
15
|
statusText;
|
|
16
16
|
contentType;
|
|
17
|
+
retryAfter;
|
|
17
18
|
text;
|
|
18
|
-
constructor(method, resource, status, statusText, contentType, text) {
|
|
19
|
+
constructor(method, resource, status, statusText, contentType, retryAfter, text) {
|
|
19
20
|
this.method = method;
|
|
20
21
|
this.resource = resource;
|
|
21
22
|
this.status = status;
|
|
22
23
|
this.statusText = statusText;
|
|
23
24
|
this.contentType = contentType;
|
|
25
|
+
this.retryAfter = retryAfter;
|
|
24
26
|
this.text = text;
|
|
25
27
|
}
|
|
26
28
|
readBody() {
|
|
27
29
|
return JsonReader.parse(this.text, this.resource);
|
|
28
30
|
}
|
|
31
|
+
readItems() {
|
|
32
|
+
let value;
|
|
33
|
+
try {
|
|
34
|
+
value = JSON.parse(this.text);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
throw new JsonException(Resources.answerNotJson, this.resource);
|
|
38
|
+
}
|
|
39
|
+
return JsonReader.fromValue({ [Resources.itemsField]: value }, this.resource).readObjectArray(Resources.itemsField);
|
|
40
|
+
}
|
|
29
41
|
readMessage() {
|
|
30
42
|
const text = this.text.trim();
|
|
31
43
|
if (text.length === 0)
|
|
@@ -34,6 +46,14 @@ export class GitHubAnswer {
|
|
|
34
46
|
return text;
|
|
35
47
|
return this.readBody().readOptionalString(Resources.messageField) ?? text;
|
|
36
48
|
}
|
|
49
|
+
readRetryMilliseconds(unavailableMilliseconds) {
|
|
50
|
+
if (this.status < Resources.firstFailureStatus)
|
|
51
|
+
return null;
|
|
52
|
+
if (!Resources.retryAfterPattern.test(this.retryAfter))
|
|
53
|
+
return Resources.unavailableStatuses.includes(this.status) ? unavailableMilliseconds : null;
|
|
54
|
+
const seconds = Number(this.retryAfter);
|
|
55
|
+
return seconds <= Resources.retryAfterMaxSeconds ? seconds * Resources.millisecondsPerSecond : null;
|
|
56
|
+
}
|
|
37
57
|
toFailure() {
|
|
38
58
|
return StepResult.failed(Resources.formatApiFailed(this.method, this.resource, this.status, this.readMessage()));
|
|
39
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"github-answer.js","sourceRoot":"","sources":["../../../../src/noldova.tools.pipelines.github/src/models/github-answer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"github-answer.js","sourceRoot":"","sources":["../../../../src/noldova.tools.pipelines.github/src/models/github-answer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,OAAO,YAAY;IACP,MAAM,CAAS;IACf,QAAQ,CAAS;IACjB,MAAM,CAAS;IACf,UAAU,CAAS;IACnB,WAAW,CAAS;IACpB,UAAU,CAAS;IACnB,IAAI,CAAS;IAE7B,YAAmB,MAAc,EAAE,QAAgB,EAAE,MAAc,EAAE,UAAkB,EAAE,WAAmB,EAAE,UAAkB,EAAE,IAAY;QAC5I,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAEM,QAAQ;QACb,OAAO,UAAU,CAAC,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AAuB,CAAC,CAAC,CAAC,IAAI,CAAC;QAE9F,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAExC,OAAO,OAAO,IAAI,SAAS,CAAC,oBAAoB,CAAC,CAAC,CAAC,OAAO,GAAG,SAAS,CAAC,qBAAqB,CAAC,CAAC,CAAC,IAAI,CAAC;IACtG,CAAC;IAEM,SAAS;QACd,OAAO,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IACnH,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noldova/tools.pipelines.github",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "api/index.js",
|
|
6
6
|
"types": "api/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@noldova/context.json": "0.0.3",
|
|
26
|
-
"@noldova/tools.pipelines": "0.0.
|
|
26
|
+
"@noldova/tools.pipelines": "0.0.3"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "a4f2a3c28d9a41aeaf8aa13b88f333587d3670ca"
|
|
29
29
|
}
|
package/resources.js
CHANGED
|
@@ -9,7 +9,9 @@ export class Resources {
|
|
|
9
9
|
static acceptHeader = "Accept";
|
|
10
10
|
static annotatedTagType = "tag";
|
|
11
11
|
static annotationEscapes = [["%", "%25"], ["\r", "%0D"], ["\n", "%0A"]];
|
|
12
|
+
static answerNotJson = "GitHub's answer is not JSON.";
|
|
12
13
|
static apiMediaType = "application/vnd.github+json";
|
|
14
|
+
static apiRetryMilliseconds = [5_000, 15_000];
|
|
13
15
|
static apiTimeoutMilliseconds = 60_000;
|
|
14
16
|
static apiUrlVariable = "GITHUB_API_URL";
|
|
15
17
|
static apiVersion = "2022-11-28";
|
|
@@ -19,22 +21,38 @@ export class Resources {
|
|
|
19
21
|
static contentTypeHeader = "Content-Type";
|
|
20
22
|
static createdStatus = 201;
|
|
21
23
|
static createMethod = "POST";
|
|
24
|
+
static deletedStatus = 204;
|
|
25
|
+
static deleteMethod = "DELETE";
|
|
26
|
+
static firstFailureStatus = 400;
|
|
22
27
|
static foundStatus = 200;
|
|
28
|
+
static idField = "id";
|
|
29
|
+
static itemsField = "items";
|
|
23
30
|
static jsonContentType = "application/json";
|
|
24
31
|
static jsonContentTypePattern = /^application\/(?:[a-z0-9.-]+\+)?json\b/i;
|
|
25
32
|
static jsonObjectStart = "{";
|
|
26
33
|
static lineSeparator = "\n";
|
|
27
34
|
static messageField = "message";
|
|
35
|
+
static millisecondsPerSecond = 1_000;
|
|
36
|
+
static nameField = "name";
|
|
28
37
|
static notFoundStatus = 404;
|
|
29
38
|
static objectField = "object";
|
|
39
|
+
static packageNamePattern = /^@([^/]+)\/([^/]+)$/;
|
|
40
|
+
static packagesRegistry = "https://npm.pkg.github.com/";
|
|
30
41
|
static programName = "pipelines";
|
|
31
42
|
static readMethod = "GET";
|
|
32
43
|
static referencesPath = "git/refs";
|
|
33
44
|
static repositoryVariable = "GITHUB_REPOSITORY";
|
|
45
|
+
static retryAfterHeader = "Retry-After";
|
|
46
|
+
static retryAfterMaxSeconds = 60;
|
|
47
|
+
static retryAfterPattern = /^[0-9]+$/;
|
|
48
|
+
static runnerTemporaryVariable = "RUNNER_TEMP";
|
|
34
49
|
static shaField = "sha";
|
|
50
|
+
static timeoutErrorName = "TimeoutError";
|
|
35
51
|
static tokenVariable = "GITHUB_TOKEN";
|
|
36
52
|
static typeField = "type";
|
|
53
|
+
static unavailableStatuses = [502, 503, 504];
|
|
37
54
|
static unprocessableStatus = 422;
|
|
55
|
+
static versionsPageSize = 100;
|
|
38
56
|
static formatErrorAnnotation(message) {
|
|
39
57
|
const escaped = Resources.annotationEscapes.reduce((text, [character, escape]) => text.replaceAll(character, escape), message);
|
|
40
58
|
return `::error::${escaped}${Resources.lineSeparator}`;
|
|
@@ -42,6 +60,24 @@ export class Resources {
|
|
|
42
60
|
static formatVariableMissing(name) {
|
|
43
61
|
return `The environment variable ${name} is not set; the tag step needs it to reach GitHub.`;
|
|
44
62
|
}
|
|
63
|
+
static formatPruneVariableMissing(name) {
|
|
64
|
+
return `The environment variable ${name} is not set; the prune step needs it to reach GitHub.`;
|
|
65
|
+
}
|
|
66
|
+
static formatPackageNotScoped(packageName) {
|
|
67
|
+
return `${packageName} has no scope; a package on GitHub Packages is named @<owner>/<name>.`;
|
|
68
|
+
}
|
|
69
|
+
static formatVersionStillListed(packageName, version) {
|
|
70
|
+
return `GitHub answered 404 to deleting ${packageName}@${version} but still lists it, so it is not deleted; the token may not be allowed to delete it.`;
|
|
71
|
+
}
|
|
72
|
+
static formatVersionsResource(packageName) {
|
|
73
|
+
return packageName.replace(Resources.packageNamePattern, (_, owner, name) => `orgs/${owner}/packages/npm/${encodeURIComponent(name)}/versions`);
|
|
74
|
+
}
|
|
75
|
+
static formatVersionsPage(resource, page) {
|
|
76
|
+
return `${resource}?per_page=${Resources.versionsPageSize}&page=${page}`;
|
|
77
|
+
}
|
|
78
|
+
static formatVersionResource(resource, id) {
|
|
79
|
+
return `${resource}/${id}`;
|
|
80
|
+
}
|
|
45
81
|
static formatResource(repository, path) {
|
|
46
82
|
return `repos/${repository}/${path}`;
|
|
47
83
|
}
|
|
@@ -60,6 +96,9 @@ export class Resources {
|
|
|
60
96
|
static formatApiFailed(method, resource, status, message) {
|
|
61
97
|
return `GitHub answered ${method} ${resource} with ${status}: ${message}`;
|
|
62
98
|
}
|
|
99
|
+
static formatApiUnanswered(method, resource, reason) {
|
|
100
|
+
return `GitHub gave no answer to ${method} ${resource}: ${reason}`;
|
|
101
|
+
}
|
|
63
102
|
static formatTagTargetInvalid(tag, type) {
|
|
64
103
|
return `${tag} points to a ${type}, not a commit.`;
|
|
65
104
|
}
|
package/resources.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../../src/noldova.tools.pipelines.github/src/resources.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,OAAO,SAAS;IACb,MAAM,CAAU,YAAY,GAAW,QAAQ,CAAC;IAChD,MAAM,CAAU,gBAAgB,GAAW,KAAK,CAAC;IACjD,MAAM,CAAU,iBAAiB,GAA2C,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IACzH,MAAM,CAAU,YAAY,GAAW,6BAA6B,CAAC;IACrE,MAAM,CAAU,sBAAsB,GAAW,MAAM,CAAC;IACxD,MAAM,CAAU,cAAc,GAAW,gBAAgB,CAAC;IAC1D,MAAM,CAAU,UAAU,GAAW,YAAY,CAAC;IAClD,MAAM,CAAU,gBAAgB,GAAW,sBAAsB,CAAC;IAClE,MAAM,CAAU,mBAAmB,GAAW,eAAe,CAAC;IAC9D,MAAM,CAAU,UAAU,GAAW,QAAQ,CAAC;IAC9C,MAAM,CAAU,iBAAiB,GAAW,cAAc,CAAC;IAC3D,MAAM,CAAU,aAAa,GAAW,GAAG,CAAC;IAC5C,MAAM,CAAU,YAAY,GAAW,MAAM,CAAC;IAC9C,MAAM,CAAU,WAAW,GAAW,GAAG,CAAC;IAC1C,MAAM,CAAU,eAAe,GAAW,kBAAkB,CAAC;IAC7D,MAAM,CAAU,sBAAsB,GAAW,yCAAyC,CAAC;IAC3F,MAAM,CAAU,eAAe,GAAW,GAAG,CAAC;IAC9C,MAAM,CAAU,aAAa,GAAW,IAAI,CAAC;IAC7C,MAAM,CAAU,YAAY,GAAW,SAAS,CAAC;IACjD,MAAM,CAAU,cAAc,GAAW,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
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { StepResult } from "@noldova/tools.pipelines";
|
|
9
|
+
import { GitHubAnswer } from "../models/github-answer.js";
|
|
10
|
+
import { Resources } from "../resources.js";
|
|
11
|
+
export class GitHubApi {
|
|
12
|
+
apiUrl;
|
|
13
|
+
token;
|
|
14
|
+
timeoutMilliseconds;
|
|
15
|
+
waitAsync;
|
|
16
|
+
createSignal;
|
|
17
|
+
constructor(apiUrl, token, timeoutMilliseconds, waitAsync, createSignal) {
|
|
18
|
+
this.apiUrl = apiUrl;
|
|
19
|
+
this.token = token;
|
|
20
|
+
this.timeoutMilliseconds = timeoutMilliseconds;
|
|
21
|
+
this.waitAsync = waitAsync;
|
|
22
|
+
this.createSignal = createSignal;
|
|
23
|
+
}
|
|
24
|
+
static createTimeoutSignal(timeoutMilliseconds) {
|
|
25
|
+
return AbortSignal.timeout(timeoutMilliseconds);
|
|
26
|
+
}
|
|
27
|
+
async requestAsync(method, resource, body) {
|
|
28
|
+
for (const retryMilliseconds of Resources.apiRetryMilliseconds) {
|
|
29
|
+
const answer = await this.sendAsync(method, resource, body);
|
|
30
|
+
const waitMilliseconds = answer instanceof StepResult ? retryMilliseconds : answer.readRetryMilliseconds(retryMilliseconds);
|
|
31
|
+
if (waitMilliseconds === null)
|
|
32
|
+
return answer;
|
|
33
|
+
await this.waitAsync(waitMilliseconds);
|
|
34
|
+
}
|
|
35
|
+
return await this.sendAsync(method, resource, body);
|
|
36
|
+
}
|
|
37
|
+
async sendAsync(method, resource, body) {
|
|
38
|
+
try {
|
|
39
|
+
const response = await fetch(`${this.apiUrl}/${resource}`, {
|
|
40
|
+
method,
|
|
41
|
+
headers: {
|
|
42
|
+
[Resources.acceptHeader]: Resources.apiMediaType,
|
|
43
|
+
[Resources.authorizationHeader]: Resources.formatAuthorization(this.token),
|
|
44
|
+
[Resources.apiVersionHeader]: Resources.apiVersion,
|
|
45
|
+
...(body === undefined ? {} : { [Resources.contentTypeHeader]: Resources.jsonContentType })
|
|
46
|
+
},
|
|
47
|
+
signal: this.createSignal(this.timeoutMilliseconds),
|
|
48
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) })
|
|
49
|
+
});
|
|
50
|
+
const headers = response.headers;
|
|
51
|
+
return new GitHubAnswer(method, resource, response.status, response.statusText, headers.get(Resources.contentTypeHeader) ?? "", headers.get(Resources.retryAfterHeader) ?? "", await response.text());
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (!GitHubApi.isUnanswered(error))
|
|
55
|
+
throw error;
|
|
56
|
+
return StepResult.failed(Resources.formatApiUnanswered(method, resource, (error.cause instanceof Error ? error.cause.message : "") || error.message));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
static isUnanswered(error) {
|
|
60
|
+
return (error instanceof DOMException && error.name === Resources.timeoutErrorName) || (error instanceof TypeError && error.cause instanceof Error);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=github-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-api.js","sourceRoot":"","sources":["../../../../src/noldova.tools.pipelines.github/src/services/github-api.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,OAAO,SAAS;IACH,MAAM,CAAS;IACf,KAAK,CAAS;IACd,mBAAmB,CAAS;IAC5B,SAAS,CAA0C;IACnD,YAAY,CAA+C;IAE5E,YAAmB,MAAc,EAAE,KAAa,EAAE,mBAA2B,EAAE,SAAkD,EAAE,YAA0D;QAC3L,IAAI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;IAEO,MAAM,CAAC,YAAY,CAAC,KAAc;QACxC,OAAO,CAAC,KAAK,YAAY,YAAY,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,YAAY,SAAS,IAAI,KAAK,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC;IACtJ,CAAC;CACF"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { setTimeout as delayAsync } from "node:timers/promises";
|
|
9
|
+
import { StepResult } from "@noldova/tools.pipelines";
|
|
10
|
+
import { Resources } from "../resources.js";
|
|
11
|
+
import { GitHubApi } from "./github-api.js";
|
|
12
|
+
export class GitHubPackages {
|
|
13
|
+
environment;
|
|
14
|
+
timeoutMilliseconds;
|
|
15
|
+
waitAsync;
|
|
16
|
+
createSignal;
|
|
17
|
+
versionIds = new Map();
|
|
18
|
+
registry = Resources.packagesRegistry;
|
|
19
|
+
constructor(environment, timeoutMilliseconds = Resources.apiTimeoutMilliseconds, waitAsync = delayAsync, createSignal = GitHubApi.createTimeoutSignal) {
|
|
20
|
+
this.environment = environment;
|
|
21
|
+
this.timeoutMilliseconds = timeoutMilliseconds;
|
|
22
|
+
this.waitAsync = waitAsync;
|
|
23
|
+
this.createSignal = createSignal;
|
|
24
|
+
}
|
|
25
|
+
async readVersionsAsync(packageName) {
|
|
26
|
+
const target = this.readTarget(packageName);
|
|
27
|
+
if (target instanceof StepResult)
|
|
28
|
+
return target;
|
|
29
|
+
const ids = await this.readIdsAsync(packageName, ...target);
|
|
30
|
+
return ids instanceof StepResult ? ids : [...ids.keys()];
|
|
31
|
+
}
|
|
32
|
+
async deleteVersionAsync(packageName, version) {
|
|
33
|
+
const target = this.readTarget(packageName);
|
|
34
|
+
if (target instanceof StepResult)
|
|
35
|
+
return target;
|
|
36
|
+
const ids = this.versionIds.get(packageName) ?? await this.readIdsAsync(packageName, ...target);
|
|
37
|
+
if (ids instanceof StepResult)
|
|
38
|
+
return ids;
|
|
39
|
+
const id = ids.get(version);
|
|
40
|
+
if (id === undefined)
|
|
41
|
+
return false;
|
|
42
|
+
const [api, resource] = target;
|
|
43
|
+
const answer = await api.requestAsync(Resources.deleteMethod, Resources.formatVersionResource(resource, id));
|
|
44
|
+
if (answer instanceof StepResult)
|
|
45
|
+
return answer;
|
|
46
|
+
if (answer.status === Resources.deletedStatus) {
|
|
47
|
+
ids.delete(version);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
if (answer.status !== Resources.notFoundStatus)
|
|
51
|
+
return answer.toFailure();
|
|
52
|
+
const listed = await this.readIdsAsync(packageName, api, resource);
|
|
53
|
+
if (listed instanceof StepResult)
|
|
54
|
+
return listed;
|
|
55
|
+
return listed.has(version) ? StepResult.failed(Resources.formatVersionStillListed(packageName, version)) : false;
|
|
56
|
+
}
|
|
57
|
+
async readIdsAsync(packageName, api, resource) {
|
|
58
|
+
const ids = new Map();
|
|
59
|
+
for (let page = 1;; page++) {
|
|
60
|
+
const answer = await api.requestAsync(Resources.readMethod, Resources.formatVersionsPage(resource, page));
|
|
61
|
+
if (answer instanceof StepResult)
|
|
62
|
+
return answer;
|
|
63
|
+
if (answer.status !== Resources.foundStatus)
|
|
64
|
+
return answer.toFailure();
|
|
65
|
+
const items = answer.readItems();
|
|
66
|
+
for (const item of items)
|
|
67
|
+
ids.set(item.readString(Resources.nameField), item.readInteger(Resources.idField));
|
|
68
|
+
if (items.length < Resources.versionsPageSize)
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
this.versionIds.set(packageName, ids);
|
|
72
|
+
return ids;
|
|
73
|
+
}
|
|
74
|
+
readTarget(packageName) {
|
|
75
|
+
if (!Resources.packageNamePattern.test(packageName))
|
|
76
|
+
return StepResult.failed(Resources.formatPackageNotScoped(packageName));
|
|
77
|
+
const missing = [Resources.apiUrlVariable, Resources.tokenVariable].find(t => this.readVariable(t).length === 0);
|
|
78
|
+
if (missing !== undefined)
|
|
79
|
+
return StepResult.failed(Resources.formatPruneVariableMissing(missing));
|
|
80
|
+
const api = new GitHubApi(this.readVariable(Resources.apiUrlVariable), this.readVariable(Resources.tokenVariable), this.timeoutMilliseconds, this.waitAsync, this.createSignal);
|
|
81
|
+
return [api, Resources.formatVersionsResource(packageName)];
|
|
82
|
+
}
|
|
83
|
+
readVariable(name) {
|
|
84
|
+
return this.environment[name] ?? "";
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=github-packages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-packages.js","sourceRoot":"","sources":["../../../../src/noldova.tools.pipelines.github/src/services/github-packages.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEhE,OAAO,EAAsB,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAE1E,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,OAAO,cAAc;IACR,WAAW,CAA+C;IAC1D,mBAAmB,CAAS;IAC5B,SAAS,CAA0C;IACnD,YAAY,CAA+C;IAC3D,UAAU,GAAqC,IAAI,GAAG,EAAE,CAAC;IAE1D,QAAQ,GAAW,SAAS,CAAC,gBAAgB,CAAC;IAE9D,YAAmB,WAAyD,EAAE,mBAAmB,GAAW,SAAS,CAAC,sBAAsB,EAAE,SAAS,GAA4C,UAAU,EAAE,YAAY,GAAiD,SAAS,CAAC,mBAAmB;QACvS,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;QAC/C,IA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5,30 @@
|
|
|
5
5
|
* This source code is licensed under the license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
import { setTimeout as delayAsync } from "node:timers/promises";
|
|
8
9
|
import { StepResult } from "@noldova/tools.pipelines";
|
|
9
10
|
import { GitHubAnswer } from "../models/github-answer.js";
|
|
10
11
|
import { GitHubConnection } from "../models/github-connection.js";
|
|
11
12
|
import { Resources } from "../resources.js";
|
|
13
|
+
import { GitHubApi } from "./github-api.js";
|
|
12
14
|
export class GitHubTags {
|
|
13
15
|
environment;
|
|
14
16
|
timeoutMilliseconds;
|
|
15
|
-
|
|
17
|
+
waitAsync;
|
|
18
|
+
createSignal;
|
|
19
|
+
constructor(environment, timeoutMilliseconds = Resources.apiTimeoutMilliseconds, waitAsync = delayAsync, createSignal = GitHubApi.createTimeoutSignal) {
|
|
16
20
|
this.environment = environment;
|
|
17
21
|
this.timeoutMilliseconds = timeoutMilliseconds;
|
|
22
|
+
this.waitAsync = waitAsync;
|
|
23
|
+
this.createSignal = createSignal;
|
|
18
24
|
}
|
|
19
25
|
async readTagAsync(tag) {
|
|
20
26
|
const connection = this.readConnection();
|
|
21
27
|
if (connection instanceof StepResult)
|
|
22
28
|
return connection;
|
|
23
29
|
const reference = await this.requestAsync(connection, Resources.readMethod, Resources.formatTagReferencePath(tag));
|
|
30
|
+
if (reference instanceof StepResult)
|
|
31
|
+
return reference;
|
|
24
32
|
if (reference.status === Resources.notFoundStatus)
|
|
25
33
|
return "";
|
|
26
34
|
if (reference.status !== Resources.foundStatus)
|
|
@@ -28,6 +36,8 @@ export class GitHubTags {
|
|
|
28
36
|
let target = reference.readBody().readObject(Resources.objectField);
|
|
29
37
|
while (target.readString(Resources.typeField) === Resources.annotatedTagType) {
|
|
30
38
|
const tagObject = await this.requestAsync(connection, Resources.readMethod, Resources.formatTagObjectPath(target.readString(Resources.shaField)));
|
|
39
|
+
if (tagObject instanceof StepResult)
|
|
40
|
+
return tagObject;
|
|
31
41
|
if (tagObject.status !== Resources.foundStatus)
|
|
32
42
|
return tagObject.toFailure();
|
|
33
43
|
target = tagObject.readBody().readObject(Resources.objectField);
|
|
@@ -42,6 +52,8 @@ export class GitHubTags {
|
|
|
42
52
|
if (connection instanceof StepResult)
|
|
43
53
|
return connection;
|
|
44
54
|
const answer = await this.requestAsync(connection, Resources.createMethod, Resources.referencesPath, { ref: Resources.formatTagReference(tag), sha: commit });
|
|
55
|
+
if (answer instanceof StepResult)
|
|
56
|
+
return answer;
|
|
45
57
|
if (answer.status === Resources.createdStatus)
|
|
46
58
|
return true;
|
|
47
59
|
if (answer.status !== Resources.unprocessableStatus)
|
|
@@ -61,19 +73,7 @@ export class GitHubTags {
|
|
|
61
73
|
return this.environment[name] ?? "";
|
|
62
74
|
}
|
|
63
75
|
async requestAsync(connection, method, path, body) {
|
|
64
|
-
|
|
65
|
-
const response = await fetch(`${connection.apiUrl}/${resource}`, {
|
|
66
|
-
method,
|
|
67
|
-
headers: {
|
|
68
|
-
[Resources.acceptHeader]: Resources.apiMediaType,
|
|
69
|
-
[Resources.authorizationHeader]: Resources.formatAuthorization(connection.token),
|
|
70
|
-
[Resources.apiVersionHeader]: Resources.apiVersion,
|
|
71
|
-
...(body === undefined ? {} : { [Resources.contentTypeHeader]: Resources.jsonContentType })
|
|
72
|
-
},
|
|
73
|
-
signal: AbortSignal.timeout(this.timeoutMilliseconds),
|
|
74
|
-
...(body === undefined ? {} : { body: JSON.stringify(body) })
|
|
75
|
-
});
|
|
76
|
-
return new GitHubAnswer(method, resource, response.status, response.statusText, response.headers.get(Resources.contentTypeHeader) ?? "", await response.text());
|
|
76
|
+
return new GitHubApi(connection.apiUrl, connection.token, this.timeoutMilliseconds, this.waitAsync, this.createSignal).requestAsync(method, Resources.formatResource(connection.repository, path), body);
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
//# sourceMappingURL=github-tags.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"github-tags.js","sourceRoot":"","sources":["../../../../src/noldova.tools.pipelines.github/src/services/github-tags.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAiB,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAErE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,OAAO,UAAU;IACJ,WAAW,CAA+C;IAC1D,mBAAmB,CAAS;
|
|
1
|
+
{"version":3,"file":"github-tags.js","sourceRoot":"","sources":["../../../../src/noldova.tools.pipelines.github/src/services/github-tags.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEhE,OAAO,EAAiB,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAErE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,OAAO,UAAU;IACJ,WAAW,CAA+C;IAC1D,mBAAmB,CAAS;IAC5B,SAAS,CAA0C;IACnD,YAAY,CAA+C;IAE5E,YAAmB,WAAyD,EAAE,mBAAmB,GAAW,SAAS,CAAC,sBAAsB,EAAE,SAAS,GAA4C,UAAU,EAAE,YAAY,GAAiD,SAAS,CAAC,mBAAmB;QACvS,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;QAC/C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;I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,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC;QAC/I,IAAI,OAAO,KAAK,SAAS;YACvB,OAAO,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC;QAErE,OAAO,IAAI,gBAAgB,CAAC,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,cAAc,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,kBAAkB,CAAC,EAAE,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC;IACxK,CAAC;IAEO,YAAY,CAAC,IAAY;QAC/B,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IACtC,CAAC;IAEO,KAAK,CAAC,YAAY,CAAC,UAA4B,EAAE,MAAc,EAAE,IAAY,EAAE,IAAuC;QAC5H,OAAO,IAAI,SAAS,CAAC,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,mBAAmB,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,cAAc,CAAC,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;IAC3M,CAAC;CACF"}
|
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
* This source code is licensed under the license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
-
import { ArchiveStep, CommandLine, Git, NightlyStep, Npm, ProcessRunner, PublishStep, SourceStep, TagStep, Tar } from "@noldova/tools.pipelines";
|
|
8
|
+
import { ArchiveStep, CommandLine, Git, LineEndingsStep, NightlyStep, Npm, ProcessRunner, PruneStep, PublishStep, ReproducibleStep, SourceStep, TagStep, Tar, ToolchainStep, UnchangedStep } from "@noldova/tools.pipelines";
|
|
9
9
|
import { Resources } from "../resources.js";
|
|
10
|
+
import { GitHubPackages } from "./github-packages.js";
|
|
10
11
|
import { GitHubTags } from "./github-tags.js";
|
|
11
12
|
export class PipelinesProgram {
|
|
12
13
|
output;
|
|
@@ -18,7 +19,7 @@ export class PipelinesProgram {
|
|
|
18
19
|
const git = new Git(processRunner, process.cwd());
|
|
19
20
|
const npm = new Npm(processRunner, process.cwd());
|
|
20
21
|
const archiveStep = new ArchiveStep(git, new Tar(processRunner));
|
|
21
|
-
const steps = [new SourceStep(git), archiveStep, new PublishStep(archiveStep, npm), new NightlyStep(git, archiveStep, npm), new TagStep(new GitHubTags(process.env))];
|
|
22
|
+
const steps = [new SourceStep(git), archiveStep, new PublishStep(archiveStep, npm), new NightlyStep(git, archiveStep, npm), new PruneStep(git, archiveStep, new GitHubPackages(process.env)), new TagStep(new GitHubTags(process.env)), new ToolchainStep(npm, process.version), new LineEndingsStep(git), new UnchangedStep(git), new ReproducibleStep(git, npm, process.env[Resources.runnerTemporaryVariable])];
|
|
22
23
|
return new CommandLine(Resources.programName, steps, this.output).runAsync(values);
|
|
23
24
|
}
|
|
24
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipelines-program.js","sourceRoot":"","sources":["../../../../src/noldova.tools.pipelines.github/src/services/pipelines-program.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,EAAoB,WAAW,EAAE,GAAG,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"pipelines-program.js","sourceRoot":"","sources":["../../../../src/noldova.tools.pipelines.github/src/services/pipelines-program.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,EAAoB,eAAe,EAAE,WAAW,EA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