Skip to content

Commit 673aed1

Browse files
Merge pull request #116 from waigel/master
Improve documentation and add ESLINT_PRIVATE_KEY_BASE64 variable
2 parents 09f00cd + e623f43 commit 673aed1

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

readme.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Then just use the formatter and it will report errors and warnings on PRs!
3131
eslint --format github file.js
3232
```
3333

34-
## Using you own GitHub App
34+
## Using you own GitHub App (recommended)
3535

3636
You might not want to use our github app for the formatter.
3737

@@ -52,6 +52,11 @@ Go to [this page](https://github.com/settings/apps) to create a new GitHub app.
5252

5353
Then hit `Save Changes` and you're all done setting up your GitHub app.
5454

55+
You need to configure Permissions for your GitHub app. You need to set the following permissions:
56+
57+
- `Checks` - `Read & Write`
58+
- `Metadata` - `Read-only`
59+
5560
### 2. Set `ESLINT_APP_ID` environment variable
5661

5762
Your GitHub application's ID. This can be found at the top of your GitHub app's edit page.
@@ -62,10 +67,43 @@ The private RSA key for your application. The prompt to generate the RSA key is
6267

6368
Once you have generated a key, open the file that is downloaded and copy to text into the `PRIVATE_KEY` environment variable.
6469

70+
When using GitHub Actions, you can use the environment variable `ESLINT_PRIVATE_KEY_BASE64` to set the private key base64 encoded.
71+
This fix the issue with the new line characters in the private key.
72+
73+
To encode the private key, you can use the following command:
74+
75+
```sh
76+
cat private-key.pem | base64
77+
```
78+
6579
### 4. Set `GH_API` (enterprise only)
6680

6781
To get this package to work on github enterprise instances you will need to set the `GH_API` environment variable to a url pointing towards your enterprise GitHub's API.
6882

6983
### 5. (optional) Set `GH_CHECK_NAME`
7084

71-
If the default check name conflicts with something, you can override it by passing `GH_CHECK_NAME` environment variable.
85+
If the default check name conflicts with something, you can override it by passing `GH_CHECK_NAME` environment variable.
86+
87+
### Example for GitHub Actions
88+
89+
> **Warning**
90+
> It is strongly recommended to create your own GitHub app and never share your private key with third parties.
91+
> Otherwise, unauthorized persons can read meta data and manipulate checks.
92+
93+
```yaml
94+
name: Lint
95+
on: [pull_request]
96+
jobs:
97+
lint:
98+
runs-on: ubuntu-latest
99+
steps:
100+
- uses: actions/checkout@v3
101+
- uses: actions/setup-node@v3
102+
with:
103+
node-version: 18
104+
- run: npm install
105+
- run: eslint src --ext .ts,.js --format github
106+
env:
107+
ESLINT_APP_ID: ${{ secrets.ESLINT_APP_ID }}
108+
ESLINT_PRIVATE_KEY_BASE64: ${{ secrets.ESLINT_PRIVATE_KEY_BASE64 }}
109+
```

src/create-check.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ export default async (results: eslint.CLIEngine.LintResult[]) => {
9797
warningCount += result.warningCount;
9898
});
9999

100+
let privateKey = process.env.ESLINT_PRIVATE_KEY || PRIVATE_KEY;
101+
if (process.env.ESLINT_PRIVATE_KEY_BASE64) {
102+
privateKey = Buffer.from(
103+
process.env.ESLINT_PRIVATE_KEY_BASE64,
104+
'base64'
105+
).toString();
106+
}
107+
100108
return createCheck({
101109
tool: 'ESLint',
102110
name: process.env.GH_CHECK_NAME || 'Check Code for Errors',
@@ -106,6 +114,6 @@ export default async (results: eslint.CLIEngine.LintResult[]) => {
106114
appId: process.env.ESLINT_APP_ID
107115
? Number(process.env.ESLINT_APP_ID)
108116
: APP_ID,
109-
privateKey: process.env.ESLINT_PRIVATE_KEY || PRIVATE_KEY
117+
privateKey
110118
});
111119
};

0 commit comments

Comments
 (0)