mirror of
https://github.com/dorny/paths-filter.git
synced 2024-11-12 08:38:35 +00:00
Compare commits
17 Commits
b671dc324f
...
298e00d169
Author | SHA1 | Date | |
---|---|---|---|
|
298e00d169 | ||
|
54ebb4d5f2 | ||
|
6f1712ff4e | ||
|
bfc6e48216 | ||
|
5c7b514919 | ||
|
d28a6399db | ||
|
f46f3f0cc6 | ||
|
61068b04d2 | ||
|
c4f6f6794a | ||
|
e5970628e0 | ||
|
09d0925459 | ||
|
19fa779d55 | ||
|
00461c6632 | ||
|
f81aac8ad0 | ||
|
6818e25de3 | ||
|
9a1e626831 | ||
|
768f03c879 |
@ -1,3 +0,0 @@
|
||||
dist/
|
||||
lib/
|
||||
node_modules/
|
@ -1,53 +0,0 @@
|
||||
{
|
||||
"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 +1,3 @@
|
||||
* text=auto eol=lf
|
||||
* text=auto eol=lf
|
||||
|
||||
dist/** -diff linguist-generated=true
|
||||
|
12
.github/workflows/build.yml
vendored
12
.github/workflows/build.yml
vendored
@ -5,19 +5,23 @@ on:
|
||||
branches:
|
||||
- master
|
||||
|
||||
env:
|
||||
VOLTA_FEATURE_PNPM: 1
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: volta-cli/action@v4
|
||||
- run: |
|
||||
npm install
|
||||
npm run all
|
||||
pnpm install
|
||||
pnpm run all
|
||||
|
||||
self-test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ./
|
||||
id: filter
|
||||
with:
|
||||
|
30
.github/workflows/pull-request-verification.yml
vendored
30
.github/workflows/pull-request-verification.yml
vendored
@ -6,21 +6,35 @@ on:
|
||||
- master
|
||||
- '**'
|
||||
|
||||
env:
|
||||
VOLTA_FEATURE_PNPM: 1
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # Need history for changelog generation
|
||||
- uses: volta-cli/action@v4
|
||||
- run: |
|
||||
npm install
|
||||
npm run all
|
||||
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
|
||||
|
||||
test-inline:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
pull-requests: read
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ./
|
||||
id: filter
|
||||
with:
|
||||
@ -41,7 +55,7 @@ jobs:
|
||||
permissions:
|
||||
pull-requests: read
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ./
|
||||
id: filter
|
||||
with:
|
||||
@ -53,7 +67,7 @@ jobs:
|
||||
test-without-token:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: ./
|
||||
id: filter
|
||||
with:
|
||||
@ -66,7 +80,7 @@ jobs:
|
||||
test-wd-without-token:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
path: somewhere
|
||||
- uses: ./somewhere
|
||||
@ -82,7 +96,7 @@ jobs:
|
||||
test-local-changes:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- run: echo "NEW FILE" > local
|
||||
- run: git add local
|
||||
- uses: ./
|
||||
|
@ -1,11 +1,10 @@
|
||||
{
|
||||
"printWidth": 120,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": false,
|
||||
"arrowParens": "avoid",
|
||||
"parser": "typescript"
|
||||
}
|
||||
"printWidth": 120,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": false,
|
||||
"arrowParens": "avoid"
|
||||
}
|
||||
|
35
.vscode/launch.json
vendored
35
.vscode/launch.json
vendored
@ -1,35 +0,0 @@
|
||||
{
|
||||
"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,4 +1,6 @@
|
||||
import {csvEscape} from '../src/list-format/csv-escape'
|
||||
import {describe, expect, test} from 'vitest'
|
||||
|
||||
import {csvEscape} from '../src/list-format/csv-escape.ts'
|
||||
|
||||
describe('csvEscape() backslash escapes every character except subset of definitely safe characters', () => {
|
||||
test('simple filename should not be modified', () => {
|
||||
|
@ -1,5 +1,7 @@
|
||||
import {Filter} from '../src/filter'
|
||||
import {File, ChangeStatus} from '../src/file'
|
||||
import {describe, expect, test} from 'vitest'
|
||||
|
||||
import {File, ChangeStatus} from '../src/file.ts'
|
||||
import {Filter} from '../src/filter.ts'
|
||||
|
||||
describe('yaml filter parsing tests', () => {
|
||||
test('throws if yaml is not a dictionary', () => {
|
||||
@ -24,7 +26,7 @@ describe('matching tests', () => {
|
||||
const yaml = `
|
||||
src: "src/**/*.js"
|
||||
`
|
||||
let filter = new Filter(yaml)
|
||||
const filter = new Filter(yaml)
|
||||
const files = modified(['src/app/module/file.js'])
|
||||
const match = filter.match(files)
|
||||
expect(match.src).toEqual(files)
|
||||
|
@ -1,8 +1,10 @@
|
||||
import * as git from '../src/git'
|
||||
import {ChangeStatus} from '../src/file'
|
||||
import {describe, expect, test} from 'vitest'
|
||||
|
||||
import {ChangeStatus} from '../src/file.ts'
|
||||
import * as git from '../src/git.ts'
|
||||
|
||||
describe('parsing output of the git diff command', () => {
|
||||
test('parseGitDiffOutput returns files with correct change status', async () => {
|
||||
test('parseGitDiffOutput returns files with correct change status', () => {
|
||||
const files = git.parseGitDiffOutput(
|
||||
'A\u0000LICENSE\u0000' + 'M\u0000src/index.ts\u0000' + 'D\u0000src/main.ts\u0000'
|
||||
)
|
||||
|
@ -1,4 +1,6 @@
|
||||
import {backslashEscape, shellEscape} from '../src/list-format/shell-escape'
|
||||
import {describe, expect, test} from 'vitest'
|
||||
|
||||
import {backslashEscape, shellEscape} from '../src/list-format/shell-escape.ts'
|
||||
|
||||
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.js'
|
||||
main: 'dist/index.mjs'
|
||||
branding:
|
||||
color: blue
|
||||
icon: filter
|
||||
|
21
dist/index.js
generated
vendored
21
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
29740
dist/index.mjs
generated
vendored
Normal file
29740
dist/index.mjs
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
41
esbuild.config.mjs
Normal file
41
esbuild.config.mjs
Normal file
@ -0,0 +1,41 @@
|
||||
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);
|
||||
}
|
||||
})();
|
98
eslint.config.mjs
Normal file
98
eslint.config.mjs
Normal file
@ -0,0 +1,98 @@
|
||||
// @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
|
||||
)
|
@ -1,11 +0,0 @@
|
||||
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
7079
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
59
package.json
59
package.json
@ -3,52 +3,59 @@
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"description": "Execute your workflow steps only if relevant files are modified.",
|
||||
"main": "lib/main.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"tscheck": "tsc --noEmit",
|
||||
"build": "pnpm run build:types && pnpm run build:bundle",
|
||||
"build:bundle": "node ./esbuild.config.mjs",
|
||||
"build:types": "tsc",
|
||||
"format": "prettier --write **/*.ts",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"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"
|
||||
"lint": "eslint",
|
||||
"test": "vitest",
|
||||
"all": "pnpm run build && pnpm run lint && pnpm run format && pnpm test run"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/actions/typescript-action.git"
|
||||
"url": "git+https://github.com/AurorNZ/paths-filter.git"
|
||||
},
|
||||
"keywords": [
|
||||
"actions",
|
||||
"node",
|
||||
"setup"
|
||||
],
|
||||
"author": "YourNameOrOrganization",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/exec": "^1.1.1",
|
||||
"@actions/github": "^6.0.0",
|
||||
"js-yaml": "^4.1.0",
|
||||
"micromatch": "^4.0.5"
|
||||
"micromatch": "^4.0.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@octokit/webhooks-types": "^7.3.1",
|
||||
"@tsconfig/node20": "^20.1.2",
|
||||
"@types/jest": "^29.5.11",
|
||||
"@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",
|
||||
"@types/js-yaml": "^4.0.9",
|
||||
"@types/micromatch": "^4.0.2",
|
||||
"@types/micromatch": "^4.0.9",
|
||||
"@types/node": "^20.0.0",
|
||||
"@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"
|
||||
"@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"
|
||||
}
|
||||
}
|
||||
|
3581
pnpm-lock.yaml
Normal file
3581
pnpm-lock.yaml
Normal file
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) => (stdout += data.toString()),
|
||||
stderr: (data: Buffer) => (stderr += data.toString())
|
||||
stdout: (data: Buffer): string => (stdout += data.toString()),
|
||||
stderr: (data: Buffer): string => (stderr += data.toString())
|
||||
}
|
||||
const code = await execImpl(commandLine, args, options)
|
||||
return {code, stdout, stderr}
|
||||
|
@ -1,11 +1,10 @@
|
||||
import * as jsyaml from 'js-yaml'
|
||||
import micromatch from 'micromatch'
|
||||
import {File} from './file'
|
||||
|
||||
import {File} from './file.ts'
|
||||
|
||||
// Type definition of object we expect to load from YAML
|
||||
interface FilterYaml {
|
||||
[name: string]: FilterItemYaml
|
||||
}
|
||||
type FilterYaml = Record<string, FilterItemYaml>
|
||||
type FilterItemYaml =
|
||||
| string // Filename pattern, e.g. "path/to/*.js"
|
||||
| FilterItemYaml[] // Supports referencing another rule via YAML anchor
|
||||
@ -15,12 +14,10 @@ const MatchOptions: micromatch.Options = {
|
||||
dot: true
|
||||
}
|
||||
|
||||
export interface FilterResults {
|
||||
[key: string]: File[]
|
||||
}
|
||||
export type FilterResults = Partial<Record<string, File[]>>
|
||||
|
||||
export class Filter {
|
||||
rules: {[key: string]: string[]} = {}
|
||||
rules: Record<string, string[]> = {}
|
||||
|
||||
// Creates instance of Filter and load rules from YAML if it's provided
|
||||
constructor(yaml?: string) {
|
||||
@ -47,9 +44,9 @@ export class Filter {
|
||||
|
||||
match(files: File[]): FilterResults {
|
||||
const result: FilterResults = {}
|
||||
const filesMap = files.reduce((result, x) => {
|
||||
result.set(x.filename, x)
|
||||
return result
|
||||
const filesMap = files.reduce((fileResult, x) => {
|
||||
fileResult.set(x.filename, x)
|
||||
return fileResult
|
||||
}, new Map<string, File>())
|
||||
|
||||
for (const [key, patterns] of Object.entries(this.rules)) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
import exec from './exec'
|
||||
import * as core from '@actions/core'
|
||||
import {File, ChangeStatus} from './file'
|
||||
|
||||
import exec from './exec.ts'
|
||||
import {File, ChangeStatus} from './file.ts'
|
||||
|
||||
export const NULL_SHA = '0000000000000000000000000000000000000000'
|
||||
export const HEAD = 'HEAD'
|
||||
@ -215,7 +216,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 => l.match(/refs\/(?:(?:heads)|(?:tags)|(?:remotes\/origin))\/(.*)$/))
|
||||
.map(l => /refs\/(?:(?:heads)|(?:tags)|(?:remotes\/origin))\/(.*)$/.exec(l))
|
||||
.filter(match => match !== null && match[1] === shortName)
|
||||
.map(match => match?.[0] ?? '') // match can't be null here but compiler doesn't understand that
|
||||
|
||||
@ -260,7 +261,7 @@ function fixStdOutNullTermination(): void {
|
||||
core.info('')
|
||||
}
|
||||
|
||||
const statusMap: {[char: string]: ChangeStatus} = {
|
||||
const statusMap: Record<string, ChangeStatus> = {
|
||||
A: ChangeStatus.Added,
|
||||
C: ChangeStatus.Copied,
|
||||
D: ChangeStatus.Deleted,
|
||||
|
30
src/main.ts
30
src/main.ts
@ -1,13 +1,14 @@
|
||||
import * as fs from 'fs'
|
||||
import * as fs from 'node:fs'
|
||||
|
||||
import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import {PullRequest, PushEvent} from '@octokit/webhooks-types'
|
||||
|
||||
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'
|
||||
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'
|
||||
|
||||
type ExportFormat = 'none' | 'csv' | 'json' | 'shell' | 'escape'
|
||||
|
||||
@ -95,7 +96,10 @@ async function getChangedFiles(token: string, base: string, ref: string, initial
|
||||
}
|
||||
|
||||
async function getChangedFilesFromGit(base: string, head: string, initialFetchDepth: number): Promise<File[]> {
|
||||
const defaultBranch = github.context.payload.repository?.default_branch
|
||||
const defaultBranch =
|
||||
typeof github.context.payload.repository?.default_branch === 'string'
|
||||
? github.context.payload.repository.default_branch
|
||||
: ''
|
||||
|
||||
const beforeSha = github.context.eventName === 'push' ? (github.context.payload as PushEvent).before : null
|
||||
|
||||
@ -174,6 +178,7 @@ 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}`)
|
||||
}
|
||||
@ -195,8 +200,9 @@ async function getChangedFilesFromApi(token: string, prNumber: PullRequest): Pro
|
||||
status: ChangeStatus.Added
|
||||
})
|
||||
files.push({
|
||||
// 'previous_filename' for some unknown reason isn't in the type definition or documentation
|
||||
filename: (<any>row).previous_filename as string,
|
||||
// Existing behaviour, possibly a bug
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
filename: row.previous_filename!,
|
||||
status: ChangeStatus.Deleted
|
||||
})
|
||||
} else {
|
||||
@ -220,6 +226,8 @@ 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) {
|
||||
@ -241,7 +249,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)
|
||||
@ -270,4 +278,4 @@ function isExportFormat(value: string): value is ExportFormat {
|
||||
return ['none', 'csv', 'shell', 'json', 'escape'].includes(value)
|
||||
}
|
||||
|
||||
run()
|
||||
;((): Promise<void> => run())()
|
||||
|
@ -1,8 +1,8 @@
|
||||
{
|
||||
"extends": "@tsconfig/node20/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"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"]
|
||||
"noEmit": true,
|
||||
|
||||
"allowImportingTsExtensions": true,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user