Compare commits
108 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6513b0d15d | |||
| 207cfa12c0 | |||
| 28ab3928fd | |||
| afbe42bffe | |||
| a324b8b9dc | |||
| 4f7d03ed0c | |||
| 4ddbbc9db7 | |||
| 3ea2cf1829 | |||
| 2c30f2f45f | |||
| cf2d9cd0b9 | |||
| 8f2f59092e | |||
| 5de89b0f8e | |||
| f4afa48ea4 | |||
| af5dd4b91e | |||
| 12d28370dc | |||
| 833b6fcac5 | |||
| cd7fabeb7f | |||
| 26da52bdf8 | |||
| 31aa95fb10 | |||
| b912482163 | |||
| 41436c6570 | |||
| 468b68840b | |||
| 57a77551b0 | |||
| a34a500176 | |||
| d7ae6f88f1 | |||
| 588c457cea | |||
| 82985934af | |||
| cb3ec583e0 | |||
| 7c3b116b19 | |||
| 4a6134be6c | |||
| 0080226132 | |||
| 896f780991 | |||
| 63b170f2a6 | |||
| 94451fa8f2 | |||
| 41e05b8ad1 | |||
| 5362fb1841 | |||
| 4e1f7cd9ac | |||
| 5c785ab41b | |||
| 9d246960f3 | |||
| eefd820cc5 | |||
| 58712f4d46 | |||
| 0bd67083ff | |||
| 40c20d5504 | |||
| c6cde72b37 | |||
| d47636092a | |||
| e292f8ca51 | |||
| 8f4080074b | |||
| b04e5db100 | |||
| 2795997f4c | |||
| 413ae51185 | |||
| 8bc0c5636e | |||
| 58bf3b35cc | |||
| 124ee84d1f | |||
| c4d478d459 | |||
| 9945ec321b | |||
| 5cb4007629 | |||
| 07fa29649e | |||
| 7bb2962bb0 | |||
| 3904c64796 | |||
| 48ad5e5251 | |||
| 317c4fcd63 | |||
| bf97052855 | |||
| dd8930fd74 | |||
| 2449e5cea1 | |||
| dba3cf5d96 | |||
| 804f83828f | |||
| cf2fd6332f | |||
| 51649f27f8 | |||
| 74db91e276 | |||
| a1d81c730f | |||
| 18d1bd9734 | |||
| fc6a1d3e0c | |||
| 6df34a78ce | |||
| aee5c2b919 | |||
| 8cdfe810db | |||
| 17a680df41 | |||
| 11d3fc25ee | |||
| d2783ed733 | |||
| 6d0f74e38b | |||
| 2ecbeafacb | |||
| a4d3fb1a3e | |||
| 83cac82450 | |||
| fc2bacfcdc | |||
| 7d8a7c11a6 | |||
| e37d7620d6 | |||
| 6e8cbc3e8c | |||
| d0916938ce | |||
| 488879804f | |||
| 736dd1a66c | |||
| d58deaf097 | |||
| f4a32c43cf | |||
| 5aed7594cf | |||
| 81094dc942 | |||
| f29fffce7e | |||
| 8fe871750e | |||
| 709d0d73c6 | |||
| febac16edd | |||
| 1ffef93f4c | |||
| 41b8fa9231 | |||
| 053accfafc | |||
| fe25433a45 | |||
| 0ee008991d | |||
| cf4dce7f71 | |||
| 4b479b0296 | |||
| 53f5a4ce69 | |||
| d08fed3cf5 | |||
| d5ef2f1539 | |||
| 1727735bd4 |
+1
-1
@@ -1 +1 @@
|
||||
* @actions/actions-experience
|
||||
* @actions/actions-workflow-development-reviewers
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
name: Create release PR
|
||||
|
||||
run-name: Create release PR for v${{ github.event.inputs.version }}
|
||||
run-name: Create release PR for new ${{ github.event.inputs.version }} version
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
required: true
|
||||
description: "Version to bump `package.json` to (format: x.y.z)"
|
||||
type: choice
|
||||
description: "What type of release is this"
|
||||
options:
|
||||
- "major"
|
||||
- "minor"
|
||||
- "patch"
|
||||
|
||||
jobs:
|
||||
create-release-pr:
|
||||
@@ -31,21 +36,27 @@ jobs:
|
||||
git config --global user.email "github-actions@github.com"
|
||||
git config --global user.name "GitHub Actions"
|
||||
|
||||
git checkout -b release/${{ inputs.version }}
|
||||
NEW_VERSION=$(./script/workflows/increment-version.sh ${{ inputs.version }})
|
||||
|
||||
npx lerna version ${{ inputs.version }} --yes --no-push --no-git-tag-version --force-publish
|
||||
git checkout -b release/$NEW_VERSION
|
||||
|
||||
npx lerna version $NEW_VERSION --yes --no-push --no-git-tag-version --force-publish
|
||||
|
||||
git add **/package.json package-lock.json lerna.json
|
||||
git commit -m "Release extension version ${{ inputs.version }}"
|
||||
git commit -m "Release extension version $NEW_VERSION"
|
||||
|
||||
git push --set-upstream origin release/${{ inputs.version }}
|
||||
git push --set-upstream origin release/$NEW_VERSION
|
||||
|
||||
echo "new_version=$NEW_VERSION" >> $GITHUB_ENV
|
||||
|
||||
- name: Create PR
|
||||
run: |
|
||||
LAST_PR=$(gh pr list --repo ${{ github.repository }} --limit 1 --state merged --search "Release version" --json number | jq -r '.[0].number')
|
||||
./script/workflows/generate-release-notes.sh $LAST_PR ${{ env.new_version }}
|
||||
gh pr create \
|
||||
--title "Release version ${{ inputs.version }}" \
|
||||
--body "Release version ${{ inputs.version }}" \
|
||||
--title "Release version ${{ env.new_version }}" \
|
||||
--body-file releasenotes.md \
|
||||
--base main \
|
||||
--head release/${{ inputs.version }}
|
||||
--head release/${{ env.new_version }}
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
*/node_modules
|
||||
*/dist
|
||||
|
||||
lerna-debug.log
|
||||
node_modules
|
||||
.DS_Store
|
||||
+10
-2
@@ -8,6 +8,8 @@ Hi there! We're thrilled that you'd like to contribute to this project. Your hel
|
||||
|
||||
We accept pull requests for bug fixes and features where we've discussed the approach in an issue and given the go-ahead for a community member to work on it. We'd also love to hear about ideas for new features as issues.
|
||||
|
||||
We track issues on our project board [here](https://github.com/orgs/github/projects/9557/views/1).
|
||||
|
||||
Please do:
|
||||
|
||||
* Check existing issues to verify that the [bug][bug issues] or [feature request][feature request issues] has not already been submitted.
|
||||
@@ -21,7 +23,7 @@ Please avoid:
|
||||
|
||||
* Opening pull requests for issues marked `needs-design`, `needs-investigation`, or `blocked`.
|
||||
|
||||
Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license) to the public under the [project's open source license](LICENSE.md).
|
||||
Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license) to the public under the [project's open source license](LICENSE).
|
||||
|
||||
Please note that this project is released with a [Contributor Code of Conduct][code-of-conduct]. By participating in this project you agree to abide by its terms.
|
||||
|
||||
@@ -60,4 +62,10 @@ Please also look at the `README.md` files for each package for additional notes
|
||||
|
||||
- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
|
||||
- [Using Pull Requests](https://help.github.com/articles/about-pull-requests/)
|
||||
- [GitHub Help](https://help.github.com)
|
||||
- [GitHub Help](https://help.github.com)
|
||||
|
||||
|
||||
[bug issues]: https://github.com/actions/languageservices/labels/bug
|
||||
[feature request issues]: https://github.com/actions/languageservices/labels/enhancement
|
||||
[hw]: https://github.com/actions/languageservices/labels/help%20wanted
|
||||
[gfi]: https://github.com/actions/languageservices/labels/good%20first%20issue
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@actions/expressions",
|
||||
"version": "0.3.1",
|
||||
"version": "0.3.7",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"source": "./src/index.ts",
|
||||
|
||||
@@ -32,7 +32,7 @@ export class Evaluator implements ExprVisitor<data.ExpressionData> {
|
||||
return this.eval(this.n);
|
||||
}
|
||||
|
||||
private eval(n: Expr): data.ExpressionData {
|
||||
protected eval(n: Expr): data.ExpressionData {
|
||||
return n.accept(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@actions/languageserver",
|
||||
"version": "0.3.1",
|
||||
"version": "0.3.7",
|
||||
"description": "Language server for GitHub Actions",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
@@ -43,8 +43,8 @@
|
||||
"watch": "tsc --build tsconfig.build.json --watch"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/languageservice": "^0.3.1",
|
||||
"@actions/workflow-parser": "^0.3.1",
|
||||
"@actions/languageservice": "^0.3.7",
|
||||
"@actions/workflow-parser": "^0.3.7",
|
||||
"@octokit/rest": "^19.0.7",
|
||||
"@octokit/types": "^9.0.0",
|
||||
"vscode-languageserver": "^8.0.2",
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import {Octokit} from "@octokit/rest";
|
||||
|
||||
export function getClient(token: string, userAgent?: string): Octokit {
|
||||
export function getClient(token: string, userAgent?: string, apiUrl?: string): Octokit {
|
||||
return new Octokit({
|
||||
auth: token,
|
||||
userAgent: userAgent || `GitHub Actions Language Server`
|
||||
userAgent: userAgent || `GitHub Actions Language Server`,
|
||||
baseUrl: apiUrl
|
||||
});
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ export function initConnection(connection: Connection) {
|
||||
const options = params.initializationOptions as InitializationOptions;
|
||||
|
||||
if (options.sessionToken) {
|
||||
client = getClient(options.sessionToken, options.userAgent);
|
||||
client = getClient(options.sessionToken, options.userAgent, options.gitHubApiUrl);
|
||||
}
|
||||
|
||||
if (options.repos) {
|
||||
|
||||
@@ -28,6 +28,7 @@ export async function getSecrets(
|
||||
}
|
||||
|
||||
const eventsConfig = workflowContext?.template?.events;
|
||||
|
||||
if (eventsConfig?.workflow_call) {
|
||||
// Unpredictable secrets may be passed in via a workflow_call trigger
|
||||
secretsContext.complete = false;
|
||||
@@ -38,6 +39,7 @@ export async function getSecrets(
|
||||
}
|
||||
|
||||
let environmentName: string | undefined;
|
||||
|
||||
if (workflowContext?.job?.environment) {
|
||||
if (isString(workflowContext.job.environment)) {
|
||||
environmentName = workflowContext.job.environment.value;
|
||||
@@ -46,10 +48,17 @@ export async function getSecrets(
|
||||
if (isString(x.key) && x.key.value === "name") {
|
||||
if (isString(x.value)) {
|
||||
environmentName = x.value.value;
|
||||
} else {
|
||||
// this means we have a dynamic enviornment, in those situations we
|
||||
// want to make sure we skip doing secret validation
|
||||
secretsContext.complete = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// if the expression is something like environment: ${{ ... }} then we want to skip validation
|
||||
secretsContext.complete = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,10 @@ import {data, DescriptionDictionary} from "@actions/expressions";
|
||||
import {Pair} from "@actions/expressions/data/expressiondata";
|
||||
import {StringData} from "@actions/expressions/data/index";
|
||||
import {WorkflowContext} from "@actions/languageservice/context/workflow-context";
|
||||
import {warn} from "@actions/languageservice/log";
|
||||
import {log, warn} from "@actions/languageservice/log";
|
||||
import {isMapping, isString} from "@actions/workflow-parser";
|
||||
import {Octokit} from "@octokit/rest";
|
||||
import {RequestError} from "@octokit/request-error";
|
||||
|
||||
import {RepositoryContext} from "../initializationOptions";
|
||||
import {TTLCache} from "../utils/cache";
|
||||
@@ -42,50 +43,58 @@ export async function getVariables(
|
||||
}
|
||||
|
||||
const variablesContext = defaultContext || new DescriptionDictionary();
|
||||
const variables = await getRemoteVariables(octokit, cache, repo, environmentName);
|
||||
try {
|
||||
const variables = await getRemoteVariables(octokit, cache, repo, environmentName);
|
||||
|
||||
// Build combined map of variables
|
||||
const variablesMap = new Map<
|
||||
string,
|
||||
{
|
||||
key: string;
|
||||
value: data.StringData;
|
||||
description?: string;
|
||||
}
|
||||
>();
|
||||
// Build combined map of variables
|
||||
const variablesMap = new Map<
|
||||
string,
|
||||
{
|
||||
key: string;
|
||||
value: data.StringData;
|
||||
description?: string;
|
||||
}
|
||||
>();
|
||||
|
||||
variables.organizationVariables.forEach(variable =>
|
||||
variablesMap.set(variable.key.toLowerCase(), {
|
||||
key: variable.key,
|
||||
value: new data.StringData(variable.value.coerceString()),
|
||||
description: `${variable.value.coerceString()} - Organization variable`
|
||||
})
|
||||
);
|
||||
variables.organizationVariables.forEach(variable =>
|
||||
variablesMap.set(variable.key.toLowerCase(), {
|
||||
key: variable.key,
|
||||
value: new data.StringData(variable.value.coerceString()),
|
||||
description: `${variable.value.coerceString()} - Organization variable`
|
||||
})
|
||||
);
|
||||
|
||||
// Override org variables with repo variables
|
||||
variables.repoVariables.forEach(variable =>
|
||||
variablesMap.set(variable.key.toLowerCase(), {
|
||||
key: variable.key,
|
||||
value: new data.StringData(variable.value.coerceString()),
|
||||
description: `${variable.value.coerceString()} - Repository variable`
|
||||
})
|
||||
);
|
||||
// Override org variables with repo variables
|
||||
variables.repoVariables.forEach(variable =>
|
||||
variablesMap.set(variable.key.toLowerCase(), {
|
||||
key: variable.key,
|
||||
value: new data.StringData(variable.value.coerceString()),
|
||||
description: `${variable.value.coerceString()} - Repository variable`
|
||||
})
|
||||
);
|
||||
|
||||
// Override repo variables with environment veriables (if defined)
|
||||
variables.environmentVariables.forEach(variable =>
|
||||
variablesMap.set(variable.key.toLowerCase(), {
|
||||
key: variable.key,
|
||||
value: new data.StringData(variable.value.coerceString()),
|
||||
description: `${variable.value.coerceString()} - Variable for environment \`${environmentName || ""}\``
|
||||
})
|
||||
);
|
||||
// Override repo variables with environment veriables (if defined)
|
||||
variables.environmentVariables.forEach(variable =>
|
||||
variablesMap.set(variable.key.toLowerCase(), {
|
||||
key: variable.key,
|
||||
value: new data.StringData(variable.value.coerceString()),
|
||||
description: `${variable.value.coerceString()} - Variable for environment \`${environmentName || ""}\``
|
||||
})
|
||||
);
|
||||
|
||||
// Sort variables by key and add to context
|
||||
Array.from(variablesMap.values())
|
||||
.sort((a, b) => a.key.localeCompare(b.key))
|
||||
.forEach(variable => variablesContext?.add(variable.key, variable.value, variable.description));
|
||||
// Sort variables by key and add to context
|
||||
Array.from(variablesMap.values())
|
||||
.sort((a, b) => a.key.localeCompare(b.key))
|
||||
.forEach(variable => variablesContext?.add(variable.key, variable.value, variable.description));
|
||||
|
||||
return variablesContext;
|
||||
return variablesContext;
|
||||
} catch (e) {
|
||||
if (!(e instanceof RequestError)) throw e;
|
||||
if (e.name == "HttpError" && e.status == 404) {
|
||||
log("Failure to request variables. Ignore if you're using GitHub Enterprise Server below version 3.8");
|
||||
return variablesContext;
|
||||
} else throw e;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getRemoteVariables(
|
||||
|
||||
@@ -2,8 +2,8 @@ import {File} from "@actions/workflow-parser/workflows/file";
|
||||
import {FileProvider} from "@actions/workflow-parser/workflows/file-provider";
|
||||
import {fileIdentifier} from "@actions/workflow-parser/workflows/file-reference";
|
||||
import {Octokit} from "@octokit/rest";
|
||||
import path from "path";
|
||||
import {TTLCache} from "./utils/cache";
|
||||
import vscodeURI from "vscode-uri/lib/umd";
|
||||
|
||||
export function getFileProvider(
|
||||
client: Octokit | undefined,
|
||||
@@ -31,7 +31,10 @@ export function getFileProvider(
|
||||
throw new Error("Local file references are not supported with this configuration");
|
||||
}
|
||||
|
||||
const file = await readFile(path.join(workspace, ref.path));
|
||||
const workspaceURI = vscodeURI.URI.parse(workspace);
|
||||
const refURI = vscodeURI.Utils.joinPath(workspaceURI, ref.path);
|
||||
const file = await readFile(refURI.toString());
|
||||
|
||||
if (!file) {
|
||||
throw new Error(`File not found: ${ref.path}`);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,11 @@ export interface InitializationOptions {
|
||||
* Desired log level
|
||||
*/
|
||||
logLevel?: LogLevel;
|
||||
|
||||
/**
|
||||
* If a GitHub Enterprise Server should be used, the URL of the API endpoint, eg "https://ghe.my-company.com/api/v3"
|
||||
*/
|
||||
gitHubApiUrl?: string;
|
||||
}
|
||||
|
||||
export interface RepositoryContext {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@actions/languageservice",
|
||||
"version": "0.3.1",
|
||||
"version": "0.3.7",
|
||||
"description": "Language service for GitHub Actions",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
@@ -44,8 +44,8 @@
|
||||
"watch": "tsc --build tsconfig.build.json --watch"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/expressions": "^0.3.1",
|
||||
"@actions/workflow-parser": "^0.3.1",
|
||||
"@actions/expressions": "^0.3.7",
|
||||
"@actions/workflow-parser": "^0.3.7",
|
||||
"vscode-languageserver-textdocument": "^1.0.7",
|
||||
"vscode-languageserver-types": "^3.17.2",
|
||||
"vscode-uri": "^3.0.7",
|
||||
|
||||
@@ -4,8 +4,8 @@ import {complete} from "./complete";
|
||||
import {registerLogger} from "./log";
|
||||
import {getPositionFromCursor} from "./test-utils/cursor-position";
|
||||
import {TestLogger} from "./test-utils/logger";
|
||||
import {ValueProviderConfig, ValueProviderKind} from "./value-providers/config";
|
||||
import {clearCache} from "./utils/workflow-cache";
|
||||
import {ValueProviderConfig, ValueProviderKind} from "./value-providers/config";
|
||||
|
||||
registerLogger(new TestLogger());
|
||||
|
||||
@@ -406,7 +406,7 @@ jobs:
|
||||
expect(result.map(e => e.label)).toContain("runs-on");
|
||||
|
||||
const textEdit = result.filter(e => e.label === "runs-on")[0].textEdit as TextEdit;
|
||||
expect(textEdit.newText).toEqual("runs-on");
|
||||
expect(textEdit.newText).toEqual("runs-on: ");
|
||||
expect(textEdit.range).toEqual({
|
||||
start: {line: 3, character: 4},
|
||||
end: {line: 3, character: 10}
|
||||
@@ -421,7 +421,7 @@ jobs:
|
||||
expect(result.map(e => e.label)).toContain("runs-on");
|
||||
|
||||
const textEdit = result.filter(e => e.label === "runs-on")[0].textEdit as TextEdit;
|
||||
expect(textEdit.newText).toEqual("runs-on");
|
||||
expect(textEdit.newText).toEqual("runs-on: ");
|
||||
expect(textEdit.range).toEqual({
|
||||
start: {line: 3, character: 4},
|
||||
end: {line: 3, character: 4}
|
||||
@@ -448,7 +448,7 @@ jobs:
|
||||
]);
|
||||
|
||||
// One-of
|
||||
expect(result.filter(x => x.label === "concurrency").map(x => x.textEdit?.newText)).toEqual(["concurrency"]);
|
||||
expect(result.filter(x => x.label === "concurrency").map(x => x.textEdit?.newText)).toEqual(["concurrency: "]);
|
||||
});
|
||||
|
||||
it("custom indentation", async () => {
|
||||
@@ -471,7 +471,50 @@ jobs:
|
||||
]);
|
||||
|
||||
// One-of
|
||||
expect(result.filter(x => x.label === "concurrency").map(x => x.textEdit?.newText)).toEqual(["concurrency"]);
|
||||
expect(result.filter(x => x.label === "concurrency").map(x => x.textEdit?.newText)).toEqual(["concurrency: "]);
|
||||
});
|
||||
});
|
||||
|
||||
it("adds a new line and indentation for mapping keys when the key is given", async () => {
|
||||
const input = "concurrency: |";
|
||||
|
||||
const result = await complete(...getPositionFromCursor(input));
|
||||
|
||||
expect(result.filter(x => x.label === "cancel-in-progress").map(x => x.textEdit?.newText)).toEqual([
|
||||
"\n cancel-in-progress: "
|
||||
]);
|
||||
expect(result.filter(x => x.label === "group").map(x => x.textEdit?.newText)).toEqual(["\n group: "]);
|
||||
});
|
||||
|
||||
it("does not add new line if no key in line", async () => {
|
||||
const input = "run-n|";
|
||||
|
||||
const result = await complete(...getPositionFromCursor(input));
|
||||
|
||||
expect(result.filter(x => x.label === "run-name").map(x => x.textEdit?.newText)).toEqual(["run-name: "]);
|
||||
});
|
||||
|
||||
it("adds new line for nested mapping", async () => {
|
||||
const input = "on:\n workflow_dispatch: in|";
|
||||
|
||||
const result = await complete(...getPositionFromCursor(input));
|
||||
|
||||
expect(result.filter(x => x.label === "inputs").map(x => x.textEdit?.newText)).toEqual(["\n inputs:\n "]);
|
||||
});
|
||||
|
||||
it("adds : for one-of", async () => {
|
||||
const input = "on:\n check_run:\n ty|";
|
||||
|
||||
const result = await complete(...getPositionFromCursor(input));
|
||||
|
||||
expect(result.filter(x => x.label === "types").map(x => x.textEdit?.newText)).toEqual(["types: "]);
|
||||
});
|
||||
|
||||
it("does not add : for one-of in key mode", async () => {
|
||||
const input = "on:\n check_run: ty|";
|
||||
|
||||
const result = await complete(...getPositionFromCursor(input));
|
||||
|
||||
expect(result.filter(x => x.label === "types").map(x => x.textEdit?.newText)).toEqual(["types"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -24,7 +24,7 @@ import {isPlaceholder, transform} from "./utils/transform";
|
||||
import {fetchOrConvertWorkflowTemplate, fetchOrParseWorkflow} from "./utils/workflow-cache";
|
||||
import {Value, ValueProviderConfig} from "./value-providers/config";
|
||||
import {defaultValueProviders} from "./value-providers/default";
|
||||
import {definitionValues} from "./value-providers/definition";
|
||||
import {DefinitionValueMode, definitionValues} from "./value-providers/definition";
|
||||
|
||||
export function getExpressionInput(input: string, pos: number): string {
|
||||
// Find start marker around the cursor position
|
||||
@@ -180,7 +180,7 @@ async function getValues(
|
||||
return [];
|
||||
}
|
||||
|
||||
const values = definitionValues(def, indentation);
|
||||
const values = definitionValues(def, indentation, keyToken ? DefinitionValueMode.Key : DefinitionValueMode.Parent);
|
||||
return filterAndSortCompletionOptions(values, existingValues);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import {data, isDescriptionDictionary} from "@actions/expressions";
|
||||
import {isDictionary} from "@actions/expressions/data/dictionary";
|
||||
import {ExpressionData, Pair} from "@actions/expressions/data/expressiondata";
|
||||
|
||||
export class AccessError extends Error {
|
||||
constructor(message: string, public readonly keyName: string) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
export class ErrorDictionary extends data.Dictionary {
|
||||
constructor(...pairs: Pair[]) {
|
||||
super(...pairs);
|
||||
}
|
||||
public complete = true;
|
||||
|
||||
get(key: string): ExpressionData | undefined {
|
||||
const value = super.get(key);
|
||||
if (value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (this.complete) {
|
||||
throw new AccessError(`Invalid context access: ${key}`, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function wrapDictionary(d: data.Dictionary): ErrorDictionary {
|
||||
const e = new ErrorDictionary();
|
||||
if (isDescriptionDictionary(d)) {
|
||||
e.complete = d.complete;
|
||||
}
|
||||
|
||||
for (const {key, value} of d.pairs()) {
|
||||
if (isDictionary(value)) {
|
||||
e.add(key, wrapDictionary(value));
|
||||
} else {
|
||||
e.add(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
return e;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import {Evaluator, ExpressionEvaluationError, data} from "@actions/expressions";
|
||||
import {Expr, Logical} from "@actions/expressions/ast";
|
||||
import {ExpressionData} from "@actions/expressions/data/expressiondata";
|
||||
import {TokenType} from "@actions/expressions/lexer";
|
||||
import {falsy, truthy} from "@actions/expressions/result";
|
||||
import {AccessError} from "./error-dictionary";
|
||||
|
||||
export type ValidationError = {
|
||||
message: string;
|
||||
severity: "error" | "warning";
|
||||
};
|
||||
|
||||
export class ValidationEvaluator extends Evaluator {
|
||||
public readonly errors: ValidationError[] = [];
|
||||
|
||||
public validate() {
|
||||
super.evaluate();
|
||||
}
|
||||
|
||||
protected override eval(n: Expr): ExpressionData {
|
||||
try {
|
||||
return super.eval(n);
|
||||
} catch (e) {
|
||||
// Record error
|
||||
if (e instanceof AccessError) {
|
||||
this.errors.push({
|
||||
message: `Context access might be invalid: ${e.keyName}`,
|
||||
severity: "warning"
|
||||
});
|
||||
} else if (e instanceof ExpressionEvaluationError) {
|
||||
this.errors.push({
|
||||
message: `Expression might be invalid: ${e.message}`,
|
||||
severity: "error"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Return null but continue with the validation
|
||||
return new data.Null();
|
||||
}
|
||||
|
||||
override visitLogical(logical: Logical): ExpressionData {
|
||||
let result: data.ExpressionData | undefined;
|
||||
|
||||
for (const arg of logical.args) {
|
||||
const r = this.eval(arg);
|
||||
|
||||
// Simulate short-circuit behavior but continue to evalute all arguments for validation purposes
|
||||
if (
|
||||
!result &&
|
||||
((logical.operator.type === TokenType.AND && falsy(r)) || (logical.operator.type === TokenType.OR && truthy(r)))
|
||||
) {
|
||||
result = r;
|
||||
}
|
||||
}
|
||||
|
||||
// result is always assigned before we return here
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
return result!;
|
||||
}
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
import {Lexer, Parser} from "@actions/expressions";
|
||||
import {Dictionary} from "@actions/expressions/data/dictionary";
|
||||
import {StringData} from "@actions/expressions/data/string";
|
||||
import {splitAllowedContext} from "@actions/workflow-parser/templates/allowed-context";
|
||||
import {ValidationVisitor} from "./visitor";
|
||||
|
||||
const testContext = new Dictionary({
|
||||
key: "github",
|
||||
value: new Dictionary(
|
||||
{
|
||||
key: "event",
|
||||
value: new StringData("push")
|
||||
},
|
||||
{
|
||||
key: "repo",
|
||||
value: new Dictionary({
|
||||
key: "name",
|
||||
value: new StringData("test")
|
||||
})
|
||||
}
|
||||
)
|
||||
});
|
||||
|
||||
function useVisitor(expression: string, allowedContext: string[]): any[] {
|
||||
const {namedContexts, functions} = splitAllowedContext(allowedContext);
|
||||
|
||||
const l = new Lexer(expression);
|
||||
const lr = l.lex();
|
||||
|
||||
const p = new Parser(lr.tokens, namedContexts, functions);
|
||||
const expr = p.parse();
|
||||
|
||||
const e = new ValidationVisitor(expr, testContext);
|
||||
e.validate();
|
||||
|
||||
return e.errors;
|
||||
}
|
||||
|
||||
describe("validation visitor", () => {
|
||||
it("invalid context access", () => {
|
||||
expect(useVisitor("github.foo", ["github"])).toEqual([
|
||||
{
|
||||
message: "Context access might be invalid: foo",
|
||||
range: {
|
||||
end: {
|
||||
column: 10,
|
||||
line: 0
|
||||
},
|
||||
start: {
|
||||
column: 0,
|
||||
line: 0
|
||||
}
|
||||
},
|
||||
severity: "warning"
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it("invalid context access as index", () => {
|
||||
expect(useVisitor("github[github.foo]", ["github"])).toEqual([
|
||||
{
|
||||
message: "Context access might be invalid: foo",
|
||||
range: {
|
||||
end: {
|
||||
column: 17,
|
||||
line: 0
|
||||
},
|
||||
start: {
|
||||
column: 7,
|
||||
line: 0
|
||||
}
|
||||
},
|
||||
severity: "warning"
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it("invalid nested context access", () => {
|
||||
expect(useVisitor("github.repo.name", ["github"])).toEqual([
|
||||
{
|
||||
message: "Context access might be invalid: name",
|
||||
range: {
|
||||
end: {
|
||||
column: 16,
|
||||
line: 0
|
||||
},
|
||||
start: {
|
||||
column: 0,
|
||||
line: 0
|
||||
}
|
||||
},
|
||||
severity: "warning"
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it("invalid context accesses", () => {
|
||||
expect(useVisitor("github.foo || github.foo.bar", ["github"])).toEqual([
|
||||
{
|
||||
message: "Context access might be invalid: foo",
|
||||
range: {
|
||||
end: {
|
||||
column: 10,
|
||||
line: 0
|
||||
},
|
||||
start: {
|
||||
column: 0,
|
||||
line: 0
|
||||
}
|
||||
},
|
||||
severity: "warning"
|
||||
},
|
||||
{
|
||||
message: "Context access might be invalid: bar",
|
||||
range: {
|
||||
end: {
|
||||
column: 28,
|
||||
line: 0
|
||||
},
|
||||
start: {
|
||||
column: 14,
|
||||
line: 0
|
||||
}
|
||||
},
|
||||
severity: "warning"
|
||||
}
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -1,148 +0,0 @@
|
||||
import {DescriptionDictionary} from "@actions/expressions";
|
||||
import {
|
||||
Binary,
|
||||
ContextAccess,
|
||||
Expr,
|
||||
ExprVisitor,
|
||||
FunctionCall,
|
||||
Grouping,
|
||||
IndexAccess,
|
||||
Literal,
|
||||
Logical,
|
||||
Unary
|
||||
} from "@actions/expressions/ast";
|
||||
import {Dictionary} from "@actions/expressions/data/dictionary";
|
||||
import {ExpressionData} from "@actions/expressions/data/expressiondata";
|
||||
import {Range} from "@actions/expressions/lexer";
|
||||
|
||||
export type ValidationError = {
|
||||
range: Range;
|
||||
message: string;
|
||||
severity: "error" | "warning";
|
||||
};
|
||||
|
||||
export class ValidationVisitor implements ExprVisitor<void> {
|
||||
public readonly errors: ValidationError[] = [];
|
||||
|
||||
constructor(private expr: Expr, private context: Dictionary) {}
|
||||
|
||||
validate(): void {
|
||||
this._validate(this.expr);
|
||||
}
|
||||
|
||||
private _validate(expr: Expr) {
|
||||
expr.accept(this);
|
||||
}
|
||||
|
||||
visitLiteral() {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
visitUnary(unary: Unary) {
|
||||
this._validate(unary.expr);
|
||||
}
|
||||
|
||||
visitBinary(binary: Binary) {
|
||||
this._validate(binary.left);
|
||||
this._validate(binary.right);
|
||||
}
|
||||
|
||||
visitLogical(logical: Logical) {
|
||||
for (const arg of logical.args) {
|
||||
this._validate(arg);
|
||||
}
|
||||
}
|
||||
|
||||
visitGrouping(grouping: Grouping) {
|
||||
this._validate(grouping.group);
|
||||
}
|
||||
|
||||
visitContextAccess(contextAccess: ContextAccess) {
|
||||
const contextName = contextAccess.name.lexeme;
|
||||
if (this.context.get(contextName) === undefined) {
|
||||
this.errors.push({
|
||||
message: `Context access might be invalid: ${contextName}`,
|
||||
range: contextAccess.name.range,
|
||||
severity: "error"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
visitIndexAccess(indexAccess: IndexAccess) {
|
||||
let contextAccess: ContextAccess | undefined;
|
||||
|
||||
const s: ExpressionData[] = [];
|
||||
let i: Expr = indexAccess;
|
||||
while (i) {
|
||||
if (i instanceof IndexAccess) {
|
||||
if (!(i.index instanceof Literal)) {
|
||||
// Not a literal, validate independently
|
||||
this._validate(i.index);
|
||||
return;
|
||||
}
|
||||
s.push(i.index.literal);
|
||||
i = i.expr;
|
||||
}
|
||||
|
||||
if (i instanceof ContextAccess) {
|
||||
contextAccess = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!contextAccess) {
|
||||
// Context not found, should not happen, ignore in this case
|
||||
return;
|
||||
}
|
||||
|
||||
const contextName = contextAccess.name.lexeme;
|
||||
let contextValue = this.context.get(contextName);
|
||||
if (contextValue === undefined || !(contextValue instanceof Dictionary)) {
|
||||
const contextName = contextAccess.name.lexeme;
|
||||
if (this.context.get(contextName) === undefined) {
|
||||
this.errors.push({
|
||||
message: `Context access might be invalid: ${contextName}`,
|
||||
range: contextAccess.name.range,
|
||||
severity: "warning"
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
while (s.length > 0) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
const idx = s.pop()!;
|
||||
|
||||
const key = idx.coerceString();
|
||||
const v: ExpressionData | undefined = contextValue.get(key);
|
||||
if (v === undefined) {
|
||||
if (contextValue instanceof DescriptionDictionary && !contextValue.complete) {
|
||||
// If the context dictionary is not complete, we cannot validate the expression
|
||||
return;
|
||||
}
|
||||
|
||||
this.errors.push({
|
||||
range: {
|
||||
start: contextAccess.name.range.start,
|
||||
end: (indexAccess.index as Literal).token.range.end
|
||||
},
|
||||
message: `Context access might be invalid: ${key}`,
|
||||
severity: "warning"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(v instanceof Dictionary)) {
|
||||
return;
|
||||
}
|
||||
|
||||
contextValue = v;
|
||||
}
|
||||
}
|
||||
|
||||
visitFunctionCall(functionCall: FunctionCall) {
|
||||
for (const arg of functionCall.args) {
|
||||
this._validate(arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import {DescriptionDictionary} from "@actions/expressions";
|
||||
import {DescriptionDictionary} from "@actions/expressions/.";
|
||||
import {DiagnosticSeverity} from "vscode-languageserver-types";
|
||||
import {ContextProviderConfig} from "./context-providers/config";
|
||||
import {registerLogger} from "./log";
|
||||
@@ -46,6 +46,52 @@ jobs:
|
||||
]);
|
||||
});
|
||||
|
||||
it("access invalid context field in short-circuited expression", async () => {
|
||||
const result = await validate(
|
||||
createDocument(
|
||||
"wf.yaml",
|
||||
`on: push
|
||||
run-name: name-\${{ github.does-not-exist || github.does-not-exist2 }}
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: echo`
|
||||
)
|
||||
);
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
message: "Context access might be invalid: does-not-exist",
|
||||
range: {
|
||||
end: {
|
||||
character: 69,
|
||||
line: 1
|
||||
},
|
||||
start: {
|
||||
character: 15,
|
||||
line: 1
|
||||
}
|
||||
},
|
||||
severity: DiagnosticSeverity.Warning
|
||||
},
|
||||
{
|
||||
message: "Context access might be invalid: does-not-exist2",
|
||||
range: {
|
||||
end: {
|
||||
character: 69,
|
||||
line: 1
|
||||
},
|
||||
start: {
|
||||
character: 15,
|
||||
line: 1
|
||||
}
|
||||
},
|
||||
severity: DiagnosticSeverity.Warning
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it("partial skip access invalid context on incomplete", async () => {
|
||||
const contextProviderConfig: ContextProviderConfig = {
|
||||
getContext: (context: string) => {
|
||||
|
||||
@@ -15,7 +15,9 @@ import {ActionMetadata, ActionReference} from "./action";
|
||||
import {ContextProviderConfig} from "./context-providers/config";
|
||||
import {Mode, getContext} from "./context-providers/default";
|
||||
import {WorkflowContext, getWorkflowContext} from "./context/workflow-context";
|
||||
import {ValidationVisitor} from "./expression-validation/visitor";
|
||||
import {wrapDictionary} from "./expression-validation/error-dictionary";
|
||||
import {ValidationEvaluator} from "./expression-validation/evaluator";
|
||||
import {validatorFunctions} from "./expression-validation/functions";
|
||||
import {error} from "./log";
|
||||
import {findToken} from "./utils/find-token";
|
||||
import {mapRange} from "./utils/range";
|
||||
@@ -203,7 +205,7 @@ async function validateExpression(
|
||||
|
||||
const context = await getContext(namedContexts, contextProviderConfig, workflowContext, Mode.Validation);
|
||||
|
||||
const e = new ValidationVisitor(expr, context);
|
||||
const e = new ValidationEvaluator(expr, wrapDictionary(context), validatorFunctions);
|
||||
e.validate();
|
||||
|
||||
diagnostics.push(
|
||||
|
||||
@@ -9,15 +9,30 @@ import {getWorkflowSchema} from "@actions/workflow-parser/workflows/workflow-sch
|
||||
import {Value} from "./config";
|
||||
import {stringsToValues} from "./strings-to-values";
|
||||
|
||||
export function definitionValues(def: Definition, indentation: string): Value[] {
|
||||
export enum DefinitionValueMode {
|
||||
/**
|
||||
* We're getting completion options for a parent token
|
||||
* foo:
|
||||
* ba|
|
||||
*/
|
||||
Parent,
|
||||
|
||||
/**
|
||||
* We're getting completion options for a key token. For example:
|
||||
* foo: |
|
||||
*/
|
||||
Key
|
||||
}
|
||||
|
||||
export function definitionValues(def: Definition, indentation: string, mode: DefinitionValueMode): Value[] {
|
||||
const schema = getWorkflowSchema();
|
||||
|
||||
if (def instanceof MappingDefinition) {
|
||||
return mappingValues(def, schema.definitions, indentation);
|
||||
return mappingValues(def, schema.definitions, indentation, mode);
|
||||
}
|
||||
|
||||
if (def instanceof OneOfDefinition) {
|
||||
return oneOfValues(def, schema.definitions, indentation);
|
||||
return oneOfValues(def, schema.definitions, indentation, mode);
|
||||
}
|
||||
|
||||
if (def instanceof BooleanDefinition) {
|
||||
@@ -36,7 +51,7 @@ export function definitionValues(def: Definition, indentation: string): Value[]
|
||||
if (def instanceof SequenceDefinition) {
|
||||
const itemDef = schema.getDefinition(def.itemType);
|
||||
if (itemDef) {
|
||||
return definitionValues(itemDef, indentation);
|
||||
return definitionValues(itemDef, indentation, mode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +61,8 @@ export function definitionValues(def: Definition, indentation: string): Value[]
|
||||
function mappingValues(
|
||||
mappingDefinition: MappingDefinition,
|
||||
definitions: {[key: string]: Definition},
|
||||
indentation: string
|
||||
indentation: string,
|
||||
mode: DefinitionValueMode
|
||||
): Value[] {
|
||||
const properties: Value[] = [];
|
||||
for (const [key, value] of Object.entries(mappingDefinition.properties)) {
|
||||
@@ -60,15 +76,36 @@ function mappingValues(
|
||||
if (typeDef) {
|
||||
switch (typeDef.definitionType) {
|
||||
case DefinitionType.Sequence:
|
||||
insertText = `${key}:\n${indentation}- `;
|
||||
if (mode == DefinitionValueMode.Key) {
|
||||
insertText = `\n${indentation}${key}:\n${indentation}${indentation}- `;
|
||||
} else {
|
||||
insertText = `${key}:\n${indentation}- `;
|
||||
}
|
||||
break;
|
||||
|
||||
case DefinitionType.Mapping:
|
||||
insertText = `${key}:\n${indentation}`;
|
||||
if (mode == DefinitionValueMode.Key) {
|
||||
insertText = `\n${indentation}${key}:\n${indentation}${indentation}`;
|
||||
} else {
|
||||
insertText = `${key}:\n${indentation}`;
|
||||
}
|
||||
break;
|
||||
|
||||
case DefinitionType.OneOf:
|
||||
// No special insertText in this case
|
||||
if (mode == DefinitionValueMode.Parent) {
|
||||
insertText = `${key}: `;
|
||||
} else {
|
||||
// No special insertText in this case
|
||||
}
|
||||
break;
|
||||
|
||||
case DefinitionType.String:
|
||||
case DefinitionType.Boolean:
|
||||
if (mode == DefinitionValueMode.Key) {
|
||||
insertText = `\n${indentation}${key}: `;
|
||||
} else {
|
||||
insertText = `${key}: `;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -89,11 +126,12 @@ function mappingValues(
|
||||
function oneOfValues(
|
||||
oneOfDefinition: OneOfDefinition,
|
||||
definitions: {[key: string]: Definition},
|
||||
indentation: string
|
||||
indentation: string,
|
||||
mode: DefinitionValueMode
|
||||
): Value[] {
|
||||
const values: Value[] = [];
|
||||
for (const key of oneOfDefinition.oneOf) {
|
||||
values.push(...definitionValues(definitions[key], indentation));
|
||||
values.push(...definitionValues(definitions[key], indentation, mode));
|
||||
}
|
||||
return distinctValues(values);
|
||||
}
|
||||
|
||||
+7
-2
@@ -1,5 +1,10 @@
|
||||
{
|
||||
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
|
||||
"useWorkspaces": true,
|
||||
"version": "0.3.1"
|
||||
"packages": [
|
||||
"expressions",
|
||||
"workflow-parser",
|
||||
"languageservice",
|
||||
"languageserver"
|
||||
],
|
||||
"version": "0.3.7"
|
||||
}
|
||||
|
||||
Generated
+16
-14
@@ -135,7 +135,7 @@
|
||||
},
|
||||
"expressions": {
|
||||
"name": "@actions/expressions",
|
||||
"version": "0.3.1",
|
||||
"version": "0.3.7",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.0.3",
|
||||
@@ -395,11 +395,11 @@
|
||||
},
|
||||
"languageserver": {
|
||||
"name": "@actions/languageserver",
|
||||
"version": "0.3.1",
|
||||
"version": "0.3.7",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/languageservice": "^0.3.1",
|
||||
"@actions/workflow-parser": "^0.3.1",
|
||||
"@actions/languageservice": "^0.3.7",
|
||||
"@actions/workflow-parser": "^0.3.7",
|
||||
"@octokit/rest": "^19.0.7",
|
||||
"@octokit/types": "^9.0.0",
|
||||
"vscode-languageserver": "^8.0.2",
|
||||
@@ -678,11 +678,11 @@
|
||||
},
|
||||
"languageservice": {
|
||||
"name": "@actions/languageservice",
|
||||
"version": "0.3.1",
|
||||
"version": "0.3.7",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/expressions": "^0.3.1",
|
||||
"@actions/workflow-parser": "^0.3.1",
|
||||
"@actions/expressions": "^0.3.7",
|
||||
"@actions/workflow-parser": "^0.3.7",
|
||||
"vscode-languageserver-textdocument": "^1.0.7",
|
||||
"vscode-languageserver-types": "^3.17.2",
|
||||
"vscode-uri": "^3.0.7",
|
||||
@@ -6652,9 +6652,10 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/http-cache-semantics": {
|
||||
"version": "4.1.0",
|
||||
"dev": true,
|
||||
"license": "BSD-2-Clause"
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz",
|
||||
"integrity": "sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/http-proxy-agent": {
|
||||
"version": "5.0.0",
|
||||
@@ -11667,8 +11668,9 @@
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/yaml": {
|
||||
"version": "2.1.3",
|
||||
"license": "ISC",
|
||||
"version": "2.2.2",
|
||||
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.2.2.tgz",
|
||||
"integrity": "sha512-CBKFWExMn46Foo4cldiChEzn7S7SRV+wqiluAb6xmueD/fGyRHIhX8m14vVGgeFWjN540nKCNVj6P21eQjgTuA==",
|
||||
"engines": {
|
||||
"node": ">= 14"
|
||||
}
|
||||
@@ -11719,10 +11721,10 @@
|
||||
},
|
||||
"workflow-parser": {
|
||||
"name": "@actions/workflow-parser",
|
||||
"version": "0.3.1",
|
||||
"version": "0.3.7",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/expressions": "^0.3.1",
|
||||
"@actions/expressions": "^0.3.7",
|
||||
"cronstrue": "^2.21.0",
|
||||
"yaml": "^2.0.0-8"
|
||||
},
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Release 0.3.5
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
# this script is used to generate release notes for a given release
|
||||
# first argument is the pull request id for the last release
|
||||
# the second is the new release number
|
||||
|
||||
# the script then grabs every pull request merged since that pull request
|
||||
# and outputs a string of release notes
|
||||
|
||||
# get the new release number
|
||||
NEW_RELEASE=$2
|
||||
|
||||
echo "Generating release notes for $NEW_RELEASE"
|
||||
|
||||
# get the last release pull request id
|
||||
LAST_RELEASE_PR=$1
|
||||
|
||||
|
||||
|
||||
#get when the last release was merged
|
||||
LAST_RELEASE_MERGED_AT=$(gh pr view $LAST_RELEASE_PR --repo actions/languageservices --json mergedAt | jq -r '.mergedAt')
|
||||
|
||||
CHANGELIST=$(gh pr list --repo actions/languageservices --base main --state merged --json title --search "merged:>$LAST_RELEASE_MERGED_AT -label:no-release")
|
||||
|
||||
# store the release notes in a variable so we can use it later
|
||||
|
||||
echo "Release $NEW_RELEASE" >> releasenotes.md
|
||||
|
||||
echo $CHANGELIST | jq -r '.[].title' | while read line; do
|
||||
echo " - $line" >> releasenotes.md
|
||||
done
|
||||
|
||||
echo " "
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
VERSION=$(cat lerna.json | jq -r '.version')
|
||||
|
||||
MAJOR=$(echo $VERSION | cut -d. -f1)
|
||||
MINOR=$(echo $VERSION | cut -d. -f2)
|
||||
PATCH=$(echo $VERSION | cut -d. -f3)
|
||||
|
||||
if [ "$1" == "major" ]; then
|
||||
MAJOR=$((MAJOR+1))
|
||||
MINOR=0
|
||||
PATCH=0
|
||||
elif [ "$1" == "minor" ]; then
|
||||
MINOR=$((MINOR+1))
|
||||
PATCH=0
|
||||
elif [ "$1" == "patch" ]; then
|
||||
PATCH=$((PATCH+1))
|
||||
else
|
||||
echo "Invalid version type. Use 'major', 'minor' or 'patch'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
|
||||
echo $NEW_VERSION
|
||||
@@ -35,7 +35,7 @@ jobs:
|
||||
);
|
||||
```
|
||||
|
||||
`convertWorkflowTemplate` then takes that intermediate representation and converts it to a [`WorkflowTemplate`](./src/workflow-template.ts) object, which is a more convenient representation for working with workflows.
|
||||
`convertWorkflowTemplate` then takes that intermediate representation and converts it to a [`WorkflowTemplate`](./src/model/workflow-template.ts) object, which is a more convenient representation for working with workflows.
|
||||
|
||||
```typescript
|
||||
const workflowTemplate = await convertWorkflowTemplate(result.context, result.value);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@actions/workflow-parser",
|
||||
"version": "0.3.1",
|
||||
"version": "0.3.7",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"source": "./src/index.ts",
|
||||
@@ -43,7 +43,7 @@
|
||||
"watch": "tsc --build tsconfig.build.json --watch"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/expressions": "^0.3.1",
|
||||
"@actions/expressions": "^0.3.7",
|
||||
"cronstrue": "^2.21.0",
|
||||
"yaml": "^2.0.0-8"
|
||||
},
|
||||
|
||||
@@ -59,17 +59,24 @@ export function convertOn(context: TemplateContext, token: TemplateToken): Event
|
||||
|
||||
// All other events are defined as mappings. During schema validation we already ensure that events
|
||||
// receive only known keys, so here we can focus on the values and whether they are valid.
|
||||
|
||||
const eventToken = item.value.assertMapping(`event ${eventName}`);
|
||||
if (eventName === "workflow_call") {
|
||||
result.workflow_call = convertEventWorkflowCall(context, eventToken);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (eventName === "workflow_dispatch") {
|
||||
result.workflow_dispatch = convertEventWorkflowDispatchInputs(context, eventToken);
|
||||
continue;
|
||||
}
|
||||
|
||||
result[eventName] = {
|
||||
...convertPatternFilter("branches", eventToken),
|
||||
...convertPatternFilter("tags", eventToken),
|
||||
...convertPatternFilter("paths", eventToken),
|
||||
...convertFilter("types", eventToken),
|
||||
...convertFilter("workflows", eventToken),
|
||||
// workflow_call and workflow_dispatch share input parsing
|
||||
...convertEventWorkflowDispatchInputs(context, eventToken),
|
||||
...convertEventWorkflowCall(context, eventToken)
|
||||
...convertFilter("workflows", eventToken)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ function convertStep(context: TemplateContext, idBuilder: IdBuilder, step: Templ
|
||||
let id: StringToken | undefined;
|
||||
let name: ScalarToken | undefined;
|
||||
let uses: StringToken | undefined;
|
||||
let continueOnError: boolean | undefined;
|
||||
let continueOnError: boolean | ScalarToken | undefined;
|
||||
let env: MappingToken | undefined;
|
||||
const ifCondition = new BasicExpressionToken(undefined, undefined, "success()", undefined, undefined, undefined);
|
||||
for (const item of mapping) {
|
||||
@@ -78,7 +78,11 @@ function convertStep(context: TemplateContext, idBuilder: IdBuilder, step: Templ
|
||||
env = item.value.assertMapping("step env");
|
||||
break;
|
||||
case "continue-on-error":
|
||||
continueOnError = item.value.assertBoolean("steps item continue-on-error").value;
|
||||
if (!item.value.isExpression) {
|
||||
continueOnError = item.value.assertBoolean("steps item continue-on-error").value;
|
||||
} else {
|
||||
continueOnError = item.value.assertScalar("steps item continue-on-error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import {TemplateContext} from "../../templates/template-context";
|
||||
import {MappingToken, TemplateToken} from "../../templates/tokens";
|
||||
import {isMapping} from "../../templates/tokens/type-guards";
|
||||
import {SecretConfig, WorkflowCallConfig} from "../workflow-template";
|
||||
import {SecretConfig, WorkflowCallConfig, InputConfig, InputType} from "../workflow-template";
|
||||
import {convertStringList} from "./string-list";
|
||||
import {ScalarToken} from "../../templates/tokens/scalar-token";
|
||||
|
||||
export function convertEventWorkflowCall(context: TemplateContext, token: MappingToken): WorkflowCallConfig {
|
||||
const result: WorkflowCallConfig = {};
|
||||
@@ -11,7 +13,7 @@ export function convertEventWorkflowCall(context: TemplateContext, token: Mappin
|
||||
|
||||
switch (key.value) {
|
||||
case "inputs":
|
||||
// Ignore, these are handled by convertEventWorkflowDispatchInputs
|
||||
result.inputs = convertWorkflowInputs(context, item.value.assertMapping("workflow dispatch inputs"));
|
||||
break;
|
||||
|
||||
case "secrets":
|
||||
@@ -27,6 +29,94 @@ export function convertEventWorkflowCall(context: TemplateContext, token: Mappin
|
||||
return result;
|
||||
}
|
||||
|
||||
export function convertWorkflowInputs(
|
||||
context: TemplateContext,
|
||||
token: MappingToken
|
||||
): {
|
||||
[inputName: string]: InputConfig;
|
||||
} {
|
||||
const result: {[inputName: string]: InputConfig} = {};
|
||||
|
||||
for (const item of token) {
|
||||
const inputName = item.key.assertString("input name");
|
||||
const inputMapping = item.value.assertMapping("input configuration");
|
||||
|
||||
result[inputName.value] = convertWorkflowInput(context, inputMapping);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export function convertWorkflowInput(context: TemplateContext, token: MappingToken): InputConfig {
|
||||
const result: InputConfig = {
|
||||
type: InputType.string // Default to string
|
||||
};
|
||||
|
||||
let defaultValue: undefined | ScalarToken;
|
||||
|
||||
for (const item of token) {
|
||||
const key = item.key.assertString("workflow dispatch input key");
|
||||
|
||||
switch (key.value) {
|
||||
case "description":
|
||||
result.description = item.value.assertString("input description").value;
|
||||
break;
|
||||
|
||||
case "required":
|
||||
result.required = item.value.assertBoolean("input required").value;
|
||||
break;
|
||||
|
||||
case "default":
|
||||
defaultValue = item.value.assertScalar("input default");
|
||||
break;
|
||||
|
||||
case "type":
|
||||
result.type = InputType[item.value.assertString("input type").value as keyof typeof InputType];
|
||||
break;
|
||||
|
||||
case "options":
|
||||
result.options = convertStringList("input options", item.value.assertSequence("input options"));
|
||||
break;
|
||||
|
||||
default:
|
||||
context.error(item.key, `Invalid key '${key.value}'`);
|
||||
}
|
||||
}
|
||||
|
||||
// Validate default value
|
||||
if (defaultValue !== undefined && !defaultValue.isExpression) {
|
||||
try {
|
||||
switch (result.type) {
|
||||
case InputType.boolean:
|
||||
result.default = defaultValue.assertBoolean("input default").value;
|
||||
|
||||
break;
|
||||
|
||||
case InputType.string:
|
||||
case InputType.choice:
|
||||
case InputType.environment:
|
||||
result.default = defaultValue.assertString("input default").value;
|
||||
break;
|
||||
}
|
||||
} catch (e) {
|
||||
context.error(defaultValue, e);
|
||||
}
|
||||
}
|
||||
|
||||
// Validate `options` for `choice` type
|
||||
if (result.type === InputType.choice) {
|
||||
if (result.options === undefined || result.options.length === 0) {
|
||||
context.error(token, "Missing 'options' for choice input");
|
||||
}
|
||||
} else {
|
||||
if (result.options !== undefined) {
|
||||
context.error(token, "Input type is not 'choice', but 'options' is defined");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function convertWorkflowCallSecrets(
|
||||
context: TemplateContext,
|
||||
token: MappingToken
|
||||
|
||||
@@ -86,7 +86,7 @@ type BaseStep = {
|
||||
id: string;
|
||||
name?: ScalarToken;
|
||||
if: BasicExpressionToken;
|
||||
"continue-on-error"?: boolean;
|
||||
"continue-on-error"?: boolean | ScalarToken;
|
||||
env?: MappingToken;
|
||||
};
|
||||
|
||||
@@ -158,7 +158,7 @@ export type WorkflowDispatchConfig = {
|
||||
};
|
||||
|
||||
export type WorkflowCallConfig = {
|
||||
inputs?: {[inputName: string]: InputConfig};
|
||||
inputs?: {[inputName: string]: InputConfig & {default?: string | boolean | number | ScalarToken}};
|
||||
secrets?: {[secretName: string]: SecretConfig};
|
||||
// TODO - these are supported in C# and Go but not in TS yet
|
||||
// outputs: { [outputName: string]: OutputConfig }
|
||||
|
||||
@@ -576,7 +576,9 @@
|
||||
"merge-group-mapping": {
|
||||
"mapping": {
|
||||
"properties": {
|
||||
"types": "merge-group-activity"
|
||||
"types": "merge-group-activity",
|
||||
"branches": "event-branches",
|
||||
"branches-ignore": "event-branches-ignore"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -1181,7 +1183,7 @@
|
||||
]
|
||||
},
|
||||
"workflow-run-activity": {
|
||||
"description": "The types of workflow run activity that trigger the workflow. Suupported activity types: `completed`, `requested`, `in_progress`.",
|
||||
"description": "The types of workflow run activity that trigger the workflow. Supported activity types: `completed`, `requested`, `in_progress`.",
|
||||
"one-of": [
|
||||
"workflow-run-activity-type",
|
||||
"workflow-run-activity-types"
|
||||
@@ -2487,7 +2489,7 @@
|
||||
"string": {
|
||||
"require-non-empty": true
|
||||
},
|
||||
"description": "Use `shell` to override the default shell settings in the runner's operating system. You can use built-in shell keywords, or you can define a custom set of shell options. The shell command that is run internally executes a temporary file that contains the comands specified in `run`."
|
||||
"description": "Use `shell` to override the default shell settings in the runner's operating system. You can use built-in shell keywords, or you can define a custom set of shell options. The shell command that is run internally executes a temporary file that contains the commands specified in `run`."
|
||||
},
|
||||
"working-directory": {
|
||||
"string": {
|
||||
|
||||
+14
-1
@@ -72,7 +72,13 @@ on:
|
||||
- edited
|
||||
- deleted
|
||||
merge_group:
|
||||
types: checks_requested
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
branches-ignore:
|
||||
- develop
|
||||
types:
|
||||
- checks_requested
|
||||
milestone:
|
||||
types:
|
||||
- created
|
||||
@@ -313,6 +319,13 @@ jobs:
|
||||
]
|
||||
},
|
||||
"merge_group": {
|
||||
"branches": [
|
||||
"master",
|
||||
"main"
|
||||
],
|
||||
"branches-ignore": [
|
||||
"develop"
|
||||
],
|
||||
"types": [
|
||||
"checks_requested"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user