Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fdad3474fc | |||
| 0446b065b0 | |||
| 763dff2018 | |||
| 0c9d817440 | |||
| cc316ab9de | |||
| d5670c383a | |||
| f62a0e189d |
@@ -0,0 +1,33 @@
|
||||
# Agents
|
||||
|
||||
## Build
|
||||
|
||||
```
|
||||
npx lerna run build
|
||||
```
|
||||
|
||||
## Test
|
||||
|
||||
```
|
||||
npm -w @actions/expressions test
|
||||
npm -w @actions/workflow-parser test
|
||||
npm -w @actions/languageservice test
|
||||
```
|
||||
|
||||
## Format
|
||||
|
||||
Always run formatting before committing:
|
||||
|
||||
```
|
||||
npx prettier --write <changed files>
|
||||
```
|
||||
|
||||
Verify with:
|
||||
|
||||
```
|
||||
npm run format-check -ws
|
||||
```
|
||||
|
||||
## Feature flags
|
||||
|
||||
Feature flags are defined in `expressions/src/features.ts` (`ExperimentalFeatures` interface + `allFeatureKeys` array). They are plumbed through `ConvertOptions`, `CompletionConfig`, `ValidationConfig`, and `initializationOptions`. When a feature graduates to stable, remove its flag and make the behavior unconditional.
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@actions/expressions",
|
||||
"version": "0.3.50",
|
||||
"version": "0.4.0",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"source": "./src/index.ts",
|
||||
|
||||
@@ -55,8 +55,7 @@ describe("FeatureFlags", () => {
|
||||
"missingInputsQuickfix",
|
||||
"blockScalarChompingWarning",
|
||||
"allowCaseFunction",
|
||||
"allowCopilotRequestsPermission",
|
||||
"allowServiceContainerCommand"
|
||||
"allowCopilotRequestsPermission"
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -40,12 +40,6 @@ export interface ExperimentalFeatures {
|
||||
* @default false
|
||||
*/
|
||||
allowCopilotRequestsPermission?: boolean;
|
||||
|
||||
/**
|
||||
* Enable `entrypoint` and `command` keys in service containers (`jobs.<job_id>.services.*`).
|
||||
* @default false
|
||||
*/
|
||||
allowServiceContainerCommand?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,8 +55,7 @@ const allFeatureKeys: ExperimentalFeatureKey[] = [
|
||||
"missingInputsQuickfix",
|
||||
"blockScalarChompingWarning",
|
||||
"allowCaseFunction",
|
||||
"allowCopilotRequestsPermission",
|
||||
"allowServiceContainerCommand"
|
||||
"allowCopilotRequestsPermission"
|
||||
];
|
||||
|
||||
export class FeatureFlags {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@actions/languageserver",
|
||||
"version": "0.3.50",
|
||||
"version": "0.4.0",
|
||||
"description": "Language server for GitHub Actions",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
@@ -48,8 +48,8 @@
|
||||
"actions-languageserver": "./bin/actions-languageserver"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/languageservice": "^0.3.50",
|
||||
"@actions/workflow-parser": "^0.3.50",
|
||||
"@actions/languageservice": "^0.4.0",
|
||||
"@actions/workflow-parser": "^0.4.0",
|
||||
"@octokit/rest": "^21.1.1",
|
||||
"@octokit/types": "^9.0.0",
|
||||
"vscode-languageserver": "^8.0.2",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@actions/languageservice",
|
||||
"version": "0.3.50",
|
||||
"version": "0.4.0",
|
||||
"description": "Language service for GitHub Actions",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
@@ -47,8 +47,8 @@
|
||||
"watch": "tsc --build tsconfig.build.json --watch"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/expressions": "^0.3.50",
|
||||
"@actions/workflow-parser": "^0.3.50",
|
||||
"@actions/expressions": "^0.4.0",
|
||||
"@actions/workflow-parser": "^0.4.0",
|
||||
"vscode-languageserver-textdocument": "^1.0.7",
|
||||
"vscode-languageserver-types": "^3.17.2",
|
||||
"vscode-uri": "^3.0.8",
|
||||
|
||||
@@ -1164,7 +1164,16 @@ jobs:
|
||||
`;
|
||||
|
||||
const result = await complete(...getPositionFromCursor(input), {contextProviderConfig});
|
||||
expect(result.map(x => x.label)).toEqual(["check_run_id", "container", "services", "status"]);
|
||||
expect(result.map(x => x.label)).toEqual([
|
||||
"check_run_id",
|
||||
"container",
|
||||
"services",
|
||||
"status",
|
||||
"workflow_file_path",
|
||||
"workflow_ref",
|
||||
"workflow_repository",
|
||||
"workflow_sha"
|
||||
]);
|
||||
});
|
||||
|
||||
it("job context is suggested within a job output", async () => {
|
||||
|
||||
@@ -105,13 +105,6 @@
|
||||
"job": {
|
||||
"description": "The [`job_id`](https://docs.github.com/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_id) of the current job.\nNote: This context property is set by the Actions runner, and is only available within the execution `steps` of a job. Otherwise, the value of this property will be `null`."
|
||||
},
|
||||
"job_workflow_sha": {
|
||||
"description": "For jobs using a reusable workflow, the commit SHA for the reusable workflow file.",
|
||||
"versions": {
|
||||
"ghes": ">=3.9",
|
||||
"ghae": ">=3.9"
|
||||
}
|
||||
},
|
||||
"path": {
|
||||
"description": "Path on the runner to the file that sets system PATH variables from workflow commands. This file is unique to the current step and is a different file for each step in a job. For more information, see \"[Workflow commands for GitHub Actions](https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path).\""
|
||||
},
|
||||
@@ -225,6 +218,18 @@
|
||||
},
|
||||
"check_run_id": {
|
||||
"description": "The unique identifier of the check run for this job."
|
||||
},
|
||||
"workflow_file_path": {
|
||||
"description": "The path of the workflow file that contains the job. For example, `.github/workflows/my-workflow.yml`."
|
||||
},
|
||||
"workflow_ref": {
|
||||
"description": "The ref path to the workflow file that contains the job. For example, `octocat/hello-world/.github/workflows/my-workflow.yml@refs/heads/my_branch`."
|
||||
},
|
||||
"workflow_repository": {
|
||||
"description": "The owner and repository name of the workflow file that contains the job. For example, `octocat/Hello-World`."
|
||||
},
|
||||
"workflow_sha": {
|
||||
"description": "The commit SHA of the workflow file that contains the job."
|
||||
}
|
||||
},
|
||||
"secrets": {
|
||||
|
||||
@@ -29,7 +29,6 @@ export function getGithubContext(workflowContext: WorkflowContext | undefined, m
|
||||
"graphql_url",
|
||||
"head_ref",
|
||||
"job",
|
||||
"job_workflow_sha",
|
||||
"path",
|
||||
"ref",
|
||||
"ref_name",
|
||||
|
||||
@@ -18,12 +18,16 @@ describe("job context", () => {
|
||||
expect(context.pairs().length).toBe(0);
|
||||
});
|
||||
|
||||
it("returns status and check_run_id when job has no container or services", () => {
|
||||
it("returns status, check_run_id, and workflow fields when job has no container or services", () => {
|
||||
const workflowContext = {job: {}} as WorkflowContext;
|
||||
const context = getJobContext(workflowContext);
|
||||
|
||||
expect(context.get("status")).toBeDefined();
|
||||
expect(context.get("check_run_id")).toBeDefined();
|
||||
expect(context.get("workflow_ref")).toBeDefined();
|
||||
expect(context.get("workflow_sha")).toBeDefined();
|
||||
expect(context.get("workflow_repository")).toBeDefined();
|
||||
expect(context.get("workflow_file_path")).toBeDefined();
|
||||
expect(context.get("container")).toBeUndefined();
|
||||
expect(context.get("services")).toBeUndefined();
|
||||
});
|
||||
@@ -173,4 +177,21 @@ describe("job context", () => {
|
||||
expect(redis.getDescription("ports")).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("workflow context fields", () => {
|
||||
it("includes workflow context fields with descriptions", () => {
|
||||
const workflowContext = {job: {}} as WorkflowContext;
|
||||
const context = getJobContext(workflowContext);
|
||||
|
||||
expect(context.get("workflow_ref")).toBeDefined();
|
||||
expect(context.get("workflow_sha")).toBeDefined();
|
||||
expect(context.get("workflow_repository")).toBeDefined();
|
||||
expect(context.get("workflow_file_path")).toBeDefined();
|
||||
|
||||
expect(context.getDescription("workflow_ref")).toBeDefined();
|
||||
expect(context.getDescription("workflow_sha")).toBeDefined();
|
||||
expect(context.getDescription("workflow_repository")).toBeDefined();
|
||||
expect(context.getDescription("workflow_file_path")).toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ import {WorkflowContext} from "../context/workflow-context.js";
|
||||
import {getDescription} from "./descriptions.js";
|
||||
|
||||
/**
|
||||
* Returns the job context with container, services, status, and check_run_id.
|
||||
* Returns the job context with container, services, status, check_run_id, and workflow identity fields.
|
||||
*/
|
||||
export function getJobContext(workflowContext: WorkflowContext): DescriptionDictionary {
|
||||
// https://docs.github.com/en/actions/learn-github-actions/contexts#job-context
|
||||
@@ -42,6 +42,12 @@ export function getJobContext(workflowContext: WorkflowContext): DescriptionDict
|
||||
// Check run ID
|
||||
jobContext.add("check_run_id", new data.StringData(""), getDescription("job", "check_run_id"));
|
||||
|
||||
// Workflow context fields (populated at runtime for reusable workflow jobs)
|
||||
jobContext.add("workflow_file_path", new data.StringData(""), getDescription("job", "workflow_file_path"));
|
||||
jobContext.add("workflow_ref", new data.StringData(""), getDescription("job", "workflow_ref"));
|
||||
jobContext.add("workflow_repository", new data.StringData(""), getDescription("job", "workflow_repository"));
|
||||
jobContext.add("workflow_sha", new data.StringData(""), getDescription("job", "workflow_sha"));
|
||||
|
||||
return jobContext;
|
||||
}
|
||||
|
||||
|
||||
@@ -432,6 +432,24 @@ jobs:
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
|
||||
it("job.workflow_* fields", async () => {
|
||||
const input = `
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: echo \${{ job.workflow_ref }}
|
||||
- run: echo \${{ job.workflow_sha }}
|
||||
- run: echo \${{ job.workflow_repository }}
|
||||
- run: echo \${{ job.workflow_file_path }}
|
||||
`;
|
||||
const result = await validate(createDocument("wf.yaml", input));
|
||||
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
|
||||
it("job.services.<service_id>", async () => {
|
||||
const input = `
|
||||
on: push
|
||||
|
||||
@@ -1,24 +1,18 @@
|
||||
import {FeatureFlags} from "@actions/expressions";
|
||||
import {registerLogger} from "./log.js";
|
||||
import {createDocument} from "./test-utils/document.js";
|
||||
import {TestLogger} from "./test-utils/logger.js";
|
||||
import {clearCache} from "./utils/workflow-cache.js";
|
||||
import {validate, ValidationConfig} from "./validate.js";
|
||||
import {validate} from "./validate.js";
|
||||
|
||||
registerLogger(new TestLogger());
|
||||
|
||||
const configWithFlag: ValidationConfig = {
|
||||
featureFlags: new FeatureFlags({allowServiceContainerCommand: true})
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
clearCache();
|
||||
});
|
||||
|
||||
describe("service container command/entrypoint", () => {
|
||||
describe("with feature flag enabled", () => {
|
||||
it("allows command in service container", async () => {
|
||||
const input = `
|
||||
it("allows command in service container", async () => {
|
||||
const input = `
|
||||
on: push
|
||||
jobs:
|
||||
build:
|
||||
@@ -30,13 +24,13 @@ jobs:
|
||||
steps:
|
||||
- run: echo hi
|
||||
`;
|
||||
const result = await validate(createDocument("wf.yaml", input), configWithFlag);
|
||||
const commandErrors = result.filter(d => d.message.includes("command"));
|
||||
expect(commandErrors).toEqual([]);
|
||||
});
|
||||
const result = await validate(createDocument("wf.yaml", input));
|
||||
const commandErrors = result.filter(d => d.message.includes("command"));
|
||||
expect(commandErrors).toEqual([]);
|
||||
});
|
||||
|
||||
it("allows entrypoint in service container", async () => {
|
||||
const input = `
|
||||
it("allows entrypoint in service container", async () => {
|
||||
const input = `
|
||||
on: push
|
||||
jobs:
|
||||
build:
|
||||
@@ -48,13 +42,13 @@ jobs:
|
||||
steps:
|
||||
- run: echo hi
|
||||
`;
|
||||
const result = await validate(createDocument("wf.yaml", input), configWithFlag);
|
||||
const entrypointErrors = result.filter(d => d.message.includes("entrypoint"));
|
||||
expect(entrypointErrors).toEqual([]);
|
||||
});
|
||||
const result = await validate(createDocument("wf.yaml", input));
|
||||
const entrypointErrors = result.filter(d => d.message.includes("entrypoint"));
|
||||
expect(entrypointErrors).toEqual([]);
|
||||
});
|
||||
|
||||
it("allows both command and entrypoint in service container", async () => {
|
||||
const input = `
|
||||
it("allows both command and entrypoint in service container", async () => {
|
||||
const input = `
|
||||
on: push
|
||||
jobs:
|
||||
build:
|
||||
@@ -67,13 +61,13 @@ jobs:
|
||||
steps:
|
||||
- run: echo hi
|
||||
`;
|
||||
const result = await validate(createDocument("wf.yaml", input), configWithFlag);
|
||||
const relevantErrors = result.filter(d => d.message.includes("command") || d.message.includes("entrypoint"));
|
||||
expect(relevantErrors).toEqual([]);
|
||||
});
|
||||
const result = await validate(createDocument("wf.yaml", input));
|
||||
const relevantErrors = result.filter(d => d.message.includes("command") || d.message.includes("entrypoint"));
|
||||
expect(relevantErrors).toEqual([]);
|
||||
});
|
||||
|
||||
it("rejects command in job container even with flag enabled", async () => {
|
||||
const input = `
|
||||
it("rejects command in job container", async () => {
|
||||
const input = `
|
||||
on: push
|
||||
jobs:
|
||||
build:
|
||||
@@ -84,13 +78,13 @@ jobs:
|
||||
steps:
|
||||
- run: echo hi
|
||||
`;
|
||||
const result = await validate(createDocument("wf.yaml", input), configWithFlag);
|
||||
const commandErrors = result.filter(d => d.message.includes("command"));
|
||||
expect(commandErrors.length).toBeGreaterThan(0);
|
||||
});
|
||||
const result = await validate(createDocument("wf.yaml", input));
|
||||
const commandErrors = result.filter(d => d.message.includes("command"));
|
||||
expect(commandErrors.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("rejects entrypoint in job container even with flag enabled", async () => {
|
||||
const input = `
|
||||
it("rejects entrypoint in job container", async () => {
|
||||
const input = `
|
||||
on: push
|
||||
jobs:
|
||||
build:
|
||||
@@ -101,47 +95,8 @@ jobs:
|
||||
steps:
|
||||
- run: echo hi
|
||||
`;
|
||||
const result = await validate(createDocument("wf.yaml", input), configWithFlag);
|
||||
const entrypointErrors = result.filter(d => d.message.includes("entrypoint"));
|
||||
expect(entrypointErrors.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with feature flag disabled", () => {
|
||||
it("rejects command in service container", async () => {
|
||||
const input = `
|
||||
on: push
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
services:
|
||||
redis:
|
||||
image: redis
|
||||
command: --port 6380
|
||||
steps:
|
||||
- run: echo hi
|
||||
`;
|
||||
const result = await validate(createDocument("wf.yaml", input));
|
||||
const commandErrors = result.filter(d => d.message.includes("command"));
|
||||
expect(commandErrors.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("rejects entrypoint in service container", async () => {
|
||||
const input = `
|
||||
on: push
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
services:
|
||||
redis:
|
||||
image: redis
|
||||
entrypoint: /usr/local/bin/redis-server
|
||||
steps:
|
||||
- run: echo hi
|
||||
`;
|
||||
const result = await validate(createDocument("wf.yaml", input));
|
||||
const entrypointErrors = result.filter(d => d.message.includes("entrypoint"));
|
||||
expect(entrypointErrors.length).toBeGreaterThan(0);
|
||||
});
|
||||
const result = await validate(createDocument("wf.yaml", input));
|
||||
const entrypointErrors = result.filter(d => d.message.includes("entrypoint"));
|
||||
expect(entrypointErrors.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
+1
-1
@@ -6,5 +6,5 @@
|
||||
"languageservice",
|
||||
"languageserver"
|
||||
],
|
||||
"version": "0.3.50"
|
||||
"version": "0.4.0"
|
||||
}
|
||||
Generated
+9
-9
@@ -136,7 +136,7 @@
|
||||
},
|
||||
"expressions": {
|
||||
"name": "@actions/expressions",
|
||||
"version": "0.3.50",
|
||||
"version": "0.4.0",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.0.3",
|
||||
@@ -396,11 +396,11 @@
|
||||
},
|
||||
"languageserver": {
|
||||
"name": "@actions/languageserver",
|
||||
"version": "0.3.50",
|
||||
"version": "0.4.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/languageservice": "^0.3.50",
|
||||
"@actions/workflow-parser": "^0.3.50",
|
||||
"@actions/languageservice": "^0.4.0",
|
||||
"@actions/workflow-parser": "^0.4.0",
|
||||
"@octokit/rest": "^21.1.1",
|
||||
"@octokit/types": "^9.0.0",
|
||||
"vscode-languageserver": "^8.0.2",
|
||||
@@ -927,11 +927,11 @@
|
||||
},
|
||||
"languageservice": {
|
||||
"name": "@actions/languageservice",
|
||||
"version": "0.3.50",
|
||||
"version": "0.4.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/expressions": "^0.3.50",
|
||||
"@actions/workflow-parser": "^0.3.50",
|
||||
"@actions/expressions": "^0.4.0",
|
||||
"@actions/workflow-parser": "^0.4.0",
|
||||
"vscode-languageserver-textdocument": "^1.0.7",
|
||||
"vscode-languageserver-types": "^3.17.2",
|
||||
"vscode-uri": "^3.0.8",
|
||||
@@ -14020,10 +14020,10 @@
|
||||
},
|
||||
"workflow-parser": {
|
||||
"name": "@actions/workflow-parser",
|
||||
"version": "0.3.50",
|
||||
"version": "0.4.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/expressions": "^0.3.50",
|
||||
"@actions/expressions": "^0.4.0",
|
||||
"cronstrue": "^2.21.0",
|
||||
"yaml": "^2.0.0-8"
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@actions/workflow-parser",
|
||||
"version": "0.3.50",
|
||||
"version": "0.4.0",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"source": "./src/index.ts",
|
||||
@@ -48,7 +48,7 @@
|
||||
"watch": "tsc --build tsconfig.build.json --watch"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/expressions": "^0.3.50",
|
||||
"@actions/expressions": "^0.4.0",
|
||||
"cronstrue": "^2.21.0",
|
||||
"yaml": "^2.0.0-8"
|
||||
},
|
||||
|
||||
@@ -146,15 +146,11 @@ export function convertToServiceContainer(context: TemplateContext, container: T
|
||||
|
||||
export function convertToJobServices(context: TemplateContext, services: TemplateToken): Container[] | undefined {
|
||||
const serviceList: Container[] = [];
|
||||
const flags = context.state.featureFlags as import("@actions/expressions/features").FeatureFlags | undefined;
|
||||
const useServiceContainer = flags?.isEnabled("allowServiceContainerCommand") ?? false;
|
||||
|
||||
const mapping = services.assertMapping("services");
|
||||
for (const service of mapping) {
|
||||
service.key.assertString("service key");
|
||||
const container = useServiceContainer
|
||||
? convertToServiceContainer(context, service.value)
|
||||
: convertToJobContainer(context, service.value);
|
||||
const container = convertToServiceContainer(context, service.value);
|
||||
if (container) {
|
||||
serviceList.push(container);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user