@noldova/tools.pipelines.github 0.0.0-stage → 0.0.2
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/LICENSE +21 -0
- package/README.md +85 -2
- package/api/index.d.ts +273 -0
- package/api/index.js +12 -0
- package/api/index.js.map +1 -0
- package/bin/pipelines.js +12 -0
- package/bin/pipelines.js.map +1 -0
- package/models/github-answer.js +51 -0
- package/models/github-answer.js.map +1 -0
- package/models/github-connection.js +18 -0
- package/models/github-connection.js.map +1 -0
- package/package.json +27 -4
- package/resources.js +94 -0
- package/resources.js.map +1 -0
- package/services/github-api.js +34 -0
- package/services/github-api.js.map +1 -0
- package/services/github-packages.js +78 -0
- package/services/github-packages.js.map +1 -0
- package/services/github-step-output.js +24 -0
- package/services/github-step-output.js.map +1 -0
- package/services/github-tags.js +68 -0
- package/services/github-tags.js.map +1 -0
- package/services/pipelines-program.js +26 -0
- package/services/pipelines-program.js.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Noldova
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,86 @@
|
|
|
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, prune and tag steps, and the prune and tag steps' access to GitHub's REST API.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @noldova/tools.pipelines.github
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Use
|
|
13
|
+
|
|
14
|
+
### In a workflow
|
|
15
|
+
|
|
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
|
+
|
|
18
|
+
```yaml
|
|
19
|
+
- run: npm install --global --ignore-scripts @noldova/tools.pipelines.github@0.0.2
|
|
20
|
+
- run: pipelines source "$VERSION" "$COMMIT"
|
|
21
|
+
- id: nightly
|
|
22
|
+
run: |
|
|
23
|
+
version="$(pipelines nightly "$COMMIT" https://registry.npmjs.org/)"
|
|
24
|
+
echo "version=$version" >> "$GITHUB_OUTPUT"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
| Step | Values |
|
|
28
|
+
|---|---|
|
|
29
|
+
| `source` | `<version> <commit>` |
|
|
30
|
+
| `archive` | `<folder> <version> <commit> <scope>` |
|
|
31
|
+
| `publish` | `<folder> <version> <commit> <scope> <registry> <access>` |
|
|
32
|
+
| `nightly` | `<commit> <registry>` |
|
|
33
|
+
| `prune` | `<version> <commit> <scope> <registry> <keep-versions>` |
|
|
34
|
+
| `tag` | `<version> <commit>` |
|
|
35
|
+
|
|
36
|
+
`@noldova/tools.pipelines`'s README says what each step checks and does.
|
|
37
|
+
|
|
38
|
+
- 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.
|
|
39
|
+
- 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.
|
|
40
|
+
- The annotation goes to standard error, which GitHub Actions reads workflow commands from as it does standard output, so a step whose output the workflow keeps, such as the nightly version above, still shows it.
|
|
41
|
+
- A fault, such as git failing to start, ends the run with its stack trace and exit code `1`.
|
|
42
|
+
|
|
43
|
+
### The tag step
|
|
44
|
+
|
|
45
|
+
`pipelines tag <version> <commit>` tags the released commit `v<version>` through GitHub's REST API, and never moves a tag.
|
|
46
|
+
It reads `GITHUB_API_URL` and `GITHUB_REPOSITORY`, which GitHub Actions sets, and `GITHUB_TOKEN`, which the workflow passes in; the token needs to write the repository's contents, and is never written anywhere:
|
|
47
|
+
|
|
48
|
+
```yaml
|
|
49
|
+
- env:
|
|
50
|
+
GITHUB_TOKEN: ${{ github.token }}
|
|
51
|
+
run: pipelines tag "$VERSION" "$COMMIT"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The job needs `permissions: contents: write`.
|
|
55
|
+
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.
|
|
56
|
+
|
|
57
|
+
### The prune step
|
|
58
|
+
|
|
59
|
+
`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.
|
|
60
|
+
A package `@<owner>/<name>` is the npm package `<name>` of the organization `<owner>`, so the scope is the organization's.
|
|
61
|
+
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:
|
|
62
|
+
|
|
63
|
+
```yaml
|
|
64
|
+
- env:
|
|
65
|
+
GITHUB_TOKEN: ${{ github.token }}
|
|
66
|
+
run: pipelines prune "$VERSION" "$COMMIT" @noldova-com https://npm.pkg.github.com/ 5
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The job needs `permissions: packages: write`, and, since the step deletes, an environment whose reviewers approve each run.
|
|
70
|
+
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.
|
|
71
|
+
A 404 to a delete counts as a version already deleted only when GitHub's list no longer has it; otherwise the step fails.
|
|
72
|
+
|
|
73
|
+
### From code
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { GitHubStepOutput, PipelinesProgram } from "@noldova/tools.pipelines.github";
|
|
77
|
+
|
|
78
|
+
const program = new PipelinesProgram(new GitHubStepOutput(process.stdout, process.stderr));
|
|
79
|
+
process.exitCode = await program.runAsync(["source", "0.0.4", "225059f4c1e6a3b2d8f7e9a0b1c2d3e4f5a6b7c8"]);
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The declaration file `api/index.d.ts` documents every member with its contract and examples.
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
MIT; see `LICENSE`.
|
package/api/index.d.ts
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
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
|
+
|
|
9
|
+
import type { IRegistryHost, IStepOutput, ITagHost, StepResult } from "@noldova/tools.pipelines";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Writes a step's messages as a GitHub Actions job reads them: a success to
|
|
13
|
+
* standard output as it is, and a failure as an error annotation, which the
|
|
14
|
+
* run's summary shows.
|
|
15
|
+
*/
|
|
16
|
+
export declare class GitHubStepOutput implements IStepOutput {
|
|
17
|
+
/**
|
|
18
|
+
* Creates the output over two streams.
|
|
19
|
+
*
|
|
20
|
+
* @param standardOutput Where a success goes, such as `process.stdout`.
|
|
21
|
+
* @param standardError Where a failure goes, such as `process.stderr`;
|
|
22
|
+
* GitHub Actions reads workflow commands from it as it does from standard
|
|
23
|
+
* output, so a workflow that keeps a step's standard output, such as the
|
|
24
|
+
* nightly version, still shows the failure.
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { GitHubStepOutput } from "@noldova/tools.pipelines.github";
|
|
28
|
+
*
|
|
29
|
+
* const output = new GitHubStepOutput(process.stdout, process.stderr);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
public constructor(standardOutput: NodeJS.WritableStream, standardError: NodeJS.WritableStream);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Writes the message of a step that succeeded, and a line feed, to standard
|
|
36
|
+
* output; an empty message writes nothing.
|
|
37
|
+
*
|
|
38
|
+
* @param message The step's message.
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { GitHubStepOutput } from "@noldova/tools.pipelines.github";
|
|
42
|
+
*
|
|
43
|
+
* const output = new GitHubStepOutput(process.stdout, process.stderr);
|
|
44
|
+
* output.writeSuccess("0.0.5-nightly.20261102"); // writes "0.0.5-nightly.20261102\n"
|
|
45
|
+
* output.writeSuccess(""); // writes nothing
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
public writeSuccess(message: string): void;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Writes the message of a step that failed to standard error as one
|
|
52
|
+
* `::error::` workflow command, with `%`, carriage returns and line feeds
|
|
53
|
+
* escaped as `%25`, `%0D` and `%0A`, so a message of several lines is one
|
|
54
|
+
* annotation.
|
|
55
|
+
*
|
|
56
|
+
* @param message What is wrong.
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { GitHubStepOutput } from "@noldova/tools.pipelines.github";
|
|
60
|
+
*
|
|
61
|
+
* const output = new GitHubStepOutput(process.stdout, process.stderr);
|
|
62
|
+
* output.writeFailure("archives has no noldova-tools.pipelines-0.0.4.tgz.\n100% of nothing");
|
|
63
|
+
* // writes "::error::archives has no noldova-tools.pipelines-0.0.4.tgz.%0A100%25 of nothing\n"
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
public writeFailure(message: string): void;
|
|
67
|
+
}
|
|
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
|
+
export declare class GitHubPackages implements IRegistryHost {
|
|
82
|
+
/**
|
|
83
|
+
* The registry it lists and deletes versions on,
|
|
84
|
+
* `"https://npm.pkg.github.com/"`.
|
|
85
|
+
*/
|
|
86
|
+
public readonly registry: string;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Creates the packages over an environment, which it reads at each call.
|
|
90
|
+
*
|
|
91
|
+
* @param environment The environment variables, such as `process.env`.
|
|
92
|
+
* @param timeoutMilliseconds How long it waits for each answer of the API.
|
|
93
|
+
* Omitted, it waits a minute.
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* import { GitHubPackages } from "@noldova/tools.pipelines.github";
|
|
97
|
+
*
|
|
98
|
+
* const packages = new GitHubPackages(process.env);
|
|
99
|
+
* packages.registry; // "https://npm.pkg.github.com/"
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
public constructor(environment: Readonly<Record<string, string | undefined>>, timeoutMilliseconds?: number);
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Lists every version of a package, reading GitHub's list a hundred at a
|
|
106
|
+
* time, and remembers each version's id for
|
|
107
|
+
* {@link GitHubPackages.deleteVersionAsync}.
|
|
108
|
+
*
|
|
109
|
+
* @param packageName The package's name, `@<owner>/<name>`, such as
|
|
110
|
+
* `@noldova-com/tools.pipelines`.
|
|
111
|
+
* @returns A promise of the versions' texts, or a failed
|
|
112
|
+
* {@link StepResult}: for a name that is not `@<owner>/<name>`; when one
|
|
113
|
+
* of the two environment variables is missing or empty, naming it; or
|
|
114
|
+
* when GitHub answers with another status than 200, such as 404 for a
|
|
115
|
+
* package it doesn't have or can't show, with the request, the status and
|
|
116
|
+
* GitHub's message. It rejects with `JsonException`, from
|
|
117
|
+
* `@noldova/context.json`, for an answer that is not a JSON list of
|
|
118
|
+
* versions, each with a whole-number `id` and a `name` text, with a
|
|
119
|
+
* `DOMException` named `TimeoutError` when GitHub doesn't answer within
|
|
120
|
+
* the timeout, and with the error `fetch` gives when GitHub can't be
|
|
121
|
+
* reached.
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* import { GitHubPackages } from "@noldova/tools.pipelines.github";
|
|
125
|
+
*
|
|
126
|
+
* const versions = await new GitHubPackages(process.env).readVersionsAsync("@noldova-com/tools.pipelines");
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
public readVersionsAsync(packageName: string): Promise<readonly string[] | StepResult>;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Deletes one version of a package, by the id its last list gave, and
|
|
133
|
+
* lists the package first if it has not yet.
|
|
134
|
+
*
|
|
135
|
+
* @param packageName The package's name, `@<owner>/<name>`.
|
|
136
|
+
* @param version The version's text, as the list gave it.
|
|
137
|
+
* @returns A promise of `true` when GitHub deleted the version, `false`
|
|
138
|
+
* when the list has no such version, or GitHub answers 404 and a new list
|
|
139
|
+
* no longer has it, as after another run deleted it, or a failed
|
|
140
|
+
* {@link StepResult} as {@link GitHubPackages.readVersionsAsync} gives
|
|
141
|
+
* one, when GitHub answers 404 and a new list still has the version, or
|
|
142
|
+
* when GitHub answers the delete with another status than 204, such as
|
|
143
|
+
* when it refuses to delete a package's last version. It rejects as
|
|
144
|
+
* {@link GitHubPackages.readVersionsAsync} does.
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* import { GitHubPackages } from "@noldova/tools.pipelines.github";
|
|
148
|
+
*
|
|
149
|
+
* const packages = new GitHubPackages(process.env);
|
|
150
|
+
* await packages.readVersionsAsync("@noldova-com/tools.pipelines");
|
|
151
|
+
* const deleted = await packages.deleteVersionAsync("@noldova-com/tools.pipelines", "0.0.1");
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
public deleteVersionAsync(packageName: string, version: string): Promise<boolean | StepResult>;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* GitHub's tags, through its REST API, as the tag step of
|
|
159
|
+
* `@noldova/tools.pipelines` reads and creates them.
|
|
160
|
+
*
|
|
161
|
+
* It reaches the API with three environment variables, which GitHub Actions
|
|
162
|
+
* sets in a job, but for the token, which the workflow passes in:
|
|
163
|
+
* `GITHUB_API_URL`, such as `https://api.github.com`; `GITHUB_REPOSITORY`,
|
|
164
|
+
* such as `noldova-com/tools`; and `GITHUB_TOKEN`, a token that may write
|
|
165
|
+
* the repository's contents, such as the job's own. It sends the token only
|
|
166
|
+
* to that API and never writes it anywhere.
|
|
167
|
+
*/
|
|
168
|
+
export declare class GitHubTags implements ITagHost {
|
|
169
|
+
/**
|
|
170
|
+
* Creates the tags over an environment, which it reads at each call.
|
|
171
|
+
*
|
|
172
|
+
* @param environment The environment variables, such as `process.env`.
|
|
173
|
+
* @param timeoutMilliseconds How long it waits for each answer of the API.
|
|
174
|
+
* Omitted, it waits a minute.
|
|
175
|
+
* @example
|
|
176
|
+
* ```ts
|
|
177
|
+
* import { GitHubTags } from "@noldova/tools.pipelines.github";
|
|
178
|
+
*
|
|
179
|
+
* const tags = new GitHubTags(process.env);
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
public constructor(environment: Readonly<Record<string, string | undefined>>, timeoutMilliseconds?: number);
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Reads the commit a tag points to, following an annotated tag to its
|
|
186
|
+
* commit.
|
|
187
|
+
*
|
|
188
|
+
* @param tag The tag's name, such as `v0.0.4`.
|
|
189
|
+
* @returns A promise of the commit's full id, `""` when the repository has
|
|
190
|
+
* no such tag, or a failed {@link StepResult}: when one of the three
|
|
191
|
+
* environment variables is missing or empty, naming it; when the tag points
|
|
192
|
+
* to something other than a commit, such as a tree; or when GitHub answers
|
|
193
|
+
* with another status, with the request, the status and GitHub's message,
|
|
194
|
+
* such as `GitHub answered GET repos/noldova-com/tools/git/ref/tags/v0.0.4
|
|
195
|
+
* with 403: Resource not accessible by integration`. It rejects with
|
|
196
|
+
* `JsonException`, from `@noldova/context.json`, for an answer that is not
|
|
197
|
+
* the JSON GitHub documents, with a `DOMException` named `TimeoutError`
|
|
198
|
+
* when GitHub doesn't answer within the timeout, and with the error `fetch`
|
|
199
|
+
* gives when GitHub can't be reached.
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts
|
|
202
|
+
* import { GitHubTags } from "@noldova/tools.pipelines.github";
|
|
203
|
+
*
|
|
204
|
+
* const commit = await new GitHubTags(process.env).readTagAsync("v0.0.4");
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
public readTagAsync(tag: string): Promise<string | StepResult>;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Creates a lightweight tag at a commit, unless the repository already has
|
|
211
|
+
* a tag of that name; it never moves a tag.
|
|
212
|
+
*
|
|
213
|
+
* @param tag The tag's name, such as `v0.0.4`.
|
|
214
|
+
* @param commit The commit's full id.
|
|
215
|
+
* @returns A promise of `true` when GitHub created the tag, or `false` when
|
|
216
|
+
* GitHub refuses it as unprocessable, status 422, and reading the tag then
|
|
217
|
+
* finds it, such as one another run made. Otherwise it is a failed
|
|
218
|
+
* {@link StepResult}, as {@link GitHubTags.readTagAsync} gives one: with the
|
|
219
|
+
* 422's message when reading finds no tag, and with the read's failure when
|
|
220
|
+
* the read fails. It rejects as {@link GitHubTags.readTagAsync} does.
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* import { GitHubTags } from "@noldova/tools.pipelines.github";
|
|
224
|
+
*
|
|
225
|
+
* const created = await new GitHubTags(process.env).createTagAsync("v0.0.4", "225059f4c1e6a3b2d8f7e9a0b1c2d3e4f5a6b7c8");
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
public createTagAsync(tag: string, commit: string): Promise<boolean | StepResult>;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* The `pipelines` command line a GitHub Actions workflow calls: it runs the
|
|
233
|
+
* source, archive, publish, nightly, prune and tag steps of
|
|
234
|
+
* `@noldova/tools.pipelines` in the current directory, which is the clone
|
|
235
|
+
* the steps check and where a folder value is. The prune step reaches
|
|
236
|
+
* GitHub Packages through {@link GitHubPackages}, and the tag step reaches
|
|
237
|
+
* GitHub through {@link GitHubTags}, each with the process's environment.
|
|
238
|
+
*/
|
|
239
|
+
export declare class PipelinesProgram {
|
|
240
|
+
/**
|
|
241
|
+
* Creates the program.
|
|
242
|
+
*
|
|
243
|
+
* @param output Where each message goes, such as a {@link GitHubStepOutput}.
|
|
244
|
+
* @example
|
|
245
|
+
* ```ts
|
|
246
|
+
* import { GitHubStepOutput, PipelinesProgram } from "@noldova/tools.pipelines.github";
|
|
247
|
+
*
|
|
248
|
+
* const program = new PipelinesProgram(new GitHubStepOutput(process.stdout, process.stderr));
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
public constructor(output: IStepOutput);
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Runs the step the first value names with the values after it.
|
|
255
|
+
*
|
|
256
|
+
* @param values The command line's values after the program, such as
|
|
257
|
+
* `["source", "0.0.4", "<commit>"]`.
|
|
258
|
+
* @returns A promise of the exit code: `0` after a step that succeeded,
|
|
259
|
+
* `1` after a step that failed, or when no step has the first value's name,
|
|
260
|
+
* after writing the usage line of every step.
|
|
261
|
+
* @throws `ProcessException`, from `@noldova/tools.pipelines`, when git,
|
|
262
|
+
* tar or npm can't start, and the other exceptions of the step that runs;
|
|
263
|
+
* a check that fails is a failed step, never an exception.
|
|
264
|
+
* @example
|
|
265
|
+
* ```ts
|
|
266
|
+
* import { GitHubStepOutput, PipelinesProgram } from "@noldova/tools.pipelines.github";
|
|
267
|
+
*
|
|
268
|
+
* const program = new PipelinesProgram(new GitHubStepOutput(process.stdout, process.stderr));
|
|
269
|
+
* process.exitCode = await program.runAsync(["source", "0.0.4", "225059f4c1e6a3b2d8f7e9a0b1c2d3e4f5a6b7c8"]);
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
public runAsync(values: readonly string[]): Promise<number>;
|
|
273
|
+
}
|
package/api/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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
|
+
export { GitHubPackages } from "../services/github-packages.js";
|
|
9
|
+
export { GitHubStepOutput } from "../services/github-step-output.js";
|
|
10
|
+
export { GitHubTags } from "../services/github-tags.js";
|
|
11
|
+
export { PipelinesProgram } from "../services/pipelines-program.js";
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
package/api/index.js.map
ADDED
|
@@ -0,0 +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,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/bin/pipelines.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright (c) Noldova.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
import { GitHubStepOutput } from "../services/github-step-output.js";
|
|
10
|
+
import { PipelinesProgram } from "../services/pipelines-program.js";
|
|
11
|
+
process.exitCode = await new PipelinesProgram(new GitHubStepOutput(process.stdout, process.stderr)).runAsync(process.argv.slice(2));
|
|
12
|
+
//# sourceMappingURL=pipelines.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipelines.js","sourceRoot":"","sources":["../../../../src/noldova.tools.pipelines.github/src/bin/pipelines.ts"],"names":[],"mappings":";AACA;;;;;;GAMG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAEpE,OAAO,CAAC,QAAQ,GAAG,MAAM,IAAI,gBAAgB,CAAC,IAAI,gBAAgB,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
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 { JsonException, JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { StepResult } from "@noldova/tools.pipelines";
|
|
10
|
+
import { Resources } from "../resources.js";
|
|
11
|
+
export class GitHubAnswer {
|
|
12
|
+
method;
|
|
13
|
+
resource;
|
|
14
|
+
status;
|
|
15
|
+
statusText;
|
|
16
|
+
contentType;
|
|
17
|
+
text;
|
|
18
|
+
constructor(method, resource, status, statusText, contentType, text) {
|
|
19
|
+
this.method = method;
|
|
20
|
+
this.resource = resource;
|
|
21
|
+
this.status = status;
|
|
22
|
+
this.statusText = statusText;
|
|
23
|
+
this.contentType = contentType;
|
|
24
|
+
this.text = text;
|
|
25
|
+
}
|
|
26
|
+
readBody() {
|
|
27
|
+
return JsonReader.parse(this.text, this.resource);
|
|
28
|
+
}
|
|
29
|
+
readItems() {
|
|
30
|
+
let value;
|
|
31
|
+
try {
|
|
32
|
+
value = JSON.parse(this.text);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
throw new JsonException(Resources.answerNotJson, this.resource);
|
|
36
|
+
}
|
|
37
|
+
return JsonReader.fromValue({ [Resources.itemsField]: value }, this.resource).readObjectArray(Resources.itemsField);
|
|
38
|
+
}
|
|
39
|
+
readMessage() {
|
|
40
|
+
const text = this.text.trim();
|
|
41
|
+
if (text.length === 0)
|
|
42
|
+
return this.statusText;
|
|
43
|
+
if (!Resources.jsonContentTypePattern.test(this.contentType) || !text.startsWith(Resources.jsonObjectStart))
|
|
44
|
+
return text;
|
|
45
|
+
return this.readBody().readOptionalString(Resources.messageField) ?? text;
|
|
46
|
+
}
|
|
47
|
+
toFailure() {
|
|
48
|
+
return StepResult.failed(Resources.formatApiFailed(this.method, this.resource, this.status, this.readMessage()));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=github-answer.js.map
|
|
@@ -0,0 +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,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,IAAI,CAAS;IAE7B,YAAmB,MAAc,EAAE,QAAgB,EAAE,MAAc,EAAE,UAAkB,EAAE,WAAmB,EAAE,IAAY;QACxH,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,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAEM,QAAQ;QACb,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACpD,CAAC;IAEM,SAAS;QACd,IAAI,KAAc,CAAC;QACnB,IAAI,CAAC;YACH,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChC,CAAC;QACD,MAAM,CAAC;YACL,MAAM,IAAI,aAAa,CAAC,SAAS,CAAC,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QAClE,CAAC;QAED,OAAO,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,eAAe,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IACtH,CAAC;IAEM,WAAW;QAChB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QAC9B,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;YACnB,OAAO,IAAI,CAAC,UAAU,CAAC;QACzB,IAAI,CAAC,SAAS,CAAC,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,eAAe,CAAC;YACzG,OAAO,IAAI,CAAC;QAEd,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC,kBAAkB,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,IAAI,CAAC;IAC5E,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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
export class GitHubConnection {
|
|
9
|
+
apiUrl;
|
|
10
|
+
repository;
|
|
11
|
+
token;
|
|
12
|
+
constructor(apiUrl, repository, token) {
|
|
13
|
+
this.apiUrl = apiUrl;
|
|
14
|
+
this.repository = repository;
|
|
15
|
+
this.token = token;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=github-connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-connection.js","sourceRoot":"","sources":["../../../../src/noldova.tools.pipelines.github/src/models/github-connection.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,OAAO,gBAAgB;IACX,MAAM,CAAS;IACf,UAAU,CAAS;IACnB,KAAK,CAAS;IAE9B,YAAmB,MAAc,EAAE,UAAkB,EAAE,KAAa;QAClE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noldova/tools.pipelines.github",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "api/index.js",
|
|
6
|
+
"types": "api/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"pipelines": "bin/pipelines.js"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/noldova-com/tools.git",
|
|
14
|
+
"directory": "src/noldova.tools.pipelines.github"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/noldova-com/tools#readme",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/noldova-com/tools/issues"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public",
|
|
22
|
+
"registry": "https://registry.npmjs.org/"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@noldova/context.json": "0.0.3",
|
|
26
|
+
"@noldova/tools.pipelines": "0.0.2"
|
|
27
|
+
},
|
|
28
|
+
"gitHead": "88191d48b554e81284f6c9662fd1752a861b4f28"
|
|
29
|
+
}
|
package/resources.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
export class Resources {
|
|
9
|
+
static acceptHeader = "Accept";
|
|
10
|
+
static annotatedTagType = "tag";
|
|
11
|
+
static annotationEscapes = [["%", "%25"], ["\r", "%0D"], ["\n", "%0A"]];
|
|
12
|
+
static answerNotJson = "GitHub's answer is not JSON.";
|
|
13
|
+
static apiMediaType = "application/vnd.github+json";
|
|
14
|
+
static apiTimeoutMilliseconds = 60_000;
|
|
15
|
+
static apiUrlVariable = "GITHUB_API_URL";
|
|
16
|
+
static apiVersion = "2022-11-28";
|
|
17
|
+
static apiVersionHeader = "X-GitHub-Api-Version";
|
|
18
|
+
static authorizationHeader = "Authorization";
|
|
19
|
+
static commitType = "commit";
|
|
20
|
+
static contentTypeHeader = "Content-Type";
|
|
21
|
+
static createdStatus = 201;
|
|
22
|
+
static createMethod = "POST";
|
|
23
|
+
static deletedStatus = 204;
|
|
24
|
+
static deleteMethod = "DELETE";
|
|
25
|
+
static foundStatus = 200;
|
|
26
|
+
static idField = "id";
|
|
27
|
+
static itemsField = "items";
|
|
28
|
+
static jsonContentType = "application/json";
|
|
29
|
+
static jsonContentTypePattern = /^application\/(?:[a-z0-9.-]+\+)?json\b/i;
|
|
30
|
+
static jsonObjectStart = "{";
|
|
31
|
+
static lineSeparator = "\n";
|
|
32
|
+
static messageField = "message";
|
|
33
|
+
static nameField = "name";
|
|
34
|
+
static notFoundStatus = 404;
|
|
35
|
+
static objectField = "object";
|
|
36
|
+
static packageNamePattern = /^@([^/]+)\/([^/]+)$/;
|
|
37
|
+
static packagesRegistry = "https://npm.pkg.github.com/";
|
|
38
|
+
static programName = "pipelines";
|
|
39
|
+
static readMethod = "GET";
|
|
40
|
+
static referencesPath = "git/refs";
|
|
41
|
+
static repositoryVariable = "GITHUB_REPOSITORY";
|
|
42
|
+
static shaField = "sha";
|
|
43
|
+
static tokenVariable = "GITHUB_TOKEN";
|
|
44
|
+
static typeField = "type";
|
|
45
|
+
static unprocessableStatus = 422;
|
|
46
|
+
static versionsPageSize = 100;
|
|
47
|
+
static formatErrorAnnotation(message) {
|
|
48
|
+
const escaped = Resources.annotationEscapes.reduce((text, [character, escape]) => text.replaceAll(character, escape), message);
|
|
49
|
+
return `::error::${escaped}${Resources.lineSeparator}`;
|
|
50
|
+
}
|
|
51
|
+
static formatVariableMissing(name) {
|
|
52
|
+
return `The environment variable ${name} is not set; the tag step needs it to reach GitHub.`;
|
|
53
|
+
}
|
|
54
|
+
static formatPruneVariableMissing(name) {
|
|
55
|
+
return `The environment variable ${name} is not set; the prune step needs it to reach GitHub.`;
|
|
56
|
+
}
|
|
57
|
+
static formatPackageNotScoped(packageName) {
|
|
58
|
+
return `${packageName} has no scope; a package on GitHub Packages is named @<owner>/<name>.`;
|
|
59
|
+
}
|
|
60
|
+
static formatVersionStillListed(packageName, version) {
|
|
61
|
+
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.`;
|
|
62
|
+
}
|
|
63
|
+
static formatVersionsResource(packageName) {
|
|
64
|
+
return packageName.replace(Resources.packageNamePattern, (_, owner, name) => `orgs/${owner}/packages/npm/${encodeURIComponent(name)}/versions`);
|
|
65
|
+
}
|
|
66
|
+
static formatVersionsPage(resource, page) {
|
|
67
|
+
return `${resource}?per_page=${Resources.versionsPageSize}&page=${page}`;
|
|
68
|
+
}
|
|
69
|
+
static formatVersionResource(resource, id) {
|
|
70
|
+
return `${resource}/${id}`;
|
|
71
|
+
}
|
|
72
|
+
static formatResource(repository, path) {
|
|
73
|
+
return `repos/${repository}/${path}`;
|
|
74
|
+
}
|
|
75
|
+
static formatTagReferencePath(tag) {
|
|
76
|
+
return `git/ref/tags/${tag}`;
|
|
77
|
+
}
|
|
78
|
+
static formatTagObjectPath(sha) {
|
|
79
|
+
return `git/tags/${sha}`;
|
|
80
|
+
}
|
|
81
|
+
static formatTagReference(tag) {
|
|
82
|
+
return `refs/tags/${tag}`;
|
|
83
|
+
}
|
|
84
|
+
static formatAuthorization(token) {
|
|
85
|
+
return `Bearer ${token}`;
|
|
86
|
+
}
|
|
87
|
+
static formatApiFailed(method, resource, status, message) {
|
|
88
|
+
return `GitHub answered ${method} ${resource} with ${status}: ${message}`;
|
|
89
|
+
}
|
|
90
|
+
static formatTagTargetInvalid(tag, type) {
|
|
91
|
+
return `${tag} points to a ${type}, not a commit.`;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=resources.js.map
|
package/resources.js.map
ADDED
|
@@ -0,0 +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,aAAa,GAAW,8BAA8B,CAAC;IACvE,MAAM,CAAU,YAAY,GAAW,6BAA6B,CAAC;IACrE,MAAM,CAAU,sBAAsB,GAAW,MAAM,CAAC;IACxD,MAAM,CAAU,cAAc,GAAW,gBAAgB,CAAC;IAC1D,MAAM,CAA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AAC,QAAgB,EAAE,EAAU;QAC9D,OAAO,GAAG,QAAQ,IAAI,EAAE,EAAE,CAAC;IAC7B,CAAC;IAEM,MAAM,CAAC,cAAc,CAAC,UAAkB,EAAE,IAAY;QAC3D,OAAO,SAAS,UAAU,IAAI,IAAI,EAAE,CAAC;IACvC,CAAC;IAEM,MAAM,CAAC,sBAAsB,CAAC,GAAW;QAC9C,OAAO,gBAAgB,GAAG,EAAE,CAAC;IAC/B,CAAC;IAEM,MAAM,CAAC,mBAAmB,CAAC,GAAW;QAC3C,OAAO,YAAY,GAAG,EAAE,CAAC;IAC3B,CAAC;IAEM,MAAM,CAAC,kBAAkB,CAAC,GAAW;QAC1C,OAAO,aAAa,GAAG,EAAE,CAAC;IAC5B,CAAC;IAEM,MAAM,CAAC,mBAAmB,CAAC,KAAa;QAC7C,OAAO,UAAU,KAAK,EAAE,CAAC;IAC3B,CAAC;IAEM,MAAM,CAAC,eAAe,CAAC,MAAc,EAAE,QAAgB,EAAE,MAAc,EAAE,OAAe;QAC7F,OAAO,mBAAmB,MAAM,IAAI,QAAQ,SAAS,MAAM,KAAK,OAAO,EAAE,CAAC;IAC5E,CAAC;IAEM,MAAM,CAAC,sBAAsB,CAAC,GAAW,EAAE,IAAY;QAC5D,OAAO,GAAG,GAAG,gBAAgB,IAAI,iBAAiB,CAAC;IACrD,CAAC;CACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
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 { GitHubAnswer } from "../models/github-answer.js";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
export class GitHubApi {
|
|
11
|
+
apiUrl;
|
|
12
|
+
token;
|
|
13
|
+
timeoutMilliseconds;
|
|
14
|
+
constructor(apiUrl, token, timeoutMilliseconds) {
|
|
15
|
+
this.apiUrl = apiUrl;
|
|
16
|
+
this.token = token;
|
|
17
|
+
this.timeoutMilliseconds = timeoutMilliseconds;
|
|
18
|
+
}
|
|
19
|
+
async requestAsync(method, resource, body) {
|
|
20
|
+
const response = await fetch(`${this.apiUrl}/${resource}`, {
|
|
21
|
+
method,
|
|
22
|
+
headers: {
|
|
23
|
+
[Resources.acceptHeader]: Resources.apiMediaType,
|
|
24
|
+
[Resources.authorizationHeader]: Resources.formatAuthorization(this.token),
|
|
25
|
+
[Resources.apiVersionHeader]: Resources.apiVersion,
|
|
26
|
+
...(body === undefined ? {} : { [Resources.contentTypeHeader]: Resources.jsonContentType })
|
|
27
|
+
},
|
|
28
|
+
signal: AbortSignal.timeout(this.timeoutMilliseconds),
|
|
29
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) })
|
|
30
|
+
});
|
|
31
|
+
return new GitHubAnswer(method, resource, response.status, response.statusText, response.headers.get(Resources.contentTypeHeader) ?? "", await response.text());
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# 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,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;IAE7C,YAAmB,MAAc,EAAE,KAAa,EAAE,mBAA2B;QAC3E,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;IACjD,CAAC;IAEM,KAAK,CAAC,YAAY,CAAC,MAAc,EAAE,QAAgB,EAAE,IAAuC;QACjG,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,QAAQ,EAAE,EAAE;YACzD,MAAM;YACN,OAAO,EAAE;gBACP,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,SAAS,CAAC,YAAY;gBAChD,CAAC,SAAS,CAAC,mBAAmB,CAAC,EAAE,SAAS,CAAC,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC;gBAC1E,CAAC,SAAS,CAAC,gBAAgB,CAAC,EAAE,SAAS,CAAC,UAAU;gBAClD,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,iBAAiB,CAAC,EAAE,SAAS,CAAC,eAAe,EAAE,CAAC;aAC5F;YACD,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,mBAAmB,CAAC;YACrD,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;SAC9D,CAAC,CAAC;QAEH,OAAO,IAAI,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,EAAE,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IAClK,CAAC;CACF"}
|
|
@@ -0,0 +1,78 @@
|
|
|
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 { StepResult } from "@noldova/tools.pipelines";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
import { GitHubApi } from "./github-api.js";
|
|
11
|
+
export class GitHubPackages {
|
|
12
|
+
environment;
|
|
13
|
+
timeoutMilliseconds;
|
|
14
|
+
versionIds = new Map();
|
|
15
|
+
registry = Resources.packagesRegistry;
|
|
16
|
+
constructor(environment, timeoutMilliseconds = Resources.apiTimeoutMilliseconds) {
|
|
17
|
+
this.environment = environment;
|
|
18
|
+
this.timeoutMilliseconds = timeoutMilliseconds;
|
|
19
|
+
}
|
|
20
|
+
async readVersionsAsync(packageName) {
|
|
21
|
+
const target = this.readTarget(packageName);
|
|
22
|
+
if (target instanceof StepResult)
|
|
23
|
+
return target;
|
|
24
|
+
const ids = await this.readIdsAsync(packageName, ...target);
|
|
25
|
+
return ids instanceof StepResult ? ids : [...ids.keys()];
|
|
26
|
+
}
|
|
27
|
+
async deleteVersionAsync(packageName, version) {
|
|
28
|
+
const target = this.readTarget(packageName);
|
|
29
|
+
if (target instanceof StepResult)
|
|
30
|
+
return target;
|
|
31
|
+
const ids = this.versionIds.get(packageName) ?? await this.readIdsAsync(packageName, ...target);
|
|
32
|
+
if (ids instanceof StepResult)
|
|
33
|
+
return ids;
|
|
34
|
+
const id = ids.get(version);
|
|
35
|
+
if (id === undefined)
|
|
36
|
+
return false;
|
|
37
|
+
const [api, resource] = target;
|
|
38
|
+
const answer = await api.requestAsync(Resources.deleteMethod, Resources.formatVersionResource(resource, id));
|
|
39
|
+
if (answer.status === Resources.deletedStatus) {
|
|
40
|
+
ids.delete(version);
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
if (answer.status !== Resources.notFoundStatus)
|
|
44
|
+
return answer.toFailure();
|
|
45
|
+
const listed = await this.readIdsAsync(packageName, api, resource);
|
|
46
|
+
if (listed instanceof StepResult)
|
|
47
|
+
return listed;
|
|
48
|
+
return listed.has(version) ? StepResult.failed(Resources.formatVersionStillListed(packageName, version)) : false;
|
|
49
|
+
}
|
|
50
|
+
async readIdsAsync(packageName, api, resource) {
|
|
51
|
+
const ids = new Map();
|
|
52
|
+
for (let page = 1;; page++) {
|
|
53
|
+
const answer = await api.requestAsync(Resources.readMethod, Resources.formatVersionsPage(resource, page));
|
|
54
|
+
if (answer.status !== Resources.foundStatus)
|
|
55
|
+
return answer.toFailure();
|
|
56
|
+
const items = answer.readItems();
|
|
57
|
+
for (const item of items)
|
|
58
|
+
ids.set(item.readString(Resources.nameField), item.readInteger(Resources.idField));
|
|
59
|
+
if (items.length < Resources.versionsPageSize)
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
this.versionIds.set(packageName, ids);
|
|
63
|
+
return ids;
|
|
64
|
+
}
|
|
65
|
+
readTarget(packageName) {
|
|
66
|
+
if (!Resources.packageNamePattern.test(packageName))
|
|
67
|
+
return StepResult.failed(Resources.formatPackageNotScoped(packageName));
|
|
68
|
+
const missing = [Resources.apiUrlVariable, Resources.tokenVariable].find(t => this.readVariable(t).length === 0);
|
|
69
|
+
if (missing !== undefined)
|
|
70
|
+
return StepResult.failed(Resources.formatPruneVariableMissing(missing));
|
|
71
|
+
const api = new GitHubApi(this.readVariable(Resources.apiUrlVariable), this.readVariable(Resources.tokenVariable), this.timeoutMilliseconds);
|
|
72
|
+
return [api, Resources.formatVersionsResource(packageName)];
|
|
73
|
+
}
|
|
74
|
+
readVariable(name) {
|
|
75
|
+
return this.environment[name] ?? "";
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# 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,EAAsB,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAE1E,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MA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E,CAAC;IACtC,CAAC;CACF"}
|
|
@@ -0,0 +1,24 @@
|
|
|
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 { Resources } from "../resources.js";
|
|
9
|
+
export class GitHubStepOutput {
|
|
10
|
+
standardOutput;
|
|
11
|
+
standardError;
|
|
12
|
+
constructor(standardOutput, standardError) {
|
|
13
|
+
this.standardOutput = standardOutput;
|
|
14
|
+
this.standardError = standardError;
|
|
15
|
+
}
|
|
16
|
+
writeSuccess(message) {
|
|
17
|
+
if (message.length > 0)
|
|
18
|
+
this.standardOutput.write(`${message}${Resources.lineSeparator}`);
|
|
19
|
+
}
|
|
20
|
+
writeFailure(message) {
|
|
21
|
+
this.standardError.write(Resources.formatErrorAnnotation(message));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=github-step-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-step-output.js","sourceRoot":"","sources":["../../../../src/noldova.tools.pipelines.github/src/services/github-step-output.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,OAAO,gBAAgB;IACV,cAAc,CAAwB;IACtC,aAAa,CAAwB;IAEtD,YAAmB,cAAqC,EAAE,aAAoC;QAC5F,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAEM,YAAY,CAAC,OAAe;QACjC,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;YACpB,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,GAAG,OAAO,GAAG,SAAS,CAAC,aAAa,EAAE,CAAC,CAAC;IACtE,CAAC;IAEM,YAAY,CAAC,OAAe;QACjC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,SAAS,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC;IACrE,CAAC;CACF"}
|
|
@@ -0,0 +1,68 @@
|
|
|
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 { StepResult } from "@noldova/tools.pipelines";
|
|
9
|
+
import { GitHubAnswer } from "../models/github-answer.js";
|
|
10
|
+
import { GitHubConnection } from "../models/github-connection.js";
|
|
11
|
+
import { Resources } from "../resources.js";
|
|
12
|
+
import { GitHubApi } from "./github-api.js";
|
|
13
|
+
export class GitHubTags {
|
|
14
|
+
environment;
|
|
15
|
+
timeoutMilliseconds;
|
|
16
|
+
constructor(environment, timeoutMilliseconds = Resources.apiTimeoutMilliseconds) {
|
|
17
|
+
this.environment = environment;
|
|
18
|
+
this.timeoutMilliseconds = timeoutMilliseconds;
|
|
19
|
+
}
|
|
20
|
+
async readTagAsync(tag) {
|
|
21
|
+
const connection = this.readConnection();
|
|
22
|
+
if (connection instanceof StepResult)
|
|
23
|
+
return connection;
|
|
24
|
+
const reference = await this.requestAsync(connection, Resources.readMethod, Resources.formatTagReferencePath(tag));
|
|
25
|
+
if (reference.status === Resources.notFoundStatus)
|
|
26
|
+
return "";
|
|
27
|
+
if (reference.status !== Resources.foundStatus)
|
|
28
|
+
return reference.toFailure();
|
|
29
|
+
let target = reference.readBody().readObject(Resources.objectField);
|
|
30
|
+
while (target.readString(Resources.typeField) === Resources.annotatedTagType) {
|
|
31
|
+
const tagObject = await this.requestAsync(connection, Resources.readMethod, Resources.formatTagObjectPath(target.readString(Resources.shaField)));
|
|
32
|
+
if (tagObject.status !== Resources.foundStatus)
|
|
33
|
+
return tagObject.toFailure();
|
|
34
|
+
target = tagObject.readBody().readObject(Resources.objectField);
|
|
35
|
+
}
|
|
36
|
+
const type = target.readString(Resources.typeField);
|
|
37
|
+
if (type !== Resources.commitType)
|
|
38
|
+
return StepResult.failed(Resources.formatTagTargetInvalid(tag, type));
|
|
39
|
+
return target.readString(Resources.shaField);
|
|
40
|
+
}
|
|
41
|
+
async createTagAsync(tag, commit) {
|
|
42
|
+
const connection = this.readConnection();
|
|
43
|
+
if (connection instanceof StepResult)
|
|
44
|
+
return connection;
|
|
45
|
+
const answer = await this.requestAsync(connection, Resources.createMethod, Resources.referencesPath, { ref: Resources.formatTagReference(tag), sha: commit });
|
|
46
|
+
if (answer.status === Resources.createdStatus)
|
|
47
|
+
return true;
|
|
48
|
+
if (answer.status !== Resources.unprocessableStatus)
|
|
49
|
+
return answer.toFailure();
|
|
50
|
+
const found = await this.readTagAsync(tag);
|
|
51
|
+
if (found instanceof StepResult)
|
|
52
|
+
return found;
|
|
53
|
+
return found.length > 0 ? false : answer.toFailure();
|
|
54
|
+
}
|
|
55
|
+
readConnection() {
|
|
56
|
+
const missing = [Resources.apiUrlVariable, Resources.repositoryVariable, Resources.tokenVariable].find(t => this.readVariable(t).length === 0);
|
|
57
|
+
if (missing !== undefined)
|
|
58
|
+
return StepResult.failed(Resources.formatVariableMissing(missing));
|
|
59
|
+
return new GitHubConnection(this.readVariable(Resources.apiUrlVariable), this.readVariable(Resources.repositoryVariable), this.readVariable(Resources.tokenVariable));
|
|
60
|
+
}
|
|
61
|
+
readVariable(name) {
|
|
62
|
+
return this.environment[name] ?? "";
|
|
63
|
+
}
|
|
64
|
+
async requestAsync(connection, method, path, body) {
|
|
65
|
+
return new GitHubApi(connection.apiUrl, connection.token, this.timeoutMilliseconds).requestAsync(method, Resources.formatResource(connection.repository, path), body);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=github-tags.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-tags.js","sourceRoot":"","sources":["../../../../src/noldova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-0,0 +1,26 @@
|
|
|
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 { ArchiveStep, CommandLine, Git, NightlyStep, Npm, ProcessRunner, PruneStep, PublishStep, SourceStep, TagStep, Tar } from "@noldova/tools.pipelines";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
import { GitHubPackages } from "./github-packages.js";
|
|
11
|
+
import { GitHubTags } from "./github-tags.js";
|
|
12
|
+
export class PipelinesProgram {
|
|
13
|
+
output;
|
|
14
|
+
constructor(output) {
|
|
15
|
+
this.output = output;
|
|
16
|
+
}
|
|
17
|
+
async runAsync(values) {
|
|
18
|
+
const processRunner = new ProcessRunner();
|
|
19
|
+
const git = new Git(processRunner, process.cwd());
|
|
20
|
+
const npm = new Npm(processRunner, process.cwd());
|
|
21
|
+
const archiveStep = new ArchiveStep(git, new Tar(processRunner));
|
|
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))];
|
|
23
|
+
return new CommandLine(Resources.programName, steps, this.output).runAsync(values);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=pipelines-program.js.map
|
|
@@ -0,0 +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,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC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