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

merge back #2

Open
wants to merge 37 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
605cc0a
Bump tmpl from 1.0.4 to 1.0.5
dependabot[bot] Sep 21, 2021
7d58108
Bump path-parse from 1.0.6 to 1.0.7
dependabot[bot] Aug 11, 2021
542dd7a
Bump glob-parent from 5.1.1 to 5.1.2
dependabot[bot] Jun 10, 2021
02ae4f4
Update node12 to node16
adriaandotcom Jan 14, 2023
5eeae7f
Bump ajv from 6.12.0 to 6.12.6
dependabot[bot] Feb 12, 2022
507359b
Bump minimist from 1.2.5 to 1.2.6
dependabot[bot] Mar 25, 2022
1e9b4bf
Bump node-fetch from 2.6.1 to 2.6.7
dependabot[bot] Jun 25, 2022
98cb255
Bump decode-uri-component from 0.2.0 to 0.2.2
dependabot[bot] Dec 4, 2022
270e75a
Bump json5 from 1.0.1 to 1.0.2
dependabot[bot] Jan 5, 2023
79b11c8
Bump @actions/core from 1.2.6 to 1.9.1
dependabot[bot] Aug 18, 2022
8b292d2
set node version in CI
a-b-r-o-w-n Mar 2, 2023
64b1433
tweak ci rules
a-b-r-o-w-n Mar 2, 2023
cf50003
Bump jsdom from 16.4.0 to 16.7.0
dependabot[bot] Mar 2, 2023
a5b325f
Bump ansi-regex from 4.1.0 to 4.1.1
dependabot[bot] Mar 2, 2023
a157321
Bump minimatch from 3.0.4 to 3.1.2
dependabot[bot] Mar 2, 2023
22881bb
Bump semver-regex from 2.0.0 to 3.1.4
dependabot[bot] Mar 2, 2023
ac3e7cd
Bump debug from 4.1.1 to 4.3.4
dependabot[bot] Oct 2, 2023
4793e2c
Bump word-wrap from 1.2.3 to 1.2.4
dependabot[bot] Jul 18, 2023
627633d
Bump semver from 5.7.1 to 5.7.2
dependabot[bot] Jul 12, 2023
14d987d
Bump tough-cookie from 4.1.2 to 4.1.3
dependabot[bot] Jul 10, 2023
34fbd10
update vscode settings
a-b-r-o-w-n Jun 1, 2024
c753d58
add node-version
a-b-r-o-w-n Jun 1, 2024
846da5e
update lockfile version
a-b-r-o-w-n Jun 1, 2024
fd80e8b
update depdendencies
a-b-r-o-w-n Jun 1, 2024
6bf770b
set up husky v9
a-b-r-o-w-n Jun 1, 2024
f93dd4e
change pre-commit to lint
a-b-r-o-w-n Jun 1, 2024
a0e1d8b
fix typescript error
a-b-r-o-w-n Jun 2, 2024
6c37997
add node-fetch
a-b-r-o-w-n Jun 2, 2024
1c0d0d2
pass fetch to Octokit constructor
a-b-r-o-w-n Jun 2, 2024
e228a69
run workflow on PR update
a-b-r-o-w-n Jun 2, 2024
15d517b
test workflow commands
a-b-r-o-w-n Jun 2, 2024
04b96ac
debug message
a-b-r-o-w-n Jun 2, 2024
c123b68
do not create check
a-b-r-o-w-n Jun 2, 2024
8d35d37
update col to startColumn
a-b-r-o-w-n Jun 2, 2024
a82d66e
only output columns if on same line
a-b-r-o-w-n Jun 2, 2024
cc31b55
refactor process results
a-b-r-o-w-n Jun 2, 2024
dd6a841
migrate to pnpm (#50)
a-b-r-o-w-n Jun 2, 2024
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
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module.exports = {
"plugin:prettier/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"prettier/@typescript-eslint",
],
plugins: ["import"],
env: {
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/PR.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Unit Tests

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: pnpm/action-setup@v4
with:
version: 9.1.4
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Checkout
uses: actions/checkout@v4
- name: Get pnpm store directory
id: pnpm-store-path
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: Cache
uses: actions/cache@v4
with:
path: |
${{ steps.pnpm-store-path.outputs.STORE_PATH }}
**/node_modules
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-
- name: Install Dependencies
run: pnpm install
shell: bash
- name: Lint
uses: ./
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
files: "src/**/*"
- name: Test
run: npm test -- --coverage
- name: Build
run: npm run build
- name: Coveralls
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
33 changes: 0 additions & 33 deletions .github/workflows/main.yml

This file was deleted.

1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm exec pretty-quick --staged
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v22.2.0
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
"typescript.tsdk": "node_modules/typescript/lib",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"cSpell.words": ["octocat", "octokit", "repos"]
}
117 changes: 89 additions & 28 deletions __tests__/processResults.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { error, warning, startGroup, endGroup } from "@actions/core";

import inputs from "../src/inputs";
import { CHECK_NAME, processResults } from "../src/processResults";
import { processResults } from "../src/processResults";

jest.mock("@actions/core", () => ({
debug: jest.fn(),
Expand All @@ -16,71 +18,130 @@ jest.mock("../src/inputs", () => ({

const errorMsg = {
line: 10,
endLine: 10,
column: 1,
endColumn: 10,
severity: 2,
ruleId: "no-var",
message: "no var allowed",
};

const warnMsg = {
line: 5,
endLine: 5,
column: 1,
endColumn: 10,
severity: 1,
ruleId: "no-console",
message: "no console allowed",
};

const multilineMsg = {
line: 5,
endLine: 10,
column: 1,
endColumn: 10,
severity: 2,
ruleId: "no-multiline",
message: "no multiline allowed",
};

const invalidMsg = {
line: 1,
severity: 2,
column: 1,
endColumn: 10,
ruleId: undefined,
message: "bad rule",
};

const mockResults = [
{
filePath: "/foo",
messages: [errorMsg, warnMsg, { ...errorMsg, line: 20 }],
messages: [errorMsg, warnMsg, { ...errorMsg, line: 20, endLine: 20 }],
},
{
filePath: "/bar",
messages: [errorMsg, invalidMsg],
messages: [errorMsg, invalidMsg, multilineMsg],
},
];

it("returns check endpoint payload with correct annotations", () => {
it("returns correct error count and warning count", () => {
// @ts-expect-error
const payload = processResults(mockResults);

expect(payload).toMatchObject({
conclusion: "failure",
output: {
title: CHECK_NAME,
summary: "3 error(s) found",
annotations: expect.any(Array),
},
});
const result = processResults(mockResults);

const annotations = payload.output?.annotations;
expect(annotations).toHaveLength(4);
expect(result).toMatchObject({
errorCount: 4,
warningCount: 1,
});
});

it("passes the check if there are no errors", () => {
const payload = processResults([
{
filePath: "/bar",
// @ts-expect-error
messages: [warnMsg, invalidMsg],
},
]);
it("logs each lint result with file annotations", () => {
// @ts-expect-error
processResults(mockResults);

expect(error).toHaveBeenCalledTimes(4);
expect(warning).toHaveBeenCalledTimes(1);

expect(error).toHaveBeenNthCalledWith(1, "[no-var] no var allowed", {
file: "/foo",
startLine: 10,
endLine: 10,
startColumn: 1,
endColumn: 10,
});

expect(warning).toHaveBeenNthCalledWith(1, "[no-console] no console allowed", {
file: "/foo",
startLine: 5,
endLine: 5,
startColumn: 1,
endColumn: 10,
});

expect(error).toHaveBeenNthCalledWith(2, "[no-var] no var allowed", {
file: "/foo",
startLine: 20,
endLine: 20,
startColumn: 1,
endColumn: 10,
});

expect(payload.conclusion).toEqual("success");
expect(error).toHaveBeenNthCalledWith(3, "[no-var] no var allowed", {
file: "/bar",
startLine: 10,
endLine: 10,
startColumn: 1,
endColumn: 10,
});

expect(error).toHaveBeenNthCalledWith(4, "[no-multiline] no multiline allowed", {
file: "/bar",
startLine: 5,
endLine: 10,
});
});

it("does not include warnings if quiet option is true", () => {
Object.defineProperty(inputs, "quiet", {
get: () => true,
});
// @ts-expect-error
const payload = processResults(mockResults);
expect(payload.output?.annotations).toHaveLength(3);
expect(payload.output?.annotations?.some((a) => a.annotation_level === "warning")).toBe(false);
const result = processResults(mockResults);
expect(result).toMatchObject({
errorCount: 4,
warningCount: 0,
});
expect(warning).not.toHaveBeenCalledWith("[no-console] no console allowed", expect.any(Object));
});

it("groups log output by file", () => {
// @ts-expect-error
processResults(mockResults);

expect(startGroup).toHaveBeenCalledTimes(2);
expect(endGroup).toHaveBeenCalledTimes(2);

expect(startGroup).toHaveBeenNthCalledWith(1, "/foo");
expect(startGroup).toHaveBeenNthCalledWith(2, "/bar");
});
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ inputs:
default: "false"
required: false
runs:
using: "node12"
using: "node16"
main: "lib/index.js"
branding:
icon: "check-circle"
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ module.exports = {
preset: "ts-jest",
testPathIgnorePatterns: ["/node_modules/", "<rootDir>/__tests__/fixtures"],
collectCoverageFrom: ["src/**/*.ts"],
resetMocks: true,
};
Loading