Skip to content
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
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

24 changes: 0 additions & 24 deletions .eslintrc.json

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ jobs:
uses: ./
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
yaml-file: ./__tests__/fixtures/labels.update.yml
yaml-file: ./tests/fixtures/labels.update.yml
skip-delete: true
dry-run: true
-
name: Labeler (exclude part 1)
uses: ./
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
yaml-file: ./__tests__/fixtures/labels.exclude1.yml
yaml-file: ./tests/fixtures/labels.exclude1.yml
dry-run: true
exclude: |
* d*
Expand All @@ -50,7 +50,7 @@ jobs:
uses: ./
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
yaml-file: ./__tests__/fixtures/labels.exclude2.yml
yaml-file: ./tests/fixtures/labels.exclude2.yml
dry-run: true
exclude: |
*fix
3 changes: 1 addition & 2 deletions .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"parser": "typescript"
"arrowParens": "avoid"
}
7 changes: 2 additions & 5 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ comment: false

coverage:
status:
project: # settings affecting project coverage
default:
target: auto # auto % coverage target
threshold: 5% # allow for 5% reduction of coverage without failing
patch: off
patch: false
project: false

github_checks:
annotations: false
41 changes: 25 additions & 16 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
ARG NODE_VERSION=20

FROM node:${NODE_VERSION}-alpine AS base
RUN apk add --no-cache cpio findutils git
RUN apk add --no-cache cpio findutils git rsync
WORKDIR /src
RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/src/.yarn/cache <<EOT
set -e
corepack enable
yarn --version
yarn config set --home enableTelemetry 0
Expand Down Expand Up @@ -34,32 +35,40 @@ RUN --mount=type=bind,target=.,rw <<EOT
EOT

FROM deps AS build
RUN --mount=type=bind,target=.,rw \
RUN --mount=target=/context \
--mount=type=cache,target=/src/.yarn/cache \
--mount=type=cache,target=/src/node_modules \
yarn run build && mkdir /out && cp -Rf dist /out/
--mount=type=cache,target=/src/node_modules <<EOT
set -e
rsync -a /context/. .
rm -rf dist
yarn run build
mkdir /out
cp -r dist /out
EOT

FROM scratch AS build-update
COPY --from=build /out /

FROM build AS build-validate
RUN --mount=type=bind,target=.,rw <<EOT
set -e
git add -A
cp -rf /out/* .
if [ -n "$(git status --porcelain -- dist)" ]; then
echo >&2 'ERROR: Build result differs. Please build first with "docker buildx bake build"'
git status --porcelain -- dist
exit 1
fi
RUN --mount=target=/context \
--mount=target=.,type=tmpfs <<EOT
set -e
rsync -a /context/. .
git add -A
rm -rf dist
cp -rf /out/* .
if [ -n "$(git status --porcelain -- dist)" ]; then
echo >&2 'ERROR: Build result differs. Please build first with "docker buildx bake build"'
git status --porcelain -- dist
exit 1
fi
EOT

FROM deps AS format
RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/src/.yarn/cache \
--mount=type=cache,target=/src/node_modules \
yarn run format \
&& mkdir /out && find . -name '*.ts' -not -path './node_modules/*' -not -path './.yarn/*' | cpio -pdm /out
yarn run format && mkdir /out && find . -name '*.ts' -not -path './node_modules/*' -not -path './.yarn/*' | cpio -pdm /out

FROM scratch AS format-update
COPY --from=format /out /
Expand All @@ -77,7 +86,7 @@ ARG GITHUB_REPOSITORY
RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/src/.yarn/cache \
--mount=type=cache,target=/src/node_modules \
yarn run test --coverage --coverageDirectory=/tmp/coverage
yarn run test --coverage --coverage.reportsDirectory=/tmp/coverage

FROM scratch AS test-coverage
COPY --from=test /tmp/coverage /
8 changes: 5 additions & 3 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/sourcemap-register.cjs

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dist/sourcemap-register.js

This file was deleted.

52 changes: 52 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {defineConfig} from 'eslint/config';
import js from '@eslint/js';
import tseslint from '@typescript-eslint/eslint-plugin';
import vitest from '@vitest/eslint-plugin';
import globals from 'globals';
import eslintConfigPrettier from 'eslint-config-prettier/flat';
import eslintPluginPrettier from 'eslint-plugin-prettier';

export default defineConfig([
{
ignores: ['.yarn/**/*', 'coverage/**/*', 'dist/**/*']
},
js.configs.recommended,
...tseslint.configs['flat/recommended'],
eslintConfigPrettier,
{
languageOptions: {
globals: {
...globals.node
}
}
},
{
files: ['tests/**'],
...vitest.configs.recommended,
languageOptions: {
globals: {
...globals.node,
...vitest.environments.env.globals
}
},
rules: {
...vitest.configs.recommended.rules,
'vitest/no-conditional-expect': 'error',
'vitest/no-disabled-tests': 0
}
},
{
plugins: {
prettier: eslintPluginPrettier
},
rules: {
'prettier/prettier': 'error',
'@typescript-eslint/no-require-imports': [
'error',
{
allowAsImport: true
}
]
}
}
]);
13 changes: 0 additions & 13 deletions jest.config.ts

This file was deleted.

39 changes: 18 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
{
"name": "github-labeler",
"description": "GitHub Action to manage labels on GitHub",
"type": "module",
"main": "src/main.ts",
"scripts": {
"build": "ncc build src/main.ts --source-map --minify --license licenses.txt",
"lint": "yarn run prettier && yarn run eslint",
"format": "yarn run prettier:fix && yarn run eslint:fix",
"eslint": "eslint --max-warnings=0 .",
"eslint:fix": "eslint --fix .",
"prettier": "prettier --check \"./**/*.ts\"",
"prettier:fix": "prettier --write \"./**/*.ts\"",
"test": "jest",
"lint": "eslint --max-warnings=0 .",
"format": "eslint --fix .",
"test": "vitest run",
"all": "yarn run build && yarn run format && yarn test"
},
"repository": {
Expand All @@ -32,20 +29,20 @@
"matcher": "^3.0.0"
},
"devDependencies": {
"@eslint/js": "^9.39.3",
"@types/js-yaml": "^4.0.9",
"@types/node": "^20.6.0",
"@typescript-eslint/eslint-plugin": "^6.6.0",
"@typescript-eslint/parser": "^6.6.0",
"@vercel/ncc": "^0.38.0",
"dotenv": "^16.3.1",
"eslint": "^8.49.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-jest": "^27.2.3",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.6.4",
"prettier": "^3.0.3",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
"@types/node": "^20.19.35",
"@typescript-eslint/eslint-plugin": "^8.56.1",
"@typescript-eslint/parser": "^8.56.1",
"@vercel/ncc": "^0.38.4",
"@vitest/coverage-v8": "^4.0.18",
"@vitest/eslint-plugin": "^1.6.9",
"eslint": "^9.39.3",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.5",
"globals": "^17.3.0",
"prettier": "^3.8.1",
"typescript": "^5.9.3",
"vitest": "^4.0.18"
}
}
3 changes: 2 additions & 1 deletion src/labeler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import matcher from 'matcher';
import * as yaml from 'js-yaml';
import * as github from '@actions/github';
import * as core from '@actions/core';
import {Inputs} from './context';

import {Inputs} from './context.js';

export type Label = {
name: string;
Expand Down
5 changes: 3 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as fs from 'fs';
import * as core from '@actions/core';
import {getInputs, Inputs} from './context';
import {Labeler} from './labeler';

import {getInputs, Inputs} from './context.js';
import {Labeler} from './labeler.js';

async function run() {
try {
Expand Down
5 changes: 3 additions & 2 deletions __tests__/context.test.ts → tests/context.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {describe, expect, it} from '@jest/globals';
import * as context from '../src/context';
import {describe, expect, it} from 'vitest';

import * as context from '../src/context.js';

describe('getInputList', () => {
it('handles single line correctly', async () => {
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions __tests__/labeler.test.ts → tests/labeler.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {describe, expect, jest, test} from '@jest/globals';
import {describe, expect, test, vi} from 'vitest';
import * as fs from 'fs';
import * as path from 'path';

import {Inputs} from '../src/context';
import {Label, Labeler, LabelStatus} from '../src/labeler';
import {Inputs} from '../src/context.js';
import {Label, Labeler, LabelStatus} from '../src/labeler.js';

const fixturesDir = path.join(__dirname, 'fixtures');

// eslint-disable-next-line @typescript-eslint/no-explicit-any
jest.spyOn(Labeler.prototype as any, 'getRepoLabels').mockImplementation((): Promise<Label[]> => {
vi.spyOn(Labeler.prototype as any, 'getRepoLabels').mockImplementation((): Promise<Label[]> => {
return <Promise<Label[]>>JSON.parse(fs.readFileSync(path.join(fixturesDir, 'repoLabels.json'), 'utf-8'));
});

Expand Down
12 changes: 4 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
{
"compilerOptions": {
"module": "nodenext",
"moduleResolution": "nodenext",
"esModuleInterop": true,
"target": "es6",
"module": "commonjs",
"newLine": "lf",
"outDir": "./lib",
"rootDir": "./src",
"forceConsistentCasingInFileNames": true,
"noImplicitAny": false,
"resolveJsonModule": true,
"useUnknownInCatchVariables": false,
"useUnknownInCatchVariables": false
},
"exclude": [
"node_modules",
"**/*.test.ts",
"jest.config.ts"
]
"include": ["src/**/*.ts"]
}
16 changes: 16 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {defineConfig} from 'vitest/config';

export default defineConfig({
test: {
environment: 'node',
setupFiles: ['./vitest.setup.ts'],
include: ['tests/**/*.test.ts'],
coverage: {
provider: 'v8',
reporter: ['text', 'clover', 'lcov'],
reportsDirectory: 'coverage',
include: ['src/**/*.ts'],
exclude: ['src/main.ts']
}
}
});
11 changes: 11 additions & 0 deletions vitest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as path from 'node:path';

const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ghaction-github-labeler-'));

process.env = Object.assign({}, process.env, {
TEMP: tmpDir,
RUNNER_TEMP: path.join(tmpDir, 'runner-temp'),
RUNNER_TOOL_CACHE: path.join(tmpDir, 'runner-tool-cache')
});
Loading
Loading