mirror of
https://github.com/dorny/paths-filter.git
synced 2024-11-12 08:38:35 +00:00
Compare commits
No commits in common. "298e00d16954592b06fe237dbf749947c3dd4a98" and "b671dc324f171009fe791ef5ec259dfea2ae3d26" have entirely different histories.
298e00d169
...
b671dc324f
3
.eslintignore
Normal file
3
.eslintignore
Normal file
@ -0,0 +1,3 @@
|
||||
dist/
|
||||
lib/
|
||||
node_modules/
|
53
.eslintrc.json
Normal file
53
.eslintrc.json
Normal file
@ -0,0 +1,53 @@
|
||||
{
|
||||
"plugins": ["jest", "@typescript-eslint"],
|
||||
"extends": ["plugin:github/internal"],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 9,
|
||||
"sourceType": "module",
|
||||
"project": "./tsconfig.json"
|
||||
},
|
||||
"rules": {
|
||||
"eslint-comments/no-use": "off",
|
||||
"import/no-namespace": "off",
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": "error",
|
||||
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
|
||||
"@typescript-eslint/no-require-imports": "error",
|
||||
"@typescript-eslint/array-type": "error",
|
||||
"@typescript-eslint/await-thenable": "error",
|
||||
"camelcase": "off",
|
||||
"@typescript-eslint/camelcase": "off",
|
||||
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
|
||||
"@typescript-eslint/func-call-spacing": ["error", "never"],
|
||||
"@typescript-eslint/no-array-constructor": "error",
|
||||
"@typescript-eslint/no-empty-interface": "error",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"@typescript-eslint/no-extraneous-class": "error",
|
||||
"@typescript-eslint/no-for-in-array": "error",
|
||||
"@typescript-eslint/no-inferrable-types": "error",
|
||||
"@typescript-eslint/no-misused-new": "error",
|
||||
"@typescript-eslint/no-namespace": "error",
|
||||
"@typescript-eslint/no-non-null-assertion": "warn",
|
||||
"@typescript-eslint/no-unnecessary-qualifier": "error",
|
||||
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
||||
"@typescript-eslint/no-useless-constructor": "error",
|
||||
"@typescript-eslint/no-var-requires": "error",
|
||||
"@typescript-eslint/prefer-for-of": "warn",
|
||||
"@typescript-eslint/prefer-function-type": "warn",
|
||||
"@typescript-eslint/prefer-includes": "error",
|
||||
"@typescript-eslint/prefer-string-starts-ends-with": "error",
|
||||
"@typescript-eslint/promise-function-async": ["error", { "allowAny": true }],
|
||||
"@typescript-eslint/require-array-sort-compare": "error",
|
||||
"@typescript-eslint/restrict-plus-operands": "error",
|
||||
"semi": "off",
|
||||
"@typescript-eslint/semi": ["error", "never"],
|
||||
"@typescript-eslint/type-annotation-spacing": "error",
|
||||
"@typescript-eslint/unbound-method": "error"
|
||||
},
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true,
|
||||
"jest/globals": true
|
||||
}
|
||||
}
|
4
.gitattributes
vendored
4
.gitattributes
vendored
@ -1,3 +1 @@
|
||||
* text=auto eol=lf
|
||||
|
||||
dist/** -diff linguist-generated=true
|
||||
* text=auto eol=lf
|
12
.github/workflows/build.yml
vendored
12
.github/workflows/build.yml
vendored
@ -5,23 +5,19 @@ on:
|
||||
branches:
|
||||
- master
|
||||
|
||||
env:
|
||||
VOLTA_FEATURE_PNPM: 1
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: volta-cli/action@v4
|
||||
- uses: actions/checkout@v3
|
||||
- run: |
|
||||
pnpm install
|
||||
pnpm run all
|
||||
npm install
|
||||
npm run all
|
||||
|
||||
self-test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v3
|
||||
- uses: ./
|
||||
id: filter
|
||||
with:
|
||||
|
30
.github/workflows/pull-request-verification.yml
vendored
30
.github/workflows/pull-request-verification.yml
vendored
@ -6,35 +6,21 @@ on:
|
||||
- master
|
||||
- '**'
|
||||
|
||||
env:
|
||||
VOLTA_FEATURE_PNPM: 1
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # Need history for changelog generation
|
||||
- uses: volta-cli/action@v4
|
||||
- uses: actions/checkout@v3
|
||||
- run: |
|
||||
pnpm i
|
||||
pnpm run all
|
||||
# We need to make sure the checked-in `index.mjs` actually matches what we expect it to be.
|
||||
- name: Compare the expected and actual dist/ directories
|
||||
run: |
|
||||
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
|
||||
echo "Detected uncommitted changes after build. See status below:"
|
||||
git diff
|
||||
exit 1
|
||||
fi
|
||||
npm install
|
||||
npm run all
|
||||
|
||||
test-inline:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
pull-requests: read
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v3
|
||||
- uses: ./
|
||||
id: filter
|
||||
with:
|
||||
@ -55,7 +41,7 @@ jobs:
|
||||
permissions:
|
||||
pull-requests: read
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v3
|
||||
- uses: ./
|
||||
id: filter
|
||||
with:
|
||||
@ -67,7 +53,7 @@ jobs:
|
||||
test-without-token:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v3
|
||||
- uses: ./
|
||||
id: filter
|
||||
with:
|
||||
@ -80,7 +66,7 @@ jobs:
|
||||
test-wd-without-token:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
path: somewhere
|
||||
- uses: ./somewhere
|
||||
@ -96,7 +82,7 @@ jobs:
|
||||
test-local-changes:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v3
|
||||
- run: echo "NEW FILE" > local
|
||||
- run: git add local
|
||||
- uses: ./
|
||||
|
@ -1,10 +1,11 @@
|
||||
{
|
||||
"printWidth": 120,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": false,
|
||||
"arrowParens": "avoid"
|
||||
}
|
||||
"printWidth": 120,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": false,
|
||||
"arrowParens": "avoid",
|
||||
"parser": "typescript"
|
||||
}
|
35
.vscode/launch.json
vendored
Normal file
35
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Jest All",
|
||||
"program": "${workspaceFolder}/node_modules/.bin/jest",
|
||||
"args": ["--runInBand"],
|
||||
"console": "integratedTerminal",
|
||||
"internalConsoleOptions": "neverOpen",
|
||||
"disableOptimisticBPs": true,
|
||||
"windows": {
|
||||
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Jest Current File",
|
||||
"program": "${workspaceFolder}/node_modules/.bin/jest",
|
||||
"args": [
|
||||
"${fileBasenameNoExtension}",
|
||||
"--config",
|
||||
"jest.config.js"
|
||||
],
|
||||
"console": "integratedTerminal",
|
||||
"internalConsoleOptions": "neverOpen",
|
||||
"disableOptimisticBPs": true,
|
||||
"windows": {
|
||||
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -1,6 +1,4 @@
|
||||
import {describe, expect, test} from 'vitest'
|
||||
|
||||
import {csvEscape} from '../src/list-format/csv-escape.ts'
|
||||
import {csvEscape} from '../src/list-format/csv-escape'
|
||||
|
||||
describe('csvEscape() backslash escapes every character except subset of definitely safe characters', () => {
|
||||
test('simple filename should not be modified', () => {
|
||||
|
@ -1,7 +1,5 @@
|
||||
import {describe, expect, test} from 'vitest'
|
||||
|
||||
import {File, ChangeStatus} from '../src/file.ts'
|
||||
import {Filter} from '../src/filter.ts'
|
||||
import {Filter} from '../src/filter'
|
||||
import {File, ChangeStatus} from '../src/file'
|
||||
|
||||
describe('yaml filter parsing tests', () => {
|
||||
test('throws if yaml is not a dictionary', () => {
|
||||
@ -26,7 +24,7 @@ describe('matching tests', () => {
|
||||
const yaml = `
|
||||
src: "src/**/*.js"
|
||||
`
|
||||
const filter = new Filter(yaml)
|
||||
let filter = new Filter(yaml)
|
||||
const files = modified(['src/app/module/file.js'])
|
||||
const match = filter.match(files)
|
||||
expect(match.src).toEqual(files)
|
||||
|
@ -1,10 +1,8 @@
|
||||
import {describe, expect, test} from 'vitest'
|
||||
|
||||
import {ChangeStatus} from '../src/file.ts'
|
||||
import * as git from '../src/git.ts'
|
||||
import * as git from '../src/git'
|
||||
import {ChangeStatus} from '../src/file'
|
||||
|
||||
describe('parsing output of the git diff command', () => {
|
||||
test('parseGitDiffOutput returns files with correct change status', () => {
|
||||
test('parseGitDiffOutput returns files with correct change status', async () => {
|
||||
const files = git.parseGitDiffOutput(
|
||||
'A\u0000LICENSE\u0000' + 'M\u0000src/index.ts\u0000' + 'D\u0000src/main.ts\u0000'
|
||||
)
|
||||
|
@ -1,6 +1,4 @@
|
||||
import {describe, expect, test} from 'vitest'
|
||||
|
||||
import {backslashEscape, shellEscape} from '../src/list-format/shell-escape.ts'
|
||||
import {backslashEscape, shellEscape} from '../src/list-format/shell-escape'
|
||||
|
||||
describe('escape() backslash escapes every character except subset of definitely safe characters', () => {
|
||||
test('simple filename should not be modified', () => {
|
||||
|
@ -49,7 +49,7 @@ outputs:
|
||||
description: JSON array with names of all filters matching any of changed files
|
||||
runs:
|
||||
using: 'node20'
|
||||
main: 'dist/index.mjs'
|
||||
main: 'dist/index.js'
|
||||
branding:
|
||||
color: blue
|
||||
icon: filter
|
||||
|
21
dist/index.js
vendored
Normal file
21
dist/index.js
vendored
Normal file
File diff suppressed because one or more lines are too long
29740
dist/index.mjs
vendored
29740
dist/index.mjs
vendored
File diff suppressed because one or more lines are too long
@ -1,41 +0,0 @@
|
||||
import chalk from "chalk";
|
||||
import { analyzeMetafile, build } from "esbuild";
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const startTime = Date.now();
|
||||
console.info(
|
||||
chalk.bold(`🚀 ${chalk.blueBright("paths-filter")} Build\n`),
|
||||
);
|
||||
|
||||
const result = await build({
|
||||
entryPoints: ["./src/main.ts"],
|
||||
outfile: "dist/index.mjs",
|
||||
metafile: true,
|
||||
bundle: true,
|
||||
format: "esm",
|
||||
platform: "node",
|
||||
target: ["node20"],
|
||||
treeShaking: true,
|
||||
// Ensure require is properly defined: https://github.com/evanw/esbuild/issues/1921
|
||||
banner: {
|
||||
js:
|
||||
"import { createRequire } from 'module';\n" +
|
||||
"const require = createRequire(import.meta.url);",
|
||||
},
|
||||
});
|
||||
|
||||
const analysis = await analyzeMetafile(result.metafile);
|
||||
console.info(`📝 Bundle Analysis:${analysis}`);
|
||||
|
||||
console.info(
|
||||
`${chalk.bold.green("✔ Bundled successfully!")} (${
|
||||
Date.now() - startTime
|
||||
}ms)`,
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(`🧨 ${chalk.red.bold("Failed:")} ${error.message}`);
|
||||
console.debug(`📚 ${chalk.blueBright.bold("Stack:")} ${error.stack}`);
|
||||
process.exit(1);
|
||||
}
|
||||
})();
|
@ -1,98 +0,0 @@
|
||||
// @ts-check
|
||||
|
||||
import {fixupPluginRules} from '@eslint/compat'
|
||||
import {FlatCompat} from '@eslint/eslintrc'
|
||||
import jsEslint from '@eslint/js'
|
||||
import eslintConfigPrettier from 'eslint-config-prettier'
|
||||
import tsEslint from 'typescript-eslint'
|
||||
|
||||
const compat = new FlatCompat({
|
||||
baseDirectory: import.meta.dirname,
|
||||
recommendedConfig: jsEslint.configs.recommended,
|
||||
allConfig: jsEslint.configs.all
|
||||
})
|
||||
|
||||
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||
/**
|
||||
* @param {string} name the pugin name
|
||||
* @param {string} alias the plugin alias
|
||||
* @returns {import("eslint").ESLint.Plugin}
|
||||
*/
|
||||
function legacyPlugin(name, alias = name) {
|
||||
const plugin = compat.plugins(name)[0]?.plugins?.[alias]
|
||||
|
||||
if (!plugin) {
|
||||
throw new Error(`Unable to resolve plugin ${name} and/or alias ${alias}`)
|
||||
}
|
||||
|
||||
return fixupPluginRules(plugin)
|
||||
}
|
||||
/* eslint-enable @typescript-eslint/explicit-function-return-type */
|
||||
|
||||
export default tsEslint.config(
|
||||
jsEslint.configs.recommended,
|
||||
...tsEslint.configs.strictTypeChecked,
|
||||
...tsEslint.configs.stylisticTypeChecked,
|
||||
{
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
projectService: {
|
||||
allowDefaultProject: ['*.js', '*.mjs']
|
||||
},
|
||||
tsconfigRootDir: import.meta.dirname
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
ignores: ['**/coverage', '**/dist', '**/esbuild.config.mjs']
|
||||
},
|
||||
{
|
||||
plugins: {
|
||||
github: legacyPlugin('eslint-plugin-github', 'github'), // pending https://github.com/github/eslint-plugin-github/issues/513
|
||||
import: legacyPlugin('eslint-plugin-import', 'import') // Needed for above
|
||||
},
|
||||
rules: {
|
||||
'@typescript-eslint/await-thenable': 'warn',
|
||||
'@typescript-eslint/explicit-function-return-type': 'warn',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/no-floating-promises': ['warn', {ignoreIIFE: true, ignoreVoid: false}],
|
||||
'@typescript-eslint/no-shadow': 'error',
|
||||
'@typescript-eslint/no-unused-vars': ['warn', {argsIgnorePattern: '^_'}],
|
||||
'@typescript-eslint/restrict-template-expressions': [
|
||||
'error',
|
||||
{
|
||||
allowNever: true,
|
||||
allowNumber: true
|
||||
}
|
||||
],
|
||||
'github/array-foreach': 'error',
|
||||
'github/no-implicit-buggy-globals': 'error',
|
||||
'github/no-then': 'error',
|
||||
'github/no-dynamic-script-tag': 'error',
|
||||
'import/no-extraneous-dependencies': [
|
||||
'error',
|
||||
{
|
||||
devDependencies: true,
|
||||
optionalDependencies: true,
|
||||
peerDependencies: true
|
||||
}
|
||||
],
|
||||
'import/order': ['warn', {'newlines-between': 'always', alphabetize: {order: 'asc'}}],
|
||||
'no-console': ['warn']
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ['**/*.test.ts'],
|
||||
rules: {
|
||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||
'@typescript-eslint/no-unsafe-assignment': 'off',
|
||||
'@typescript-eslint/no-unsafe-member-access': 'off'
|
||||
}
|
||||
},
|
||||
{
|
||||
files: ['**/*.js', '**/*.mjs'],
|
||||
...tsEslint.configs.disableTypeChecked
|
||||
},
|
||||
eslintConfigPrettier
|
||||
)
|
11
jest.config.js
Normal file
11
jest.config.js
Normal file
@ -0,0 +1,11 @@
|
||||
module.exports = {
|
||||
clearMocks: true,
|
||||
moduleFileExtensions: ['js', 'ts'],
|
||||
testEnvironment: 'node',
|
||||
testMatch: ['**/*.test.ts'],
|
||||
testRunner: 'jest-circus/runner',
|
||||
transform: {
|
||||
'^.+\\.ts$': 'ts-jest'
|
||||
},
|
||||
verbose: true
|
||||
}
|
7079
package-lock.json
generated
Normal file
7079
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
59
package.json
59
package.json
@ -3,59 +3,52 @@
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"description": "Execute your workflow steps only if relevant files are modified.",
|
||||
"type": "module",
|
||||
"main": "lib/main.js",
|
||||
"scripts": {
|
||||
"build": "pnpm run build:types && pnpm run build:bundle",
|
||||
"build:bundle": "node ./esbuild.config.mjs",
|
||||
"build:types": "tsc",
|
||||
"build": "tsc",
|
||||
"tscheck": "tsc --noEmit",
|
||||
"format": "prettier --write **/*.ts",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"lint": "eslint",
|
||||
"test": "vitest",
|
||||
"all": "pnpm run build && pnpm run lint && pnpm run format && pnpm test run"
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"pack": "ncc build -m",
|
||||
"test": "jest",
|
||||
"all": "npm run build && npm run format && npm run lint && npm run pack && npm test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/AurorNZ/paths-filter.git"
|
||||
"url": "git+https://github.com/actions/typescript-action.git"
|
||||
},
|
||||
"keywords": [
|
||||
"actions",
|
||||
"node",
|
||||
"setup"
|
||||
],
|
||||
"author": "YourNameOrOrganization",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/exec": "^1.1.1",
|
||||
"@actions/github": "^6.0.0",
|
||||
"js-yaml": "^4.1.0",
|
||||
"micromatch": "^4.0.8"
|
||||
"micromatch": "^4.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/compat": "^1.1.1",
|
||||
"@eslint/eslintrc": "^3.1.0",
|
||||
"@eslint/js": "^9.10.0",
|
||||
"@octokit/webhooks-types": "^7.5.1",
|
||||
"@tsconfig/node20": "^20.1.4",
|
||||
"@types/eslint__js": "^8.42.3",
|
||||
"@octokit/webhooks-types": "^7.3.1",
|
||||
"@tsconfig/node20": "^20.1.2",
|
||||
"@types/jest": "^29.5.11",
|
||||
"@types/js-yaml": "^4.0.9",
|
||||
"@types/micromatch": "^4.0.9",
|
||||
"@types/micromatch": "^4.0.2",
|
||||
"@types/node": "^20.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.5.0",
|
||||
"@typescript-eslint/parser": "^8.5.0",
|
||||
"chalk": "^5.3.0",
|
||||
"esbuild": "^0.23.1",
|
||||
"eslint": "^9.10.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-import-resolver-typescript": "^3.6.3",
|
||||
"eslint-plugin-github": "^5.0.1",
|
||||
"prettier": "^3.3.3",
|
||||
"typescript": "^5.6.2",
|
||||
"typescript-eslint": "^8.5.0",
|
||||
"vitest": "^2.0.5"
|
||||
},
|
||||
"volta": {
|
||||
"node": "20.17.0",
|
||||
"pnpm": "8.15.8"
|
||||
"@typescript-eslint/eslint-plugin": "^6.20.0",
|
||||
"@typescript-eslint/parser": "^6.20.0",
|
||||
"@vercel/ncc": "^0.38.1",
|
||||
"eslint": "^8.56.0",
|
||||
"eslint-plugin-github": "^4.10.1",
|
||||
"eslint-plugin-jest": "^27.6.3",
|
||||
"jest": "^29.7.0",
|
||||
"jest-circus": "^29.7.0",
|
||||
"prettier": "^3.2.4",
|
||||
"ts-jest": "^29.1.2",
|
||||
"typescript": "^5.3.3"
|
||||
}
|
||||
}
|
||||
|
3581
pnpm-lock.yaml
3581
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
@ -3,12 +3,12 @@ import {exec as execImpl, ExecOptions} from '@actions/exec'
|
||||
// Wraps original exec() function
|
||||
// Returns exit code and whole stdout/stderr
|
||||
export default async function exec(commandLine: string, args?: string[], options?: ExecOptions): Promise<ExecResult> {
|
||||
options = options ?? {}
|
||||
options = options || {}
|
||||
let stdout = ''
|
||||
let stderr = ''
|
||||
options.listeners = {
|
||||
stdout: (data: Buffer): string => (stdout += data.toString()),
|
||||
stderr: (data: Buffer): string => (stderr += data.toString())
|
||||
stdout: (data: Buffer) => (stdout += data.toString()),
|
||||
stderr: (data: Buffer) => (stderr += data.toString())
|
||||
}
|
||||
const code = await execImpl(commandLine, args, options)
|
||||
return {code, stdout, stderr}
|
||||
|
@ -1,10 +1,11 @@
|
||||
import * as jsyaml from 'js-yaml'
|
||||
import micromatch from 'micromatch'
|
||||
|
||||
import {File} from './file.ts'
|
||||
import {File} from './file'
|
||||
|
||||
// Type definition of object we expect to load from YAML
|
||||
type FilterYaml = Record<string, FilterItemYaml>
|
||||
interface FilterYaml {
|
||||
[name: string]: FilterItemYaml
|
||||
}
|
||||
type FilterItemYaml =
|
||||
| string // Filename pattern, e.g. "path/to/*.js"
|
||||
| FilterItemYaml[] // Supports referencing another rule via YAML anchor
|
||||
@ -14,10 +15,12 @@ const MatchOptions: micromatch.Options = {
|
||||
dot: true
|
||||
}
|
||||
|
||||
export type FilterResults = Partial<Record<string, File[]>>
|
||||
export interface FilterResults {
|
||||
[key: string]: File[]
|
||||
}
|
||||
|
||||
export class Filter {
|
||||
rules: Record<string, string[]> = {}
|
||||
rules: {[key: string]: string[]} = {}
|
||||
|
||||
// Creates instance of Filter and load rules from YAML if it's provided
|
||||
constructor(yaml?: string) {
|
||||
@ -44,9 +47,9 @@ export class Filter {
|
||||
|
||||
match(files: File[]): FilterResults {
|
||||
const result: FilterResults = {}
|
||||
const filesMap = files.reduce((fileResult, x) => {
|
||||
fileResult.set(x.filename, x)
|
||||
return fileResult
|
||||
const filesMap = files.reduce((result, x) => {
|
||||
result.set(x.filename, x)
|
||||
return result
|
||||
}, new Map<string, File>())
|
||||
|
||||
for (const [key, patterns] of Object.entries(this.rules)) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
import exec from './exec'
|
||||
import * as core from '@actions/core'
|
||||
|
||||
import exec from './exec.ts'
|
||||
import {File, ChangeStatus} from './file.ts'
|
||||
import {File, ChangeStatus} from './file'
|
||||
|
||||
export const NULL_SHA = '0000000000000000000000000000000000000000'
|
||||
export const HEAD = 'HEAD'
|
||||
@ -216,7 +215,7 @@ async function getLocalRef(shortName: string): Promise<string | undefined> {
|
||||
const output = (await exec('git', ['show-ref', shortName], {ignoreReturnCode: true})).stdout
|
||||
const refs = output
|
||||
.split(/\r?\n/g)
|
||||
.map(l => /refs\/(?:(?:heads)|(?:tags)|(?:remotes\/origin))\/(.*)$/.exec(l))
|
||||
.map(l => l.match(/refs\/(?:(?:heads)|(?:tags)|(?:remotes\/origin))\/(.*)$/))
|
||||
.filter(match => match !== null && match[1] === shortName)
|
||||
.map(match => match?.[0] ?? '') // match can't be null here but compiler doesn't understand that
|
||||
|
||||
@ -261,7 +260,7 @@ function fixStdOutNullTermination(): void {
|
||||
core.info('')
|
||||
}
|
||||
|
||||
const statusMap: Record<string, ChangeStatus> = {
|
||||
const statusMap: {[char: string]: ChangeStatus} = {
|
||||
A: ChangeStatus.Added,
|
||||
C: ChangeStatus.Copied,
|
||||
D: ChangeStatus.Deleted,
|
||||
|
30
src/main.ts
30
src/main.ts
@ -1,14 +1,13 @@
|
||||
import * as fs from 'node:fs'
|
||||
|
||||
import * as fs from 'fs'
|
||||
import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import {PullRequest, PushEvent} from '@octokit/webhooks-types'
|
||||
|
||||
import {File, ChangeStatus} from './file.ts'
|
||||
import {Filter, FilterResults} from './filter.ts'
|
||||
import * as git from './git.ts'
|
||||
import {csvEscape} from './list-format/csv-escape.ts'
|
||||
import {backslashEscape, shellEscape} from './list-format/shell-escape.ts'
|
||||
import {Filter, FilterResults} from './filter'
|
||||
import {File, ChangeStatus} from './file'
|
||||
import * as git from './git'
|
||||
import {backslashEscape, shellEscape} from './list-format/shell-escape'
|
||||
import {csvEscape} from './list-format/csv-escape'
|
||||
|
||||
type ExportFormat = 'none' | 'csv' | 'json' | 'shell' | 'escape'
|
||||
|
||||
@ -96,10 +95,7 @@ async function getChangedFiles(token: string, base: string, ref: string, initial
|
||||
}
|
||||
|
||||
async function getChangedFilesFromGit(base: string, head: string, initialFetchDepth: number): Promise<File[]> {
|
||||
const defaultBranch =
|
||||
typeof github.context.payload.repository?.default_branch === 'string'
|
||||
? github.context.payload.repository.default_branch
|
||||
: ''
|
||||
const defaultBranch = github.context.payload.repository?.default_branch
|
||||
|
||||
const beforeSha = github.context.eventName === 'push' ? (github.context.payload as PushEvent).before : null
|
||||
|
||||
@ -178,7 +174,6 @@ async function getChangedFilesFromApi(token: string, prNumber: PullRequest): Pro
|
||||
page
|
||||
})
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
if (response.status !== 200) {
|
||||
throw new Error(`Fetching list of changed files from GitHub API failed with error code ${response.status}`)
|
||||
}
|
||||
@ -200,9 +195,8 @@ async function getChangedFilesFromApi(token: string, prNumber: PullRequest): Pro
|
||||
status: ChangeStatus.Added
|
||||
})
|
||||
files.push({
|
||||
// Existing behaviour, possibly a bug
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
filename: row.previous_filename!,
|
||||
// 'previous_filename' for some unknown reason isn't in the type definition or documentation
|
||||
filename: (<any>row).previous_filename as string,
|
||||
status: ChangeStatus.Deleted
|
||||
})
|
||||
} else {
|
||||
@ -226,8 +220,6 @@ function exportResults(results: FilterResults, format: ExportFormat): void {
|
||||
core.info('Results:')
|
||||
const changes = []
|
||||
for (const [key, files] of Object.entries(results)) {
|
||||
if (!files) continue
|
||||
|
||||
const value = files.length > 0
|
||||
core.startGroup(`Filter ${key} = ${value}`)
|
||||
if (files.length > 0) {
|
||||
@ -249,7 +241,7 @@ function exportResults(results: FilterResults, format: ExportFormat): void {
|
||||
core.endGroup()
|
||||
}
|
||||
|
||||
if (results.changes === undefined) {
|
||||
if (results['changes'] === undefined) {
|
||||
const changesJson = JSON.stringify(changes)
|
||||
core.info(`Changes output set to ${changesJson}`)
|
||||
core.setOutput('changes', changesJson)
|
||||
@ -278,4 +270,4 @@ function isExportFormat(value: string): value is ExportFormat {
|
||||
return ['none', 'csv', 'shell', 'json', 'escape'].includes(value)
|
||||
}
|
||||
|
||||
;((): Promise<void> => run())()
|
||||
run()
|
||||
|
@ -1,8 +1,8 @@
|
||||
{
|
||||
"extends": "@tsconfig/node20/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"noEmit": true,
|
||||
|
||||
"allowImportingTsExtensions": true,
|
||||
}
|
||||
"outDir": "./lib", /* Redirect output structure to the directory. */
|
||||
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
},
|
||||
"exclude": ["node_modules", "**/*.test.ts"]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user