Merge branch 'main' into cschleiden/events-without-default-types

This commit is contained in:
Christopher Schleiden
2023-03-17 09:09:01 -07:00
committed by GitHub
10 changed files with 145 additions and 51 deletions
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "browser-playground", "name": "browser-playground",
"version": "0.1.173", "version": "0.1.174",
"description": "", "description": "",
"private": true, "private": true,
"main": "index.js", "main": "index.js",
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"@github/actions-languageserver": "^0.1.173", "@github/actions-languageserver": "^0.1.174",
"monaco-editor-webpack-plugin": "^7.0.1", "monaco-editor-webpack-plugin": "^7.0.1",
"monaco-editor-workers": "^0.34.2", "monaco-editor-workers": "^0.34.2",
"monaco-languageclient": "^4.0.3", "monaco-languageclient": "^4.0.3",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@github/actions-expressions", "name": "@github/actions-expressions",
"version": "0.1.173", "version": "0.1.174",
"license": "MIT", "license": "MIT",
"type": "module", "type": "module",
"source": "./src/index.ts", "source": "./src/index.ts",
+3 -3
View File
@@ -1,6 +1,6 @@
{ {
"name": "@github/actions-languageserver", "name": "@github/actions-languageserver",
"version": "0.1.173", "version": "0.1.174",
"description": "Language server for GitHub Actions", "description": "Language server for GitHub Actions",
"license": "MIT", "license": "MIT",
"type": "module", "type": "module",
@@ -40,8 +40,8 @@
"watch": "tsc --build tsconfig.build.json --watch" "watch": "tsc --build tsconfig.build.json --watch"
}, },
"dependencies": { "dependencies": {
"@github/actions-languageservice": "^0.1.173", "@github/actions-languageservice": "^0.1.174",
"@github/actions-workflow-parser": "^0.1.173", "@github/actions-workflow-parser": "^0.1.174",
"@octokit/rest": "^19.0.7", "@octokit/rest": "^19.0.7",
"@octokit/types": "^9.0.0", "@octokit/types": "^9.0.0",
"vscode-languageserver": "^8.0.2", "vscode-languageserver": "^8.0.2",
+3 -2
View File
@@ -1,5 +1,6 @@
import {documentLinks, hover, validate, ValidationConfig} from "@github/actions-languageservice"; import {documentLinks, hover, validate, ValidationConfig} from "@github/actions-languageservice";
import {registerLogger, setLogLevel} from "@github/actions-languageservice/log"; import {registerLogger, setLogLevel} from "@github/actions-languageservice/log";
import {clearCache, clearCacheEntry} from "@github/actions-languageservice/utils/workflow-cache";
import {Octokit} from "@octokit/rest"; import {Octokit} from "@octokit/rest";
import { import {
CompletionItem, CompletionItem,
@@ -28,7 +29,6 @@ import {fetchActionMetadata} from "./utils/action-metadata";
import {TTLCache} from "./utils/cache"; import {TTLCache} from "./utils/cache";
import {timeOperation} from "./utils/timer"; import {timeOperation} from "./utils/timer";
import {valueProviders} from "./value-providers"; import {valueProviders} from "./value-providers";
import {clearCacheEntry, clearCache} from "@github/actions-languageservice/utils/workflow-cache";
export function initConnection(connection: Connection) { export function initConnection(connection: Connection) {
const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument); const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);
@@ -165,7 +165,8 @@ export function initConnection(connection: Connection) {
}); });
connection.onDocumentLinks(async ({textDocument}: DocumentLinkParams): Promise<DocumentLink[] | null> => { connection.onDocumentLinks(async ({textDocument}: DocumentLinkParams): Promise<DocumentLink[] | null> => {
return documentLinks(documents.get(textDocument.uri)!); const repoContext = repos.find(repo => textDocument.uri.startsWith(repo.workspaceUri));
return documentLinks(documents.get(textDocument.uri)!, repoContext?.workspaceUri);
}); });
// Make the text document manager listen on the connection // Make the text document manager listen on the connection
+4 -3
View File
@@ -1,6 +1,6 @@
{ {
"name": "@github/actions-languageservice", "name": "@github/actions-languageservice",
"version": "0.1.173", "version": "0.1.174",
"description": "Language service for GitHub Actions", "description": "Language service for GitHub Actions",
"license": "MIT", "license": "MIT",
"type": "module", "type": "module",
@@ -41,10 +41,11 @@
"watch": "tsc --build tsconfig.build.json --watch" "watch": "tsc --build tsconfig.build.json --watch"
}, },
"dependencies": { "dependencies": {
"@github/actions-expressions": "^0.1.173", "@github/actions-expressions": "^0.1.174",
"@github/actions-workflow-parser": "^0.1.173", "@github/actions-workflow-parser": "^0.1.174",
"vscode-languageserver-textdocument": "^1.0.7", "vscode-languageserver-textdocument": "^1.0.7",
"vscode-languageserver-types": "^3.17.2", "vscode-languageserver-types": "^3.17.2",
"vscode-uri": "^3.0.7",
"yaml": "^2.1.1" "yaml": "^2.1.1"
}, },
"engines": { "engines": {
+50 -3
View File
@@ -14,7 +14,7 @@ jobs:
runs-on: [self-hosted] runs-on: [self-hosted]
steps: steps:
- run: echo "Hello World"`; - run: echo "Hello World"`;
const result = await documentLinks(createDocument("test.yaml", input)); const result = await documentLinks(createDocument("test.yaml", input), undefined);
expect(result).toHaveLength(0); expect(result).toHaveLength(0);
}); });
@@ -23,7 +23,7 @@ jobs:
jobs: jobs:
build: build:
runs-on: [self-hosted]`; runs-on: [self-hosted]`;
const result = await documentLinks(createDocument("test.yaml", input)); const result = await documentLinks(createDocument("test.yaml", input), undefined);
expect(result).toHaveLength(0); expect(result).toHaveLength(0);
}); });
@@ -36,7 +36,7 @@ jobs:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: github/codeql-action/init@v2`; - uses: github/codeql-action/init@v2`;
const result = await documentLinks(createDocument("test.yaml", input)); const result = await documentLinks(createDocument("test.yaml", input), undefined);
expect(result).toEqual([ expect(result).toEqual([
{ {
range: { range: {
@@ -82,4 +82,51 @@ jobs:
} }
]); ]);
}); });
it("links for reusable local workflow", async () => {
const input = `on: push
jobs:
build:
uses: ./.github/workflows/reusable-workflow.yml`;
const result = await documentLinks(createDocument("test.yaml", input), "file:///workspace/");
expect(result).toEqual([
{
range: {
end: {
character: 51,
line: 3
},
start: {
character: 10,
line: 3
}
},
target: "file:///workspace/.github/workflows/reusable-workflow.yml"
}
]);
});
it("links for reusable remote workflow", async () => {
const input = `on: push
jobs:
build:
uses: seismis-rainier/workflows/reusable-workflow.yml@main`;
const result = await documentLinks(createDocument("test.yaml", input), "file:///workspace/");
expect(result).toEqual([
{
range: {
end: {
character: 62,
line: 3
},
start: {
character: 10,
line: 3
}
},
target: "https://www.github.com/seismis-rainier/workflows/tree/main/reusable-workflow.yml",
tooltip: "Open reusable workflow on GitHub"
}
]);
});
}); });
+50 -17
View File
@@ -1,13 +1,15 @@
import {ErrorPolicy} from "@github/actions-workflow-parser/model/convert"; import {ErrorPolicy} from "@github/actions-workflow-parser/model/convert";
import {isJob} from "@github/actions-workflow-parser/model/type-guards"; import {isJob, isReusableWorkflowJob} from "@github/actions-workflow-parser/model/type-guards";
import {File} from "@github/actions-workflow-parser/workflows/file"; import {File} from "@github/actions-workflow-parser/workflows/file";
import {parseFileReference} from "@github/actions-workflow-parser/workflows/file-reference";
import {TextDocument} from "vscode-languageserver-textdocument"; import {TextDocument} from "vscode-languageserver-textdocument";
import {DocumentLink} from "vscode-languageserver-types"; import {DocumentLink} from "vscode-languageserver-types";
import vscodeURI from "vscode-uri/lib/umd"; // work around issues with the vscode-uri package
import {actionUrl, parseActionReference} from "./action"; import {actionUrl, parseActionReference} from "./action";
import {mapRange} from "./utils/range"; import {mapRange} from "./utils/range";
import {fetchOrParseWorkflow, fetchOrConvertWorkflowTemplate} from "./utils/workflow-cache"; import {fetchOrConvertWorkflowTemplate, fetchOrParseWorkflow} from "./utils/workflow-cache";
export async function documentLinks(document: TextDocument): Promise<DocumentLink[]> { export async function documentLinks(document: TextDocument, workspace: string | undefined): Promise<DocumentLink[]> {
const file: File = { const file: File = {
name: document.uri, name: document.uri,
content: document.getText() content: document.getText()
@@ -22,30 +24,61 @@ export async function documentLinks(document: TextDocument): Promise<DocumentLin
errorPolicy: ErrorPolicy.TryConversion errorPolicy: ErrorPolicy.TryConversion
}); });
// Add links to referenced actions const links: DocumentLink[] = [];
const actionLinks: DocumentLink[] = [];
for (const job of template?.jobs || []) { for (const job of template?.jobs || []) {
if (!job || !isJob(job)) { if (!job) {
continue; continue;
} }
for (const step of job.steps || []) {
if ("uses" in step) { if (isJob(job)) {
const actionRef = parseActionReference(step.uses.value); // Add links to referenced actions
if (!actionRef) { for (const step of job.steps || []) {
continue; if ("uses" in step) {
const actionRef = parseActionReference(step.uses.value);
if (!actionRef) {
continue;
}
const url = actionUrl(actionRef);
links.push({
range: mapRange(step.uses.range),
target: url,
tooltip: `Open action on GitHub`
});
} }
}
} else if (isReusableWorkflowJob(job)) {
// Add links to referenced reusable workflows
const ref = parseFileReference(job.ref.value);
if ("repository" in ref) {
// Remote workflow
const url = actionUrl({
owner: ref.owner,
name: ref.repository,
path: ref.path,
ref: ref.version
});
const url = actionUrl(actionRef); links.push({
range: mapRange(job.ref.range),
actionLinks.push({
range: mapRange(step.uses.range),
target: url, target: url,
tooltip: `Open action on GitHub` tooltip: `Open reusable workflow on GitHub`
});
} else if (workspace) {
// We need workspace information to generate this link
// Local workflow, generate workspace link
const workspaceURI = vscodeURI.URI.parse(workspace);
const refURI = vscodeURI.Utils.joinPath(workspaceURI, job.ref.value);
links.push({
range: mapRange(job.ref.range),
target: refURI.toString()
}); });
} }
} }
} }
return [...actionLinks]; return [...links];
} }
+1 -1
View File
@@ -1,5 +1,5 @@
{ {
"$schema": "node_modules/lerna/schemas/lerna-schema.json", "$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useWorkspaces": true, "useWorkspaces": true,
"version": "0.1.173" "version": "0.1.174"
} }
+29 -17
View File
@@ -111,10 +111,10 @@
} }
}, },
"browser-playground": { "browser-playground": {
"version": "0.1.173", "version": "0.1.174",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@github/actions-languageserver": "^0.1.173", "@github/actions-languageserver": "^0.1.174",
"monaco-editor-webpack-plugin": "^7.0.1", "monaco-editor-webpack-plugin": "^7.0.1",
"monaco-editor-workers": "^0.34.2", "monaco-editor-workers": "^0.34.2",
"monaco-languageclient": "^4.0.3", "monaco-languageclient": "^4.0.3",
@@ -135,7 +135,7 @@
}, },
"expressions": { "expressions": {
"name": "@github/actions-expressions", "name": "@github/actions-expressions",
"version": "0.1.173", "version": "0.1.174",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@types/jest": "^29.0.3", "@types/jest": "^29.0.3",
@@ -151,11 +151,11 @@
}, },
"languageserver": { "languageserver": {
"name": "@github/actions-languageserver", "name": "@github/actions-languageserver",
"version": "0.1.173", "version": "0.1.174",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@github/actions-languageservice": "^0.1.173", "@github/actions-languageservice": "^0.1.174",
"@github/actions-workflow-parser": "^0.1.173", "@github/actions-workflow-parser": "^0.1.174",
"@octokit/rest": "^19.0.7", "@octokit/rest": "^19.0.7",
"@octokit/types": "^9.0.0", "@octokit/types": "^9.0.0",
"vscode-languageserver": "^8.0.2", "vscode-languageserver": "^8.0.2",
@@ -190,13 +190,14 @@
}, },
"languageservice": { "languageservice": {
"name": "@github/actions-languageservice", "name": "@github/actions-languageservice",
"version": "0.1.173", "version": "0.1.174",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@github/actions-expressions": "^0.1.173", "@github/actions-expressions": "^0.1.174",
"@github/actions-workflow-parser": "^0.1.173", "@github/actions-workflow-parser": "^0.1.174",
"vscode-languageserver-textdocument": "^1.0.7", "vscode-languageserver-textdocument": "^1.0.7",
"vscode-languageserver-types": "^3.17.2", "vscode-languageserver-types": "^3.17.2",
"vscode-uri": "^3.0.7",
"yaml": "^2.1.1" "yaml": "^2.1.1"
}, },
"devDependencies": { "devDependencies": {
@@ -13566,6 +13567,11 @@
"integrity": "sha512-9hJp0xL7HW1Q5OgGe03NACo7yiCTMEk3WU/rtKXUbncLtdg6rVVNJnHwD88UhbIYU2KoxY0Dih0x+kIsmUKn2A==", "integrity": "sha512-9hJp0xL7HW1Q5OgGe03NACo7yiCTMEk3WU/rtKXUbncLtdg6rVVNJnHwD88UhbIYU2KoxY0Dih0x+kIsmUKn2A==",
"peer": true "peer": true
}, },
"node_modules/vscode-uri": {
"version": "3.0.7",
"resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-3.0.7.tgz",
"integrity": "sha512-eOpPHogvorZRobNqJGhapa0JdwaxpjVvyBp0QIUMRMSf8ZAlqOdEquKuRmw9Qwu0qXtJIWqFtMkmvJjUZmMjVA=="
},
"node_modules/walk-up-path": { "node_modules/walk-up-path": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/walk-up-path/-/walk-up-path-1.0.0.tgz", "resolved": "https://registry.npmjs.org/walk-up-path/-/walk-up-path-1.0.0.tgz",
@@ -14279,10 +14285,10 @@
}, },
"workflow-parser": { "workflow-parser": {
"name": "@github/actions-workflow-parser", "name": "@github/actions-workflow-parser",
"version": "0.1.173", "version": "0.1.174",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@github/actions-expressions": "^0.1.173", "@github/actions-expressions": "^0.1.174",
"cronstrue": "^2.21.0", "cronstrue": "^2.21.0",
"yaml": "^2.0.0-8" "yaml": "^2.0.0-8"
}, },
@@ -14841,8 +14847,8 @@
"@github/actions-languageserver": { "@github/actions-languageserver": {
"version": "file:languageserver", "version": "file:languageserver",
"requires": { "requires": {
"@github/actions-languageservice": "^0.1.173", "@github/actions-languageservice": "^0.1.174",
"@github/actions-workflow-parser": "^0.1.173", "@github/actions-workflow-parser": "^0.1.174",
"@octokit/rest": "^19.0.7", "@octokit/rest": "^19.0.7",
"@octokit/types": "^9.0.0", "@octokit/types": "^9.0.0",
"@types/jest": "^29.0.3", "@types/jest": "^29.0.3",
@@ -14875,8 +14881,8 @@
"@github/actions-languageservice": { "@github/actions-languageservice": {
"version": "file:languageservice", "version": "file:languageservice",
"requires": { "requires": {
"@github/actions-expressions": "^0.1.173", "@github/actions-expressions": "^0.1.174",
"@github/actions-workflow-parser": "^0.1.173", "@github/actions-workflow-parser": "^0.1.174",
"@types/jest": "^29.0.3", "@types/jest": "^29.0.3",
"jest": "^29.0.3", "jest": "^29.0.3",
"prettier": "^2.8.3", "prettier": "^2.8.3",
@@ -14887,13 +14893,14 @@
"typescript": "^4.8.4", "typescript": "^4.8.4",
"vscode-languageserver-textdocument": "^1.0.7", "vscode-languageserver-textdocument": "^1.0.7",
"vscode-languageserver-types": "^3.17.2", "vscode-languageserver-types": "^3.17.2",
"vscode-uri": "^3.0.7",
"yaml": "^2.1.1" "yaml": "^2.1.1"
} }
}, },
"@github/actions-workflow-parser": { "@github/actions-workflow-parser": {
"version": "file:workflow-parser", "version": "file:workflow-parser",
"requires": { "requires": {
"@github/actions-expressions": "^0.1.173", "@github/actions-expressions": "^0.1.174",
"@types/jest": "^29.0.3", "@types/jest": "^29.0.3",
"@typescript-eslint/eslint-plugin": "^5.40.0", "@typescript-eslint/eslint-plugin": "^5.40.0",
"@typescript-eslint/parser": "^5.40.0", "@typescript-eslint/parser": "^5.40.0",
@@ -17887,7 +17894,7 @@
"browser-playground": { "browser-playground": {
"version": "file:browser-playground", "version": "file:browser-playground",
"requires": { "requires": {
"@github/actions-languageserver": "^0.1.173", "@github/actions-languageserver": "^0.1.174",
"css-loader": "^6.7.2", "css-loader": "^6.7.2",
"monaco-editor-webpack-plugin": "^7.0.1", "monaco-editor-webpack-plugin": "^7.0.1",
"monaco-editor-workers": "^0.34.2", "monaco-editor-workers": "^0.34.2",
@@ -24672,6 +24679,11 @@
"integrity": "sha512-9hJp0xL7HW1Q5OgGe03NACo7yiCTMEk3WU/rtKXUbncLtdg6rVVNJnHwD88UhbIYU2KoxY0Dih0x+kIsmUKn2A==", "integrity": "sha512-9hJp0xL7HW1Q5OgGe03NACo7yiCTMEk3WU/rtKXUbncLtdg6rVVNJnHwD88UhbIYU2KoxY0Dih0x+kIsmUKn2A==",
"peer": true "peer": true
}, },
"vscode-uri": {
"version": "3.0.7",
"resolved": "https://registry.npmjs.org/vscode-uri/-/vscode-uri-3.0.7.tgz",
"integrity": "sha512-eOpPHogvorZRobNqJGhapa0JdwaxpjVvyBp0QIUMRMSf8ZAlqOdEquKuRmw9Qwu0qXtJIWqFtMkmvJjUZmMjVA=="
},
"walk-up-path": { "walk-up-path": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/walk-up-path/-/walk-up-path-1.0.0.tgz", "resolved": "https://registry.npmjs.org/walk-up-path/-/walk-up-path-1.0.0.tgz",
+2 -2
View File
@@ -1,6 +1,6 @@
{ {
"name": "@github/actions-workflow-parser", "name": "@github/actions-workflow-parser",
"version": "0.1.173", "version": "0.1.174",
"license": "MIT", "license": "MIT",
"type": "module", "type": "module",
"source": "./src/index.ts", "source": "./src/index.ts",
@@ -40,7 +40,7 @@
"watch": "tsc --build tsconfig.build.json --watch" "watch": "tsc --build tsconfig.build.json --watch"
}, },
"dependencies": { "dependencies": {
"@github/actions-expressions": "^0.1.173", "@github/actions-expressions": "^0.1.174",
"cronstrue": "^2.21.0", "cronstrue": "^2.21.0",
"yaml": "^2.0.0-8" "yaml": "^2.0.0-8"
}, },