@mark1russell7/workflow-github 0.0.0-bootstrap.0 → 0.1.0
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 +18 -1
- package/build/index.d.ts +207 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +1728 -0
- package/build/index.js.map +1 -0
- package/package.json +42 -6
- package/src/expression.ts +374 -0
- package/src/index.ts +30 -0
- package/src/inject.ts +307 -0
- package/src/language.ts +142 -0
- package/src/yaml.ts +670 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mark Russell
|
|
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,20 @@
|
|
|
1
1
|
# @mark1russell7/workflow-github
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The GitHub Actions add-on of the workflow language. It reads the YAML of a GitHub workflow into a workflow document, and it writes the document back as YAML.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { checkGitHub, fromGitHub, toGitHub } from "@mark1russell7/workflow-github";
|
|
7
|
+
|
|
8
|
+
const { doc, issues } = fromGitHub(text, { file: "ci.yml", workspace: "main" });
|
|
9
|
+
const problems = checkGitHub(doc); // the checks of the workflow language, with the contexts of GitHub
|
|
10
|
+
const yaml = toGitHub(doc); // the same text when the document did not change
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
- Each GitHub expression `${{ ... }}` becomes a document of the formula kit. A text with expressions becomes a `template`. An `if:` without `${{ }}` is an expression too.
|
|
14
|
+
- `secrets.NAME` becomes a secret document. It is a reference, not a value.
|
|
15
|
+
- A `uses:` step, a `run:` step and a call of a reusable workflow are kinds of the namespace `github`. Only GitHub runs them.
|
|
16
|
+
- Each key that the core does not model stays in the layer `github` of its node, thus the round trip keeps it.
|
|
17
|
+
- The export changes only the edited values of the source tree. The comments and the forms of the other values stay.
|
|
18
|
+
- `parseExpression` and `printExpression` read and write one expression. `printExpression` gives a canonical text.
|
|
19
|
+
|
|
20
|
+
The design is in [`docs/WORKFLOW.md`](https://github.com/mark1russell7/coeval/blob/main/docs/WORKFLOW.md).
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { EditResult, RefChoice, WorkflowCheckOptions, WorkflowIssue } from "@mark1russell7/workflow";
|
|
2
|
+
import { FormulaProfile, Language, Machine } from "@mark1russell7/coeval";
|
|
3
|
+
/**
|
|
4
|
+
* The script injection rule of GitHub. GitHub puts the value of each `${{ }}` into the text of a script before the
|
|
5
|
+
* shell reads it. A value that a person outside the repository writes (the title of an issue, the name of a branch)
|
|
6
|
+
* can thus become a command. The safe form reads the value from an environment variable.
|
|
7
|
+
*/
|
|
8
|
+
type Key = string | number;
|
|
9
|
+
/** The trust of a read in a script: safe, written by a person outside the repository, or not known. */
|
|
10
|
+
type ReadTrust = "trusted" | "outside" | "unknown";
|
|
11
|
+
/**
|
|
12
|
+
* This function gives the trust of a reference in a script. A read of the list `TRUSTED_READS` is safe. A read of
|
|
13
|
+
* `github.event` or `github.head_ref` comes from outside. Each other read is not known: an input, the output of a step,
|
|
14
|
+
* a value of `env` or the name of a branch.
|
|
15
|
+
*
|
|
16
|
+
* @param path - The path of the reference, for example `["names", "github", "event", "issue", "title"]`.
|
|
17
|
+
* @returns The trust.
|
|
18
|
+
*/
|
|
19
|
+
export declare function readTrust(path: readonly unknown[]): ReadTrust;
|
|
20
|
+
/**
|
|
21
|
+
* This function finds each script that reads an unsafe value with `${{ }}`. A read from outside the repository
|
|
22
|
+
* (`github.event`, `github.head_ref`) is an error. A read that is not known is a warning. Each problem has the code
|
|
23
|
+
* `script-injection`, and `moveToEnv` corrects it.
|
|
24
|
+
*
|
|
25
|
+
* A script with a text `${{` that no reader read is also an error, with the code `raw-expression`. The export
|
|
26
|
+
* writes it as an expression, but the check did not see it. A typed script with an open `${{` gives this error.
|
|
27
|
+
*
|
|
28
|
+
* @param doc - The workflow document.
|
|
29
|
+
* @returns The problems.
|
|
30
|
+
*/
|
|
31
|
+
export declare function scriptInjections(doc: unknown): WorkflowIssue[];
|
|
32
|
+
/**
|
|
33
|
+
* This function moves each unsafe value of a script to `env` of its step. The script then reads the variable, and
|
|
34
|
+
* the shell does not read the value as code. The same value gets one variable. A new name is not a name of `env` of
|
|
35
|
+
* the job or of the workflow, thus the move hides no value.
|
|
36
|
+
*
|
|
37
|
+
* @param doc - The workflow document.
|
|
38
|
+
* @param at - The JSON path of the script, as the problem of `scriptInjections` gives it.
|
|
39
|
+
* @returns The new document, or the reason of a refusal.
|
|
40
|
+
*/
|
|
41
|
+
export declare function moveToEnv(doc: unknown, at: readonly Key[]): EditResult;
|
|
42
|
+
/**
|
|
43
|
+
* The GitHub expression grammar, as documents of the formula kit.
|
|
44
|
+
*
|
|
45
|
+
* The add-on has its own parser until W8. The syntax kit of the kernel has no index step, no `-` in a name, no
|
|
46
|
+
* function names without case and no filter step `.*`. The roadmap row W8 adds them, and then this grammar becomes a
|
|
47
|
+
* profile of the syntax kit.
|
|
48
|
+
*/
|
|
49
|
+
/** A problem of an expression text: its offset in the text, and a message. */
|
|
50
|
+
interface ExpressionIssue {
|
|
51
|
+
readonly offset: number;
|
|
52
|
+
readonly message: string;
|
|
53
|
+
}
|
|
54
|
+
/** The result of `parseExpression`. */
|
|
55
|
+
type ExpressionResult = {
|
|
56
|
+
readonly ok: true;
|
|
57
|
+
readonly doc: unknown;
|
|
58
|
+
} | {
|
|
59
|
+
readonly ok: false;
|
|
60
|
+
readonly issue: ExpressionIssue;
|
|
61
|
+
};
|
|
62
|
+
/** The functions of GitHub, by their names in lower case. The value is the name of the operation. */
|
|
63
|
+
export declare const GITHUB_FUNCTIONS: Readonly<Record<string, string>>;
|
|
64
|
+
/**
|
|
65
|
+
* This function reads a GitHub expression, the text between `${{` and `}}`, into a document of the formula kit.
|
|
66
|
+
*
|
|
67
|
+
* - A context is a reference from `names`, for example `inputs.version` gives `["names", "inputs", "version"]`.
|
|
68
|
+
* - `secrets.NAME` gives the secret document `{ type: "secret", value: "NAME" }`.
|
|
69
|
+
* - The operators give `and`, `or` and the operations `not`, `eq`, `ne`, `lt`, `le`, `gt` and `ge`.
|
|
70
|
+
* - An index of a value that is not a reference gives the operation `at`, and `.*` gives the operation `pluck`.
|
|
71
|
+
* - A literal at the top gives a `lit` document, thus a text part of a template stays different from a literal.
|
|
72
|
+
*
|
|
73
|
+
* @param text - The text of the expression.
|
|
74
|
+
* @returns The document, or the problem with its offset.
|
|
75
|
+
*/
|
|
76
|
+
export declare function parseExpression(text: string): ExpressionResult;
|
|
77
|
+
/**
|
|
78
|
+
* This function writes a document of the formula kit as a GitHub expression, without `${{` and `}}`. The text is
|
|
79
|
+
* the canonical text: one space around each operator, and the GitHub names of the functions.
|
|
80
|
+
*
|
|
81
|
+
* @param doc - The document.
|
|
82
|
+
* @returns The text.
|
|
83
|
+
*/
|
|
84
|
+
export declare function printExpression(doc: unknown): string;
|
|
85
|
+
/** One part of a text with expressions: a text part, or an expression with its source text. */
|
|
86
|
+
type TextPart = {
|
|
87
|
+
readonly text: string;
|
|
88
|
+
} | {
|
|
89
|
+
readonly source: string;
|
|
90
|
+
readonly offset: number;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* This function splits a text at each `${{ ... }}`. The end of an expression is the first `}}` outside a quoted text.
|
|
94
|
+
*
|
|
95
|
+
* @param text - The text.
|
|
96
|
+
* @returns The parts, or `undefined` when an expression has no end.
|
|
97
|
+
*/
|
|
98
|
+
export declare function splitText(text: string): TextPart[] | undefined;
|
|
99
|
+
/** The version of the GitHub add-on language. */
|
|
100
|
+
export declare const GITHUB_VERSION = "0.1.0";
|
|
101
|
+
/** The formula profile of GitHub: the operations of the workflow language and the operations of GitHub. */
|
|
102
|
+
export declare const GITHUB_OPS: FormulaProfile;
|
|
103
|
+
/** The GitHub add-on language: the namespace `github`. */
|
|
104
|
+
export declare const GITHUB_LANGUAGE: Language;
|
|
105
|
+
/**
|
|
106
|
+
* This function gives the machine of a GitHub workflow: the workflow language with the GitHub profile and the
|
|
107
|
+
* namespace `github`.
|
|
108
|
+
*
|
|
109
|
+
* @param more - The languages of other add-ons, in order.
|
|
110
|
+
* @returns The machine.
|
|
111
|
+
*/
|
|
112
|
+
export declare function githubMachine(...more: readonly Language[]): Machine;
|
|
113
|
+
/** The contexts of GitHub that an expression can read, beside the names of the workflow language. */
|
|
114
|
+
export declare const GITHUB_NAMES: readonly string[];
|
|
115
|
+
/** The call namespaces of GitHub: an input of such a call can hold a secret. */
|
|
116
|
+
export declare const GITHUB_CALLS: readonly string[];
|
|
117
|
+
/** The values of the GitHub contexts that a builder offers at each position, as reference documents. */
|
|
118
|
+
export declare const GITHUB_CONTEXT_CHOICES: readonly RefChoice[];
|
|
119
|
+
/** The name of the format of the layer of the add-on. */
|
|
120
|
+
export declare const GITHUB_LAYER = "github/1";
|
|
121
|
+
/** A problem of an import, at the path of its value in the YAML. */
|
|
122
|
+
interface ImportIssue {
|
|
123
|
+
readonly level: "error" | "warning";
|
|
124
|
+
readonly at: readonly (string | number)[];
|
|
125
|
+
readonly message: string;
|
|
126
|
+
}
|
|
127
|
+
/** The result of `fromGitHub`: the workflow document, and the problems of the import. */
|
|
128
|
+
interface ImportResult {
|
|
129
|
+
/** `false` when the text is not a workflow. Then the document is absent. */
|
|
130
|
+
readonly ok: boolean;
|
|
131
|
+
readonly doc?: {
|
|
132
|
+
readonly type: "workflow";
|
|
133
|
+
readonly value: Record<string, unknown>;
|
|
134
|
+
};
|
|
135
|
+
readonly issues: readonly ImportIssue[];
|
|
136
|
+
}
|
|
137
|
+
/** The options of `fromGitHub`. */
|
|
138
|
+
interface ImportOptions {
|
|
139
|
+
/** The name of the file. A workflow without a name gets it. */
|
|
140
|
+
readonly file?: string;
|
|
141
|
+
/** The id of the workspace of the workflow. The default is `default`. */
|
|
142
|
+
readonly workspace?: string;
|
|
143
|
+
}
|
|
144
|
+
type Rec = Record<string, unknown>;
|
|
145
|
+
/** This function tells if two JSON values are equal. The order of the keys of a record does not count. */
|
|
146
|
+
export declare function sameJson(a: unknown, b: unknown): boolean;
|
|
147
|
+
/** The value of a text of GitHub: a text, or the document of its expressions, and the problems of the read. */
|
|
148
|
+
interface TextValue {
|
|
149
|
+
readonly value: unknown;
|
|
150
|
+
readonly problems: readonly string[];
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* This function reads a text value of GitHub. A text without `${{` stays a text, unless it is a condition. A text that
|
|
154
|
+
* is one expression gives its document. Another text with expressions gives a `template`. A text with a bad expression
|
|
155
|
+
* stays a text, with a problem.
|
|
156
|
+
*
|
|
157
|
+
* @param text - The text.
|
|
158
|
+
* @param condition - `true` for the text of `if`, which is an expression without `${{ }}`.
|
|
159
|
+
* @returns The value and the problems.
|
|
160
|
+
*/
|
|
161
|
+
export declare function readText(text: string, condition?: boolean): TextValue;
|
|
162
|
+
/**
|
|
163
|
+
* This function reads the YAML of a GitHub workflow into a workflow document. It does not throw.
|
|
164
|
+
*
|
|
165
|
+
* - The parser is the `yaml` package. A text with anchors or aliases is refused.
|
|
166
|
+
* - Each expression becomes a document, and the layer keeps its source text.
|
|
167
|
+
* - Each key that the core does not model stays in the layer `github` of its workflow, job, step or trigger.
|
|
168
|
+
* - The layer of the workflow keeps the source text, thus `toGitHub` changes only the edited values.
|
|
169
|
+
*
|
|
170
|
+
* @param text - The YAML text.
|
|
171
|
+
* @param options - The name of the file and the workspace.
|
|
172
|
+
* @returns The document and the problems.
|
|
173
|
+
*/
|
|
174
|
+
export declare function fromGitHub(text: string, options?: ImportOptions): ImportResult;
|
|
175
|
+
/**
|
|
176
|
+
* This function writes a workflow document as the plain value of a GitHub workflow: the value that the YAML of the
|
|
177
|
+
* file gives. Each expression gives its source text when its document did not change.
|
|
178
|
+
*
|
|
179
|
+
* @param doc - The workflow document.
|
|
180
|
+
* @returns The value.
|
|
181
|
+
*/
|
|
182
|
+
export declare function toGitHubObject(doc: unknown): Rec;
|
|
183
|
+
/**
|
|
184
|
+
* This function writes a workflow document as the YAML of a GitHub workflow.
|
|
185
|
+
*
|
|
186
|
+
* - A document from `fromGitHub` keeps its source text in its layer. When the document did not change, the result is
|
|
187
|
+
* that text, byte for byte.
|
|
188
|
+
* - After an edit, the export changes only the edited values of the source tree. The comments and the forms of the
|
|
189
|
+
* other values stay.
|
|
190
|
+
* - A document with no source text gives new YAML.
|
|
191
|
+
*
|
|
192
|
+
* @param doc - The workflow document.
|
|
193
|
+
* @returns The YAML text.
|
|
194
|
+
*/
|
|
195
|
+
export declare function toGitHub(doc: unknown): string;
|
|
196
|
+
/**
|
|
197
|
+
* This function checks a workflow from GitHub with the machine of the add-on. The contexts of GitHub are names, an
|
|
198
|
+
* input of a `github` call can hold a secret, and the secrets of the repository need no declaration. A script that
|
|
199
|
+
* reads an untrusted value with `${{ }}` is an error (`scriptInjections`).
|
|
200
|
+
*
|
|
201
|
+
* @param doc - The workflow document.
|
|
202
|
+
* @param options - More options of `checkWorkflow`.
|
|
203
|
+
* @returns The problems.
|
|
204
|
+
*/
|
|
205
|
+
export declare function checkGitHub(doc: unknown, options?: WorkflowCheckOptions): readonly WorkflowIssue[];
|
|
206
|
+
export type { ExpressionIssue, ExpressionResult, ImportIssue, ImportOptions, ImportResult, ReadTrust, TextPart, TextValue };
|
|
207
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/inject.ts","../src/expression.ts","../src/language.ts","../src/yaml.ts","../src/index.ts"],"mappings":";;;;;;;KASK;;KA4CO;;;;;;;;;wBAUI,UAAU,2BAA2B;;;;;;;;;;;;wBA8IrC,iBAAiB,eAAe;;;;;;;;;;wBAqDhC,UAAU,cAAc,aAAa,QAAQ;;;;;;;;;UCvP5C;WACN;WACA;;;KAIC;WAA8B;WAAmB;;WAA4B;WAAoB,OAAO;;;qBAGvG,kBAAkB,SAAS;;;;;;;;;;;;;wBA6PxB,gBAAgB,eAAe;;;;;;;;wBAiE/B,gBAAgB;;KAKpB;WAAsB;;WAA4B;WAAyB;;;;;;;;wBAQvE,UAAU,eAAe;;qBC/U5B;;qBAoDA,YAAY;;qBAoCZ,iBAAiB;;;;;;;;wBAcd,iBAAiB,eAAe,aAAa;;qBAKhD;;qBAGA;;qBAGA,iCAAiC;;qBC5HjC;;UAGI;WACN;WACA;WACA;;;UAIM;;WAEN;WACA;aAAiB;aAA2B,OAAO;;WACnD,iBAAiB;;;UAIX;;WAEN;;WAEA;;KAGN,MAAM;;wBAUK,SAAS,YAAY;;UAoBpB;WACN;WACA;;;;;;;;;;;wBAYK,SAAS,cAAc,sBAAoB;;;;;;;;;;;;;wBA6U3C,WAAW,cAAc,UAAS,gBAAqB;;;;;;;;wBA6LvD,eAAe,eAAe;;;;;;;;;;;;;wBA8D9B,SAAS;;;;;;;;;;wBC9nBT,YAAY,cAAc,UAAS,gCAAqC"}
|