Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1 Rewrite #34

Merged
merged 10 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .actrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# The micro image does not have git, so we need the medium image
-P ubuntu-latest=catthehacker/ubuntu:act-latest
56 changes: 56 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Test
on: [pull_request]

jobs:

balto-eslint-v9:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
- run: "npm ci"
working-directory: "test/v9"
- uses: ./
with:
working-directory: "test/v9"

balto-eslint-v8:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
- run: "npm ci"
working-directory: "test/v8"
- uses: ./
with:
working-directory: "test/v8"

balto-eslint-v7:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
- run: "npm ci"
working-directory: "test/v7"
- uses: ./
with:
working-directory: "test/v7"

balto-eslint-v6:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
- run: "npm ci"
working-directory: "test/v6"
- uses: ./
with:
working-directory: "test/v6"
1 change: 0 additions & 1 deletion .tool-versions

This file was deleted.

10 changes: 0 additions & 10 deletions CONTRIBUTING.md

This file was deleted.

55 changes: 18 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@

Balto is Smart and Fast:

* Installs _your_ versions of eslint and eslint plugins (optionally)
* _Only_ runs on files that have changed
* _Only_ annotates lines that have changed

## Requirements

* Default configuration of `dependencyInstallMode` requires `yarn` to be used
* If you use npm you will need to set `dependencyInstallMode` to `'none'` and
handle the install yourself.

## Sample config

(place in `.github/workflows/balto.yml`):
Expand All @@ -22,49 +15,37 @@ name: Balto
on: [pull_request]

jobs:
lint:
# Note: the name of this job will be how annotations are labeled
balto-eslint:
runs-on: ubuntu-latest
permissions: # may not be necessary, see note below
contents: read
checks: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

# Optional but may be helpful depending on the ESLint plugins your project uses
- uses: actions/cache@v2
with:
path: ~/.npm
# Change to package-lock.json if using npm in your own project
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-

- uses: planningcenter/balto-eslint@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
extensions: "js,jsx"
# Alternatively, use planningcenter/balto-utils/npm@v2
- uses: planningcenter/balto-utils/yarn@v2
- uses: planningcenter/balto-eslint@v1
```

## Inputs

| Name | Description | Required | Default |
|:-:|:-:|:-:|:-:|
| `conclusionLevel` | Which check run conclusion type to use when annotations are created (`"neutral"` or `"failure"` are most common). See [GitHub Checks documentation](https://developer.github.com/v3/checks/runs/#parameters) for all available options. | no | `"neutral"` |
| `failureLevel` | The lowest annotation level to fail on | no | `"error"` |
| `extensions` | A comma separated list of extensions to run ESLint on | no | `"js"` |
| `dependencyInstallMode` | `"smart"` or `"none"`. Control how dependencies are installed (if at all). Smart (requires yarn) will attempt to install the least amount of packages to successfully run eslint.| no | `"smart"` |
| `failure-level` | The lowest annotation level to fail on ("warning or "error"") | no | `"error"` |
| `conclusion-level` | Action conclusion ("success" or "failure") if annotations of the failure-level were created. | no | `"success"` |
| `working-directory` | Which directory to run the action in | no | `"."` |

## Outputs

| Name | Description |
|:-:|:-:|
| `issuesCount` | Number of ESLint violations found |
| `warning-count` | Number of ESLint warnings found |
| `error-count` | Number of ESLint errors found |
| `total-count` | Number of ESLint errors and warnings found |

## A note about permissions
## Contributing

Because some tools, like [dependabot](https://github.com/dependabot), use tokens for actions that have read-only permissions, you'll need to elevate its permissions for this action to work with those sorts of tools. If you don't use any of those tools, and your workflow will only run when users with permissions in your repo create and update pull requests, you may not need these explicit permissions at all.
1. Install [devbox](https://www.jetify.com/devbox/)
2. `devbox setup`
3. `devbox test`

When defining any permissions in a workflow or job, you need to explicitly include any permission the action needs. In the sample config above, we explicitly give `write` permissons to the [checks API](https://docs.github.com/en/rest/checks/runs) for the job that includes balto-eslint as a step. Because balto-eslint uses [check runs](https://docs.github.com/en/rest/guides/getting-started-with-the-checks-api), the `GITHUB_TOKEN` used in an action must have permissions to create a `check run`. You'll also need `contents: read` for `actions/checkout` to be able to clone the code.
This will simulate a balto workflow like the above sample config that you can
inspect for accuracy. At time of writing, there are not automated tests (PRs
welcome!).
30 changes: 14 additions & 16 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,22 @@ branding:
icon: life-buoy
color: orange
inputs:
extensions:
description: "A comma separated list of extensions to run on"
required: false
default: "js"
conclusionLevel:
description: 'Which check run conclusion type to use when annotations are created ("neutral" or "failure" are most common)'
required: false
default: "neutral"
failureLevel:
failure-level:
description: 'The lowest annotation level to fail on ("warning" or "error")'
required: false
default: "error"
dependencyInstallMode:
description: "'smart' or 'none'. Control how dependencies are installed (if
at all). Smart (requires yarn) will attempt to install the least amount of
packages to successfully run eslint."
conclusion-level:
description: 'Action conclusion ("success" or "failure") if annotations of the failure-level were created'
required: false
default: "success"
working-directory:
description: Which directory to run the action in
required: false
default: 'smart'
default: "."
outputs:
issuesCount:
description: "Number of eslint violations found"
warning-count:
description: "Number of relevant warnings found"
error-count:
description: "Number of relevant errors found"
total-count:
description: "Number of relevant warnings and errors"
38 changes: 38 additions & 0 deletions devbox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.12.0/.schema/devbox.schema.json",
"packages": [
"nodejs@20",
"ruby@latest",
"act@latest"
],
"env": {"DEVBOX_COREPACK_ENABLED": "true"},
"shell": {
"scripts": {
"setup": [
"gem install rerun",
"npm ci"
],
"test": "npm run test",
"dev": "npm run dev",
"rebuildtests": [
"git diff --quiet || { echo 'Working tree is not clean, exiting.'; exit 1; }",
"cd test/v6 && rm existing.js new.js some_file_that_eslint_should_ignore && cd ../..",
"cd test/v7 && rm existing.js new.js some_file_that_eslint_should_ignore && cd ../..",
"cd test/v8 && rm existing.js new.js some_file_that_eslint_should_ignore && cd ../..",
"cd test/v9 && rm existing.js new.js some_file_that_eslint_should_ignore && cd ../..",
"cp test/snapshots/base/* test/v6",
"cp test/snapshots/base/* test/v7",
"cp test/snapshots/base/* test/v8",
"cp test/snapshots/base/* test/v9",
"git add . && git commit -m 'Undo simulated changes'",
"echo \"{ \\\"pull_request\\\": { \\\"base\\\": { \\\"sha\\\": \\\"$(git rev-parse HEAD)\\\" } } }\" > test/pull_request_event_payload.json",
"git add . && git commit -m 'Update test target sha'",
"cp test/snapshots/updates/* test/v6",
"cp test/snapshots/updates/* test/v7",
"cp test/snapshots/updates/* test/v8",
"cp test/snapshots/updates/* test/v9",
"git add . && git commit -m 'Simulate changes'"
]
}
}
}
Loading