Giter VIP home page Giter VIP logo

languageservices's Introduction

Language Services for GitHub Actions

This repository contains multiple npm packages for working with GitHub Actions workflow YAML files. See the README.md files in the individual package folders.

Contributing

See CONTRIBUTING.md

languageservices's People

Contributors

activescott avatar bdehamer avatar cdb avatar cschleiden avatar dependabot[bot] avatar elbrenn avatar felipesu19 avatar hashtagchris avatar joshmgross avatar jtamsut avatar ketchuponmyketchup avatar konradpabjan avatar lauraway avatar lrotschy avatar muzimuzhi avatar olfi01 avatar thyeggman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

languageservices's Issues

Shouldn't warn with "Context access might be invalid" if not logged in

Describe the bug
This mostly shows itself when using the GitHub Actions VSCode extension, but not logging in. In this case the extension reports the warning "Context access might be invalid" on all secret names, which is presumably unwanted behavior.

Since the warning is caused by the language server, this seems like the appropriate repo to open the issue in.

To Reproduce
Steps to reproduce the behavior:

  1. Install the GitHub Actions VSCode extension but do not log in (or log out if you're already logged in).
  2. Navigate to an action file using a secret.
  3. Observe that the warning is logged.

Expected behavior
The language server either logs one warning, saying that it isn't logged in, or doesn't log any warning at all.

Screenshots
Screenshot of the warning

Package/Area

  • Expressions
  • Workflow Parser
  • Language Service
  • Language Server

Package Version
v0.3.8

Additional context
Code logging the warning appears to be:

if (e instanceof AccessError) {
this.errors.push({
message: `Context access might be invalid: ${e.keyName}`,
severity: "warning"
});

This has been previously reported in the github/vscode-github-actions repo, including in github/vscode-github-actions#222 (comment)

Fetching variables isn't handling 404 error requests for `Variables` in GHES versions before 3.8

Describe the bug
Whenever I open a workflow connected to GHES 3.7, I get the following error message (sensitive data hidden by ***). This is because the Variables support was introduced on GHES 3.8.

Failure to retrieve variables:  Cs [HttpError]: Not Found
{
  status: 404,
  response: {
    url: 'https://***/api/v3/repos/***/***/actions/variables?per_page=100',
    status: 404,
    headers: {
      'access-control-allow-origin': '*',
      'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset',
      'content-encoding': 'gzip',
      'content-security-policy': "default-src 'none'",
      'content-type': 'application/json; charset=utf-8',
      date: 'Wed, 10 Apr 2024 16:41:09 GMT',
      'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
      server: 'GitHub.com',
      'strict-transport-security': 'max-age=31536000; includeSubdomains',
      'transfer-encoding': 'chunked',
      'x-accepted-oauth-scopes': 'repo',
      'x-content-type-options': 'nosniff',
      'x-frame-options': 'deny',
      'x-github-enterprise-version': '3.7.5',
      'x-github-media-type': 'github.v3; format=json',
      'x-github-request-id': '***',
      'x-oauth-client-id': '***',
      'x-oauth-scopes': 'repo, workflow',
      'x-ratelimit-limit': '5000',
      'x-ratelimit-remaining': '4982',
      'x-ratelimit-reset': '1712767559',
      'x-ratelimit-resource': 'core',
      'x-ratelimit-used': '18',
      'x-runtime-rack': '0.033786',
      'x-xss-protection': '0'
    },
    data: {
      message: 'Not Found',
      documentation_url: 'https://docs.github.com/[email protected]/rest'
    }
  },
  request: {
    method: 'GET',
    url: 'https://***/api/v3/repos/***/***/actions/variables?per_page=100',
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'VS Code GitHub Actions (0.26.2) octokit-rest.js/19.0.7 octokit-core.js/4.1.0 Node.js/18.18.2 (linux; x64)',
      authorization: 'token [REDACTED]'
    },
    request: { hook: [Function: bound bound e] }
  }
}

To Reproduce
Steps to reproduce the behavior:

  1. Log into a GitHub Enterprise server version 3.7 in VSCode
  2. Open a workflow file related to a GH project
  3. See several 404 errors trying to reach https://<ghes_url>/api/v3/repos/<user>/<repo>/actions/variables

Expected behavior
Either detect whether the server supports this request or waive this error without throwing it considering that the server may not support this.

Screenshots
If applicable, add screenshots to help explain your problem.

Package/Area

  • Expressions
  • Workflow Parser
  • Language Service
  • Language Server

Package Version
v0.3.9

Additional context
I recently reported github/vscode-github-actions#313. I noticed their repo uses @actions/languageserver, and after some investigation, I found that the root cause for unhandled 404 error requests for Variables might be related to the code below - based on the error message I'm getting (line 142).

async function fetchVariables(octokit: Octokit, owner: string, name: string): Promise<Pair[]> {
try {
return await octokit.paginate(
octokit.actions.listRepoVariables,
{
owner: owner,
repo: name,
per_page: 100
},
response =>
response.data.map(variable => {
return {key: variable.name, value: new StringData(variable.value)};
})
);
} catch (e) {
console.log("Failure to retrieve variables: ", e);
throw e;
}
}

The only place I can see this function being called is inside getRemoteVariables, which is also only used in the code below (line 47).

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;
}
>();
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 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));
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;
}

However, the error should be caught by:

} 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;
}

And the error would be waived. But it looks like the error isn't handled properly for e.name == "HttpError" && e.status == 404 and the error is thrown anyway.

Blaming the file, I see 41436c6 might have shadowed the case where the context is still returned and a log message is displayed. I'm not 100% confident of this because I don't know if the error thrown for 404 is NOT a RequestError, but that's the only reason I could think of.

Thanks for the language server :) amazing work here

validation false-positives in diff editor

This validation is very helpful when editing workflow files:

context.error(job.ref, new Error("Unable to find reusable workflow"));

But unfortunately, it runs not only on opened VS Code editors, but on diff editors as well. And in diff editors, it triggers false positives on all relative file paths. Example:

image

I suspect this might be because diff editors have different file url scheme, so it is unable to consolidate that with file:// lookup?
Additionally, it triggers on both the before and after file editors.

I wonder if it is possible to detect diff editors, and skip running this kind of validation when not possible?
Thank you.

Provide a standalone binary executable for `actions-languageserver`?

Is your feature request related to a problem? Please describe.
I would like to use actions-languageserver in my vim/neovim setup, but this project and npm package don't seem to provide a standalone executable.

Describe the solution you'd like
Is it possible to produce a standalone binary executable for actions-languageserver to be used by other editors?

Additional context
N/A

No "exports" main defined

Describe the bug

When importing the module i get the following error:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /home/itasahobby/Documentos/OpenPwn/node_modules/@actions/workflow-parser/package.json
    at new NodeError (node:internal/errors:405:5)
    at exportsNotFound (node:internal/modules/esm/resolve:261:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:535:13)
    at resolveExports (node:internal/modules/cjs/loader:547:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:621:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1034:27)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/usr/local/lib/node_modules/ts-node/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
    at Function.Module._load (node:internal/modules/cjs/loader:901:27)
    at Module.require (node:internal/modules/cjs/loader:1115:19)
    at require (node:internal/modules/helpers:119:18) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

To Reproduce
Steps to reproduce the behavior:

  1. npm init -y
  2. npm install '@actions/workflow-parser
  3. Create index.ts with the following:
import { NoOperationTraceWriter, parseWorkflow } from "@actions/workflow-parser";

var trace = new NoOperationTraceWriter();

const result = parseWorkflow(
    {
        name: "test.yaml",
        content: `on: push
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - run: echo 'hello'`
    },
    trace
);
  1. ts-node index.ts

Expected behavior
Program should work as expected.

Screenshots
image

Package/Area

  • Expressions
  • Workflow Parser
  • Language Service
  • Language Server

Package Version
v0.3.6"

Additional context
Versions:

  • node 20.5.0
  • ts-node 10.9.1
  • npm 9.8.0
  • Linux debia Debian 5.10.179-1

Incorrect description of cron's minimum schedule time

Describe the bug
The cron description states the following:

"\n\nActions schedules run at most every 5 minutes." +

Is this not incorrect, or am I reading this wrong? If schedules run at most every 5 minutes, then schedules may only run between 0-5 minutes, hence "5 minutes at most". Should this not be:

- Actions schedules run at most every 5 minutes.
+ Actions schedules run at least every 5 minutes.

Or rephrased from the documentation:

The shortest interval is once every 5 minutes.

These suggested descriptions now state the shortest minimum time is 5 minutes.

To Reproduce
N/A

Expected behavior
Correct (unambiguous) text.

Screenshots
N/A

Package/Area

  • Expressions
  • Workflow Parser
  • Language Service
  • Language Server

Package Version
v0.3.9

Additional context
N/A

expressions: ERR_MODULE_NOT_FOUND attempting to run example demo script

Describe the bug
The instructions for running the demo don't seem to work. While I'm pretty sure it's user error, it's not clear how to address this. Especially from within the runtime context of a @actions/github-script.

To Reproduce
Steps to reproduce the behavior:

  1. npm install @actions/expressions
  2. copy example code block, simple example to a file (note: it's not obvious, but it appears it must be in a mjs file as it uses imports keyword)
  3. run with: node ./example.mjs.

Expected behavior
A testable example.

Screenshots

$ npm install @actions/expressions
$ vim example.mjs
...
$ node example.mjs
node:internal/modules/esm/resolve:264
    throw new ERR_MODULE_NOT_FOUND(
          ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/private/var/folders/j0/_6v6ffj54qs0wrl91bz5tbw40000gp/T/tmp.mvxT5dPk/node_modules/@actions/expressions/dist/ast' imported from /private/var/folders/j0/_6v6ffj54qs0wrl91bz5tbw40000gp/T/tmp.mvxT5dPk/node_modules/@actions/expressions/dist/index.js
    at finalizeResolution (node:internal/modules/esm/resolve:264:11)
    at moduleResolve (node:internal/modules/esm/resolve:917:10)
    at defaultResolve (node:internal/modules/esm/resolve:1130:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:396:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:365:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:240:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
    at link (node:internal/modules/esm/module_job:84:36) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///private/var/folders/j0/_6v6ffj54qs0wrl91bz5tbw40000gp/T/tmp.mvxT5dPk/node_modules/@actions/expressions/dist/ast'
}

Node.js v21.4.0

Package/Area

  • Expressions
  • Workflow Parser
  • Language Service
  • Language Server

Package Version
v0.3.8

Additional context

I really just want to access this module from within a @actions/github-script step but for the life of me I haven't been able to figure out how to do that. With other NPM installed modules it was some variation of an import directive. However, this one just doesn't work. So I tried just replicating exactly what is documented in this project to check my assumptions. Which is how I came to this point.

I'll be honest, this could very well be user error. Undoubtedly further complicated by my personal lack of familiarity with the state of module/script vs require/imports in Node. But struggle as I may, I cannot figure out how to import this module into a script to run.

Very likely related to #50.

Thank you

Pull request activity type missing `(de)milestoned`

Describe the bug
Valid pull request event types include milestoned and demilestoned (like issue event types), but the schema doesn’t show them:

"pull-request-activity-type": {
"allowed-values": [
"assigned",
"unassigned",
"labeled",
"unlabeled",
"opened",
"edited",
"closed",
"reopened",
"synchronize",
"converted_to_draft",
"ready_for_review",
"locked",
"unlocked",
"review_requested",
"review_request_removed",
"auto_merge_enabled",
"auto_merge_disabled"
]
},

To Reproduce
Steps to reproduce the behavior:

  1. Try to validate your valid workflow (it runs as expected when adding or removing a milestone)
  2. see validation errors for the milestoned and demilestoned event

Expected behavior
milestoned and demilestoned are accepted as valid

Screenshots
grafik

Package/Area

  • Expressions
  • Workflow Parser
  • Language Service
  • Language Server

Package Version
v0.3.6

Additional context
The GitHub docs are also inconsistent here: The webhook docs list those event types but the workflow syntax docs don’t.

A said: It’s definitely valid. Using the event types works, part of the docs mention the event types, and clearly adding milestones to a PR is something you can do both with the API and the web UI.

Missing and raising incorrect error for `runner.debug` and `runner.environment`

Describe the bug

In runner context, documented runner.debug and runner.environment is handled as an incorrect key.

To Reproduce
Steps to reproduce the behavior:

  1. With this workflow https://github.com/kachick/wait-other-jobs/blob/9777fd46dd0c2782a09cfd067201bdb21529dbbe/.github/workflows/itself.yml#L196
  2. Open in vscode
  3. See error Context access might be invalid:

Expected behavior

  • Should be completed
  • Should not be raised validation error
  • (optional) Hover the descriptions

Screenshots
If applicable, add screenshots to help explain your problem.

image
image
image

Package/Area

  • Expressions
  • Workflow Parser
  • Language Service
  • Language Server

Package Version
v0.3.10

Additional context

Add success and failure types to workflow_run trigger

Is your feature request related to a problem? Please describe.
The completed type for the workflow_run trigger is often interpreted ambiguously, and for example, still runs after canceled action runs

Describe the solution you'd like
Adding additional types that would allow higher specificity such as "failure" or "success", would allow the action only to be triggered on successful or failed triggering actions

Additional context
I think this request would be an excellent quality-of-life feature, and I am happy to discuss this further should you have any questions about my proposal.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.