Giter VIP home page Giter VIP logo

eslint-plugin-actions's Introduction

eslint-plugin-actions

npm CI semantic-release

Lint JS inside GitHub Actions workflow

A JS script in a GitHub workflow editor has red squiggly underlines. A tooltip explains the problem.

Installation

You'll first need to install ESLint 8 or greater:

$ npm i eslint --save-dev
$ yarn add -D eslint

Next, install eslint-plugin-actions:

$ npm install eslint-plugin-actions --save-dev
$ yarn add -D eslint-plugin-actions

Usage

Extending the plugin:actions/recommended config will enable the processor on all workflow .{yml,yaml} files:

{
    "extends": ["plugin:actions/recommended"]
}

Currently, only literal blocks (|) are supported and it's recommended to use them:

# .github/workflows/ci.yml
jobs:
  build:
    steps:
    - uses: actions/github-script@v2
      with:
        script: |
          // .github/workflows/ci.yml/0_build/0.js

The autofixing (--fix) is supported, but it's still experimental and whitespace handling of YAML is different from JS, so be sure to check the result.

Advanced Configuration

Dotfiles are ignored by ESLint by default. To lint files inside .github, you'll need to add !.github to .eslintignore file or ignorePatterns of your configuration file:

!/.github

Then, add actions to the plugins section of your configuration file. You can omit the eslint-plugin- prefix:

{
    "plugins": ["actions"]
}

Use the processor option in an overrides entry to enable the plugin on workflow YAML files:

{
    "overrides": [{
        "files": [".github/workflows/*.{yml,yaml}"],
        "processor": "actions/actions"
    }]
}

Each script inside a workflow has a virtual filename appended to the YAML file's path. It has the format of [global index]_[job id]/[local index].js (see the example above). overrides glob patterns for these virtual filenames can customize configuration for scripts without affecting regular code. For more information on configuring processors, refer to the ESLint documentation:

{
    "overrides": [{
        "files": [".github/workflows/*.{yml,yaml}/*_build/*.js"],
        "rules": {
            "indent": ["error", 2, {"outerIIFEBody": 0}]
            ...
        },
        ...
    }]
}

Rules

The script will be enclosed in an IIFE async function, when processed by ESLint:

(async function(context, github, io, core) {
...
}());

Therefore, if indent or indent-legacy rule is used, the outerIIFEBody option should be set to 0 (see above). Furthermore, rules affecting the beginning and the end of the file, such as unicode-bom, eol-last and no-multiple-empty-lines, are ignored.

Supported Actions

Remark

This plugin is heavily inspired by and adapted from eslint-plugin-markdown.

License

MIT License

eslint-plugin-actions's People

Contributors

dependabot[bot] avatar renovate[bot] avatar ylemkimon avatar

Stargazers

 avatar

Watchers

 avatar  avatar

eslint-plugin-actions's Issues

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two Factor Authentication for your account, set its level to "Authorization only" in your account settings. semantic-release cannot publish with the default "
Authorization and writes" level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Support expressions in scripts

If I use expressions such as ${{ github.event.workflow_run.id }} within a actions/github-script script, this currently leads to a parse error.

I can work around this by using env vars & adding them as globals in my ESLint config, but I was wondering whether there is a better way to support such expressions.

Add type check

https://github.com/actions/github-script/blob/fc4d6279013dd0c4f4db0c7c21ff1a1c46e5c8ea/src/async-function.ts#L1-L14:

import * as core from '@actions/core'
import {Context} from '@actions/github/lib/context'
import {GitHub} from '@actions/github/lib/utils'
import * as io from '@actions/io'

const AsyncFunction = Object.getPrototypeOf(async () => null).constructor

type AsyncFunctionArguments = {
  context: Context
  core: typeof core
  github: InstanceType<typeof GitHub>
  io: typeof io
  require: NodeRequire
}

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.