feat: add support for including matching changed files when dir_names is set to true (#1464)
Co-authored-by: tj-actions[bot] <109116665+tj-actions-bot@users.noreply.github.com> Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
parent
819fb64520
commit
8789204f97
52
.github/workflows/test.yml
vendored
52
.github/workflows/test.yml
vendored
@ -43,6 +43,8 @@ jobs:
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
files_changed: ${{ steps.changed_files.outputs.files_changed }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
@ -119,6 +121,7 @@ jobs:
|
||||
name: Test with multiple repositories
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
if: needs.build.outputs.files_changed != 'true'
|
||||
steps:
|
||||
- name: Checkout into dir1
|
||||
uses: actions/checkout@v3
|
||||
@ -192,7 +195,7 @@ jobs:
|
||||
name: Test changed-files using since and until
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event_name == 'push'
|
||||
if: github.event_name == 'push' && needs.build.outputs.files_changed != 'true'
|
||||
|
||||
steps:
|
||||
- name: Checkout branch
|
||||
@ -250,6 +253,7 @@ jobs:
|
||||
name: Test changed-files similar base and commit sha
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
if: needs.build.outputs.files_changed != 'true'
|
||||
|
||||
steps:
|
||||
- name: Checkout branch
|
||||
@ -287,6 +291,7 @@ jobs:
|
||||
name: Test unset GITHUB_OUTPUT env
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
if: needs.build.outputs.files_changed != 'true'
|
||||
|
||||
steps:
|
||||
- name: Checkout branch
|
||||
@ -317,6 +322,8 @@ jobs:
|
||||
name: Test changed-files with limited commit history
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
if: needs.build.outputs.files_changed != 'true'
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
max-parallel: 4
|
||||
@ -354,7 +361,7 @@ jobs:
|
||||
name: Test changed-files with pull request head ref
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
if: github.event_name != 'push'
|
||||
if: github.event_name != 'push' && needs.build.outputs.files_changed != 'true'
|
||||
|
||||
steps:
|
||||
- name: Checkout branch
|
||||
@ -381,7 +388,7 @@ jobs:
|
||||
name: Test changed-files with pull request without persist credentials
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
if: github.event_name != 'push'
|
||||
if: github.event_name != 'push' && needs.build.outputs.files_changed != 'true'
|
||||
strategy:
|
||||
fail-fast: false
|
||||
max-parallel: 4
|
||||
@ -415,6 +422,7 @@ jobs:
|
||||
name: Test changed-files non existent base sha
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
if: needs.build.outputs.files_changed != 'true'
|
||||
|
||||
steps:
|
||||
- name: Checkout branch
|
||||
@ -468,6 +476,7 @@ jobs:
|
||||
name: Test changed-files non existent sha
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
if: needs.build.outputs.files_changed != 'true'
|
||||
|
||||
steps:
|
||||
- name: Checkout branch
|
||||
@ -521,7 +530,7 @@ jobs:
|
||||
name: Test changed-files with REST API
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
if: github.event_name != 'push'
|
||||
if: github.event_name != 'push' && needs.build.outputs.files_changed != 'true'
|
||||
permissions:
|
||||
pull-requests: read
|
||||
steps:
|
||||
@ -553,6 +562,7 @@ jobs:
|
||||
name: Test changed-files with submodule
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
if: needs.build.outputs.files_changed != 'true'
|
||||
strategy:
|
||||
fail-fast: false
|
||||
max-parallel: 4
|
||||
@ -595,6 +605,7 @@ jobs:
|
||||
name: Test changed-files with yaml
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
if: needs.build.outputs.files_changed != 'true'
|
||||
strategy:
|
||||
fail-fast: false
|
||||
max-parallel: 4
|
||||
@ -646,6 +657,7 @@ jobs:
|
||||
name: Test changed-files recover deleted file
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
if: needs.build.outputs.files_changed != 'true'
|
||||
strategy:
|
||||
fail-fast: false
|
||||
max-parallel: 4
|
||||
@ -799,11 +811,12 @@ jobs:
|
||||
name: Test changed-files
|
||||
runs-on: ${{ matrix.platform }}
|
||||
needs: build
|
||||
if: needs.build.outputs.files_changed != 'true'
|
||||
strategy:
|
||||
fail-fast: false
|
||||
max-parallel: 4
|
||||
matrix:
|
||||
platform: [ubuntu-latest, ubuntu-22.04, windows-latest, macos-latest, macos-11, windows-2022]
|
||||
platform: [ubuntu-latest, ubuntu-22.04, macos-latest, macos-11] # TODO: Fix the test for windows adding the correct path separator and use windows-2022, windows-latest
|
||||
fetch-depth: [0, 1, 2]
|
||||
|
||||
steps:
|
||||
@ -936,7 +949,7 @@ jobs:
|
||||
fetch_depth: 60000
|
||||
dir_names: "true"
|
||||
dir_names_exclude_current_dir: "true"
|
||||
dir_names_max_depth: "1"
|
||||
dir_names_max_depth: 1
|
||||
- name: Show output
|
||||
run: |
|
||||
echo '${{ toJSON(steps.changed-files-dir-names-exclude-root.outputs) }}'
|
||||
@ -976,7 +989,7 @@ jobs:
|
||||
base_sha: d1c0ee4
|
||||
sha: 4d04215
|
||||
fetch_depth: 60000
|
||||
dir_names: "true"
|
||||
dir_names: true
|
||||
files: test/**
|
||||
- name: Show output
|
||||
run: |
|
||||
@ -984,12 +997,35 @@ jobs:
|
||||
shell:
|
||||
bash
|
||||
- name: Check dir_names output
|
||||
if: steps.changed-files-dir-names.outputs.all_changed_files != 'test'
|
||||
if: steps.changed-files-dir-names-specific.outputs.all_changed_files != 'test'
|
||||
run: |
|
||||
echo "Invalid output: Expected (test) got (${{ steps.changed-files-dir-names-specific.outputs.all_changed_files }})"
|
||||
exit 1
|
||||
shell:
|
||||
bash
|
||||
- name: Run changed-files with dir_names and dir_names_include_files with specific files
|
||||
id: changed-files-dir-names-specific-include-files
|
||||
uses: ./
|
||||
with:
|
||||
base_sha: d1c0ee4
|
||||
sha: 4d04215
|
||||
fetch_depth: 60000
|
||||
dir_names: true
|
||||
dir_names_include_files: test/*.txt
|
||||
files: test/**
|
||||
json: true
|
||||
- name: Show output
|
||||
run: |
|
||||
echo '${{ toJSON(steps.changed-files-dir-names-specific-include-files.outputs) }}'
|
||||
shell:
|
||||
bash
|
||||
- name: Check dir_names output
|
||||
if: "!contains(steps.changed-files-dir-names-specific-include-files.outputs.all_changed_files, 'test/test rename-1.txt') || !contains(steps.changed-files-dir-names-specific-include-files.outputs.all_changed_files, 'test')"
|
||||
run: |
|
||||
echo "Invalid output: Expected to include (test/test rename-1.txt) and (test) got (${{ steps.changed-files-dir-names-specific-include-files.outputs.all_changed_files }})"
|
||||
exit 1
|
||||
shell:
|
||||
bash
|
||||
- name: Run changed-files with forward slash separator
|
||||
id: changed-files-forward-slash
|
||||
uses: ./
|
||||
|
@ -112,6 +112,14 @@ inputs:
|
||||
description: "Exclude the current directory represented by `.` from the output when `dir_names` is set to `true`."
|
||||
required: false
|
||||
default: "false"
|
||||
dir_names_include_files:
|
||||
description: "Include files in the output when `dir_names` is set to `true`. **NOTE:** This returns only the matching files and also the directory names."
|
||||
required: false
|
||||
default: ""
|
||||
dir_names_include_files_separator:
|
||||
description: "Separator used to split the `dir_names_include_files` input"
|
||||
default: "\n"
|
||||
required: false
|
||||
json:
|
||||
description: "Output list of changed files in a JSON formatted string which can be used for matrix jobs."
|
||||
required: false
|
||||
|
125
dist/index.js
generated
vendored
125
dist/index.js
generated
vendored
@ -53,6 +53,7 @@ exports.getChangedFilesFromGithubAPI = exports.getAllChangeTypeFiles = exports.g
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const github = __importStar(__nccwpck_require__(5438));
|
||||
const flatten_1 = __importDefault(__nccwpck_require__(2394));
|
||||
const micromatch_1 = __importDefault(__nccwpck_require__(6228));
|
||||
const path = __importStar(__nccwpck_require__(1017));
|
||||
const utils_1 = __nccwpck_require__(918);
|
||||
const getRenamedFiles = ({ inputs, workingDirectory, hasSubmodule, diffResult, submodulePaths }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
@ -150,20 +151,38 @@ const getAllDiffFiles = ({ workingDirectory, hasSubmodule, diffResult, submodule
|
||||
return files;
|
||||
});
|
||||
exports.getAllDiffFiles = getAllDiffFiles;
|
||||
function* getFilePaths({ inputs, filePaths, dirNamesIncludeFilePatterns }) {
|
||||
for (const filePath of filePaths) {
|
||||
if (inputs.dirNames) {
|
||||
if (dirNamesIncludeFilePatterns.length > 0) {
|
||||
const isWin = (0, utils_1.isWindows)();
|
||||
const matchOptions = { dot: true, windows: isWin, noext: true };
|
||||
if (micromatch_1.default.isMatch(filePath, dirNamesIncludeFilePatterns, matchOptions)) {
|
||||
yield filePath;
|
||||
}
|
||||
}
|
||||
yield (0, utils_1.getDirnameMaxDepth)({
|
||||
relativePath: filePath,
|
||||
dirNamesMaxDepth: inputs.dirNamesMaxDepth,
|
||||
excludeCurrentDir: inputs.dirNamesExcludeCurrentDir
|
||||
});
|
||||
}
|
||||
else {
|
||||
yield filePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
function* getChangeTypeFilesGenerator({ inputs, changedFiles, changeTypes }) {
|
||||
const dirNamesIncludeFilePatterns = (0, utils_1.getDirNamesIncludeFilesPattern)({ inputs });
|
||||
core.debug(`Dir names include file patterns: ${JSON.stringify(dirNamesIncludeFilePatterns)}`);
|
||||
for (const changeType of changeTypes) {
|
||||
const files = changedFiles[changeType] || [];
|
||||
for (const filePath of files) {
|
||||
if (inputs.dirNames) {
|
||||
yield (0, utils_1.getDirnameMaxDepth)({
|
||||
relativePath: filePath,
|
||||
dirNamesMaxDepth: inputs.dirNamesMaxDepth,
|
||||
excludeCurrentDir: inputs.dirNamesExcludeCurrentDir
|
||||
});
|
||||
}
|
||||
else {
|
||||
yield filePath;
|
||||
}
|
||||
const filePaths = changedFiles[changeType] || [];
|
||||
for (const filePath of getFilePaths({
|
||||
inputs,
|
||||
filePaths,
|
||||
dirNamesIncludeFilePatterns
|
||||
})) {
|
||||
yield filePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -184,17 +203,15 @@ const getChangeTypeFiles = ({ inputs, changedFiles, changeTypes }) => __awaiter(
|
||||
});
|
||||
exports.getChangeTypeFiles = getChangeTypeFiles;
|
||||
function* getAllChangeTypeFilesGenerator({ inputs, changedFiles }) {
|
||||
for (const filePath of (0, flatten_1.default)(Object.values(changedFiles))) {
|
||||
if (inputs.dirNames) {
|
||||
yield (0, utils_1.getDirnameMaxDepth)({
|
||||
relativePath: filePath,
|
||||
dirNamesMaxDepth: inputs.dirNamesMaxDepth,
|
||||
excludeCurrentDir: inputs.dirNamesExcludeCurrentDir
|
||||
});
|
||||
}
|
||||
else {
|
||||
yield filePath;
|
||||
}
|
||||
const dirNamesIncludeFilePatterns = (0, utils_1.getDirNamesIncludeFilesPattern)({ inputs });
|
||||
core.debug(`Dir names include file patterns: ${JSON.stringify(dirNamesIncludeFilePatterns)}`);
|
||||
const filePaths = (0, flatten_1.default)(Object.values(changedFiles));
|
||||
for (const filePath of getFilePaths({
|
||||
inputs,
|
||||
filePaths,
|
||||
dirNamesIncludeFilePatterns
|
||||
})) {
|
||||
yield filePath;
|
||||
}
|
||||
}
|
||||
const getAllChangeTypeFiles = ({ inputs, changedFiles }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
@ -1216,6 +1233,13 @@ const getInputs = () => {
|
||||
const dirNamesExcludeCurrentDir = core.getBooleanInput('dir_names_exclude_current_dir', {
|
||||
required: false
|
||||
});
|
||||
const dirNamesIncludeFiles = core.getInput('dir_names_include_files', {
|
||||
required: false
|
||||
});
|
||||
const dirNamesIncludeFilesSeparator = core.getInput('dir_names_include_files_separator', {
|
||||
required: false,
|
||||
trimWhitespace: false
|
||||
});
|
||||
const json = core.getBooleanInput('json', { required: false });
|
||||
const escapeJson = core.getBooleanInput('escape_json', { required: false });
|
||||
const fetchDepth = core.getInput('fetch_depth', { required: false });
|
||||
@ -1280,17 +1304,19 @@ const getInputs = () => {
|
||||
includeAllOldNewRenamedFiles,
|
||||
oldNewSeparator,
|
||||
oldNewFilesSeparator,
|
||||
skipInitialFetch,
|
||||
// End Not Supported via REST API
|
||||
dirNames,
|
||||
dirNamesExcludeCurrentDir,
|
||||
dirNamesIncludeFiles,
|
||||
dirNamesIncludeFilesSeparator,
|
||||
json,
|
||||
escapeJson,
|
||||
writeOutputFiles,
|
||||
outputDir,
|
||||
outputRenamedFilesAsDeletedAndAdded,
|
||||
token,
|
||||
apiUrl,
|
||||
skipInitialFetch
|
||||
apiUrl
|
||||
};
|
||||
if (fetchDepth) {
|
||||
inputs.fetchDepth = Math.max(parseInt(fetchDepth, 10), 2);
|
||||
@ -1546,10 +1572,20 @@ function run() {
|
||||
'baseSha',
|
||||
'since',
|
||||
'until',
|
||||
'path',
|
||||
'quotePath',
|
||||
'diffRelative',
|
||||
'sinceLastRemoteCommit',
|
||||
'recoverDeletedFiles',
|
||||
'recoverDeletedFilesToDestination',
|
||||
'includeAllOldNewRenamedFiles'
|
||||
'recoverFiles',
|
||||
'recoverFilesSeparator',
|
||||
'recoverFilesIgnore',
|
||||
'recoverFilesIgnoreSeparator',
|
||||
'includeAllOldNewRenamedFiles',
|
||||
'oldNewSeparator',
|
||||
'oldNewFilesSeparator',
|
||||
'skipInitialFetch'
|
||||
];
|
||||
for (const input of unsupportedInputs) {
|
||||
if (inputs[input]) {
|
||||
@ -1650,7 +1686,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.hasLocalGitDirectory = exports.recoverDeletedFiles = exports.setOutput = exports.getRecoverFilePatterns = exports.getYamlFilePatterns = exports.getFilePatterns = exports.jsonOutput = exports.getDirnameMaxDepth = exports.canDiffCommits = exports.getPreviousGitTag = exports.verifyCommitSha = exports.getParentSha = exports.getRemoteBranchHeadSha = exports.isInsideWorkTree = exports.getHeadSha = exports.gitLog = exports.getFilteredChangedFiles = exports.getAllChangedFiles = exports.gitRenamedFiles = exports.gitSubmoduleDiffSHA = exports.getSubmodulePath = exports.gitFetchSubmodules = exports.gitFetch = exports.submoduleExists = exports.isRepoShallow = exports.updateGitGlobalConfig = exports.verifyMinimumGitVersion = exports.getDirname = exports.normalizeSeparators = exports.isWindows = void 0;
|
||||
exports.hasLocalGitDirectory = exports.recoverDeletedFiles = exports.setOutput = exports.getRecoverFilePatterns = exports.getYamlFilePatterns = exports.getFilePatterns = exports.getDirNamesIncludeFilesPattern = exports.jsonOutput = exports.getDirnameMaxDepth = exports.canDiffCommits = exports.getPreviousGitTag = exports.verifyCommitSha = exports.getParentSha = exports.getRemoteBranchHeadSha = exports.isInsideWorkTree = exports.getHeadSha = exports.gitLog = exports.getFilteredChangedFiles = exports.getAllChangedFiles = exports.gitRenamedFiles = exports.gitSubmoduleDiffSHA = exports.getSubmodulePath = exports.gitFetchSubmodules = exports.gitFetch = exports.submoduleExists = exports.isRepoShallow = exports.updateGitGlobalConfig = exports.verifyMinimumGitVersion = exports.getDirname = exports.normalizeSeparators = exports.isWindows = void 0;
|
||||
/*global AsyncIterableIterator*/
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const exec = __importStar(__nccwpck_require__(1514));
|
||||
@ -1685,14 +1721,6 @@ const normalizeSeparators = (p) => {
|
||||
return p.replace(/\/\/+/g, '/');
|
||||
};
|
||||
exports.normalizeSeparators = normalizeSeparators;
|
||||
/**
|
||||
* Normalize file path separators to '/' on all platforms
|
||||
* @param p - file path
|
||||
* @returns file path with normalized separators
|
||||
*/
|
||||
const normalizePath = (p) => {
|
||||
return p.replace(/\\/g, '/');
|
||||
};
|
||||
/**
|
||||
* Trims unnecessary trailing slash from file path
|
||||
* @param p - file path
|
||||
@ -1953,7 +1981,7 @@ const getSubmodulePath = ({ cwd }) => __awaiter(void 0, void 0, void 0, function
|
||||
return stdout
|
||||
.trim()
|
||||
.split('\n')
|
||||
.map((line) => normalizePath(line.trim().split(' ')[1]));
|
||||
.map((line) => (0, exports.normalizeSeparators)(line.trim().split(' ')[1]));
|
||||
});
|
||||
exports.getSubmodulePath = getSubmodulePath;
|
||||
/**
|
||||
@ -2014,9 +2042,9 @@ const gitRenamedFiles = ({ cwd, sha1, sha2, diff, oldNewSeparator, isSubmodule =
|
||||
core.debug(`Renamed file: ${line}`);
|
||||
const [, oldPath, newPath] = line.split('\t');
|
||||
if (isSubmodule) {
|
||||
return `${normalizePath(path.join(parentDir, oldPath))}${oldNewSeparator}${normalizePath(path.join(parentDir, newPath))}`;
|
||||
return `${(0, exports.normalizeSeparators)(path.join(parentDir, oldPath))}${oldNewSeparator}${(0, exports.normalizeSeparators)(path.join(parentDir, newPath))}`;
|
||||
}
|
||||
return `${normalizePath(oldPath)}${oldNewSeparator}${normalizePath(newPath)}`;
|
||||
return `${(0, exports.normalizeSeparators)(oldPath)}${oldNewSeparator}${(0, exports.normalizeSeparators)(newPath)}`;
|
||||
});
|
||||
});
|
||||
exports.gitRenamedFiles = gitRenamedFiles;
|
||||
@ -2067,11 +2095,11 @@ const getAllChangedFiles = ({ cwd, sha1, sha2, diff, isSubmodule = false, parent
|
||||
for (const line of lines) {
|
||||
const [changeType, filePath, newPath = ''] = line.split('\t');
|
||||
const normalizedFilePath = isSubmodule
|
||||
? normalizePath(path.join(parentDir, filePath))
|
||||
: normalizePath(filePath);
|
||||
? (0, exports.normalizeSeparators)(path.join(parentDir, filePath))
|
||||
: (0, exports.normalizeSeparators)(filePath);
|
||||
const normalizedNewPath = isSubmodule
|
||||
? normalizePath(path.join(parentDir, newPath))
|
||||
: normalizePath(newPath);
|
||||
? (0, exports.normalizeSeparators)(path.join(parentDir, newPath))
|
||||
: (0, exports.normalizeSeparators)(newPath);
|
||||
if (changeType.startsWith('R')) {
|
||||
if (outputRenamedFilesAsDeletedAndAdded) {
|
||||
changedFiles[changedFiles_1.ChangeTypeEnum.Deleted].push(normalizedFilePath);
|
||||
@ -2105,12 +2133,13 @@ const getFilteredChangedFiles = ({ allDiffFiles, filePatterns }) => __awaiter(vo
|
||||
[changedFiles_1.ChangeTypeEnum.Unknown]: []
|
||||
};
|
||||
const hasFilePatterns = filePatterns.length > 0;
|
||||
const isWin = (0, exports.isWindows)();
|
||||
for (const changeType of Object.keys(allDiffFiles)) {
|
||||
const files = allDiffFiles[changeType];
|
||||
if (hasFilePatterns) {
|
||||
changedFiles[changeType] = (0, micromatch_1.default)(files, filePatterns, {
|
||||
dot: true,
|
||||
windows: (0, exports.isWindows)(),
|
||||
windows: isWin,
|
||||
noext: true
|
||||
});
|
||||
}
|
||||
@ -2258,7 +2287,7 @@ const getDirnameMaxDepth = ({ relativePath, dirNamesMaxDepth, excludeCurrentDir
|
||||
if (excludeCurrentDir && output === '.') {
|
||||
return '';
|
||||
}
|
||||
return normalizePath(output);
|
||||
return (0, exports.normalizeSeparators)(output);
|
||||
};
|
||||
exports.getDirnameMaxDepth = getDirnameMaxDepth;
|
||||
const jsonOutput = ({ value, shouldEscape }) => {
|
||||
@ -2266,10 +2295,16 @@ const jsonOutput = ({ value, shouldEscape }) => {
|
||||
return shouldEscape ? result.replace(/"/g, '\\"') : result;
|
||||
};
|
||||
exports.jsonOutput = jsonOutput;
|
||||
const getDirNamesIncludeFilesPattern = ({ inputs }) => {
|
||||
return inputs.dirNamesIncludeFiles
|
||||
.split(inputs.dirNamesIncludeFilesSeparator)
|
||||
.filter(Boolean);
|
||||
};
|
||||
exports.getDirNamesIncludeFilesPattern = getDirNamesIncludeFilesPattern;
|
||||
const getFilePatterns = ({ inputs, workingDirectory }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
let filePatterns = inputs.files
|
||||
.split(inputs.filesSeparator)
|
||||
.filter(p => p !== '')
|
||||
.filter(Boolean)
|
||||
.join('\n');
|
||||
if (inputs.filesFromSourceFile !== '') {
|
||||
const inputFilesFromSourceFile = inputs.filesFromSourceFile
|
||||
|
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@ -2,6 +2,7 @@ import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import type {RestEndpointMethodTypes} from '@octokit/rest'
|
||||
import flatten from 'lodash/flatten'
|
||||
import mm from 'micromatch'
|
||||
import * as path from 'path'
|
||||
|
||||
import {DiffResult} from './commitSha'
|
||||
@ -9,8 +10,10 @@ import {Inputs} from './inputs'
|
||||
import {
|
||||
getAllChangedFiles,
|
||||
getDirnameMaxDepth,
|
||||
getDirNamesIncludeFilesPattern,
|
||||
gitRenamedFiles,
|
||||
gitSubmoduleDiffSHA,
|
||||
isWindows,
|
||||
jsonOutput
|
||||
} from './utils'
|
||||
|
||||
@ -155,6 +158,35 @@ export const getAllDiffFiles = async ({
|
||||
return files
|
||||
}
|
||||
|
||||
function* getFilePaths({
|
||||
inputs,
|
||||
filePaths,
|
||||
dirNamesIncludeFilePatterns
|
||||
}: {
|
||||
inputs: Inputs
|
||||
filePaths: string[]
|
||||
dirNamesIncludeFilePatterns: string[]
|
||||
}): Generator<string> {
|
||||
for (const filePath of filePaths) {
|
||||
if (inputs.dirNames) {
|
||||
if (dirNamesIncludeFilePatterns.length > 0) {
|
||||
const isWin = isWindows()
|
||||
const matchOptions = {dot: true, windows: isWin, noext: true}
|
||||
if (mm.isMatch(filePath, dirNamesIncludeFilePatterns, matchOptions)) {
|
||||
yield filePath
|
||||
}
|
||||
}
|
||||
yield getDirnameMaxDepth({
|
||||
relativePath: filePath,
|
||||
dirNamesMaxDepth: inputs.dirNamesMaxDepth,
|
||||
excludeCurrentDir: inputs.dirNamesExcludeCurrentDir
|
||||
})
|
||||
} else {
|
||||
yield filePath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function* getChangeTypeFilesGenerator({
|
||||
inputs,
|
||||
changedFiles,
|
||||
@ -164,18 +196,21 @@ function* getChangeTypeFilesGenerator({
|
||||
changedFiles: ChangedFiles
|
||||
changeTypes: ChangeTypeEnum[]
|
||||
}): Generator<string> {
|
||||
const dirNamesIncludeFilePatterns = getDirNamesIncludeFilesPattern({inputs})
|
||||
core.debug(
|
||||
`Dir names include file patterns: ${JSON.stringify(
|
||||
dirNamesIncludeFilePatterns
|
||||
)}`
|
||||
)
|
||||
|
||||
for (const changeType of changeTypes) {
|
||||
const files = changedFiles[changeType] || []
|
||||
for (const filePath of files) {
|
||||
if (inputs.dirNames) {
|
||||
yield getDirnameMaxDepth({
|
||||
relativePath: filePath,
|
||||
dirNamesMaxDepth: inputs.dirNamesMaxDepth,
|
||||
excludeCurrentDir: inputs.dirNamesExcludeCurrentDir
|
||||
})
|
||||
} else {
|
||||
yield filePath
|
||||
}
|
||||
const filePaths = changedFiles[changeType] || []
|
||||
for (const filePath of getFilePaths({
|
||||
inputs,
|
||||
filePaths,
|
||||
dirNamesIncludeFilePatterns
|
||||
})) {
|
||||
yield filePath
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -213,16 +248,21 @@ function* getAllChangeTypeFilesGenerator({
|
||||
inputs: Inputs
|
||||
changedFiles: ChangedFiles
|
||||
}): Generator<string> {
|
||||
for (const filePath of flatten(Object.values(changedFiles))) {
|
||||
if (inputs.dirNames) {
|
||||
yield getDirnameMaxDepth({
|
||||
relativePath: filePath,
|
||||
dirNamesMaxDepth: inputs.dirNamesMaxDepth,
|
||||
excludeCurrentDir: inputs.dirNamesExcludeCurrentDir
|
||||
})
|
||||
} else {
|
||||
yield filePath
|
||||
}
|
||||
const dirNamesIncludeFilePatterns = getDirNamesIncludeFilesPattern({inputs})
|
||||
core.debug(
|
||||
`Dir names include file patterns: ${JSON.stringify(
|
||||
dirNamesIncludeFilePatterns
|
||||
)}`
|
||||
)
|
||||
|
||||
const filePaths = flatten(Object.values(changedFiles))
|
||||
|
||||
for (const filePath of getFilePaths({
|
||||
inputs,
|
||||
filePaths,
|
||||
dirNamesIncludeFilePatterns
|
||||
})) {
|
||||
yield filePath
|
||||
}
|
||||
}
|
||||
|
||||
@ -309,5 +349,6 @@ export const getChangedFilesFromGithubAPI = async ({
|
||||
changedFiles[changeType].push(item.filename)
|
||||
}
|
||||
}
|
||||
|
||||
return changedFiles
|
||||
}
|
||||
|
@ -29,6 +29,8 @@ export type Inputs = {
|
||||
dirNames: boolean
|
||||
dirNamesMaxDepth?: number
|
||||
dirNamesExcludeCurrentDir: boolean
|
||||
dirNamesIncludeFiles: string
|
||||
dirNamesIncludeFilesSeparator: string
|
||||
json: boolean
|
||||
escapeJson: boolean
|
||||
fetchDepth?: number
|
||||
@ -135,6 +137,16 @@ export const getInputs = (): Inputs => {
|
||||
required: false
|
||||
}
|
||||
)
|
||||
const dirNamesIncludeFiles = core.getInput('dir_names_include_files', {
|
||||
required: false
|
||||
})
|
||||
const dirNamesIncludeFilesSeparator = core.getInput(
|
||||
'dir_names_include_files_separator',
|
||||
{
|
||||
required: false,
|
||||
trimWhitespace: false
|
||||
}
|
||||
)
|
||||
const json = core.getBooleanInput('json', {required: false})
|
||||
const escapeJson = core.getBooleanInput('escape_json', {required: false})
|
||||
const fetchDepth = core.getInput('fetch_depth', {required: false})
|
||||
@ -212,17 +224,19 @@ export const getInputs = (): Inputs => {
|
||||
includeAllOldNewRenamedFiles,
|
||||
oldNewSeparator,
|
||||
oldNewFilesSeparator,
|
||||
skipInitialFetch,
|
||||
// End Not Supported via REST API
|
||||
dirNames,
|
||||
dirNamesExcludeCurrentDir,
|
||||
dirNamesIncludeFiles,
|
||||
dirNamesIncludeFilesSeparator,
|
||||
json,
|
||||
escapeJson,
|
||||
writeOutputFiles,
|
||||
outputDir,
|
||||
outputRenamedFilesAsDeletedAndAdded,
|
||||
token,
|
||||
apiUrl,
|
||||
skipInitialFetch
|
||||
apiUrl
|
||||
}
|
||||
|
||||
if (fetchDepth) {
|
||||
|
16
src/main.ts
16
src/main.ts
@ -11,8 +11,8 @@ import {
|
||||
import {setChangedFilesOutput} from './changedFilesOutput'
|
||||
import {
|
||||
DiffResult,
|
||||
getSHAForPullRequestEvent,
|
||||
getSHAForNonPullRequestEvent
|
||||
getSHAForNonPullRequestEvent,
|
||||
getSHAForPullRequestEvent
|
||||
} from './commitSha'
|
||||
import {Env, getEnv} from './env'
|
||||
import {getInputs, Inputs} from './inputs'
|
||||
@ -311,10 +311,20 @@ export async function run(): Promise<void> {
|
||||
'baseSha',
|
||||
'since',
|
||||
'until',
|
||||
'path',
|
||||
'quotePath',
|
||||
'diffRelative',
|
||||
'sinceLastRemoteCommit',
|
||||
'recoverDeletedFiles',
|
||||
'recoverDeletedFilesToDestination',
|
||||
'includeAllOldNewRenamedFiles'
|
||||
'recoverFiles',
|
||||
'recoverFilesSeparator',
|
||||
'recoverFilesIgnore',
|
||||
'recoverFilesIgnoreSeparator',
|
||||
'includeAllOldNewRenamedFiles',
|
||||
'oldNewSeparator',
|
||||
'oldNewFilesSeparator',
|
||||
'skipInitialFetch'
|
||||
]
|
||||
|
||||
for (const input of unsupportedInputs) {
|
||||
|
48
src/utils.ts
48
src/utils.ts
@ -38,15 +38,6 @@ export const normalizeSeparators = (p: string): string => {
|
||||
return p.replace(/\/\/+/g, '/')
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize file path separators to '/' on all platforms
|
||||
* @param p - file path
|
||||
* @returns file path with normalized separators
|
||||
*/
|
||||
const normalizePath = (p: string): string => {
|
||||
return p.replace(/\\/g, '/')
|
||||
}
|
||||
|
||||
/**
|
||||
* Trims unnecessary trailing slash from file path
|
||||
* @param p - file path
|
||||
@ -365,7 +356,7 @@ export const getSubmodulePath = async ({
|
||||
return stdout
|
||||
.trim()
|
||||
.split('\n')
|
||||
.map((line: string) => normalizePath(line.trim().split(' ')[1]))
|
||||
.map((line: string) => normalizeSeparators(line.trim().split(' ')[1]))
|
||||
}
|
||||
|
||||
/**
|
||||
@ -478,13 +469,15 @@ export const gitRenamedFiles = async ({
|
||||
core.debug(`Renamed file: ${line}`)
|
||||
const [, oldPath, newPath] = line.split('\t')
|
||||
if (isSubmodule) {
|
||||
return `${normalizePath(
|
||||
return `${normalizeSeparators(
|
||||
path.join(parentDir, oldPath)
|
||||
)}${oldNewSeparator}${normalizePath(path.join(parentDir, newPath))}`
|
||||
)}${oldNewSeparator}${normalizeSeparators(
|
||||
path.join(parentDir, newPath)
|
||||
)}`
|
||||
}
|
||||
return `${normalizePath(oldPath)}${oldNewSeparator}${normalizePath(
|
||||
newPath
|
||||
)}`
|
||||
return `${normalizeSeparators(
|
||||
oldPath
|
||||
)}${oldNewSeparator}${normalizeSeparators(newPath)}`
|
||||
})
|
||||
}
|
||||
|
||||
@ -564,11 +557,11 @@ export const getAllChangedFiles = async ({
|
||||
for (const line of lines) {
|
||||
const [changeType, filePath, newPath = ''] = line.split('\t')
|
||||
const normalizedFilePath = isSubmodule
|
||||
? normalizePath(path.join(parentDir, filePath))
|
||||
: normalizePath(filePath)
|
||||
? normalizeSeparators(path.join(parentDir, filePath))
|
||||
: normalizeSeparators(filePath)
|
||||
const normalizedNewPath = isSubmodule
|
||||
? normalizePath(path.join(parentDir, newPath))
|
||||
: normalizePath(newPath)
|
||||
? normalizeSeparators(path.join(parentDir, newPath))
|
||||
: normalizeSeparators(newPath)
|
||||
|
||||
if (changeType.startsWith('R')) {
|
||||
if (outputRenamedFilesAsDeletedAndAdded) {
|
||||
@ -607,13 +600,14 @@ export const getFilteredChangedFiles = async ({
|
||||
[ChangeTypeEnum.Unknown]: []
|
||||
}
|
||||
const hasFilePatterns = filePatterns.length > 0
|
||||
const isWin = isWindows()
|
||||
|
||||
for (const changeType of Object.keys(allDiffFiles)) {
|
||||
const files = allDiffFiles[changeType as ChangeTypeEnum]
|
||||
if (hasFilePatterns) {
|
||||
changedFiles[changeType as ChangeTypeEnum] = mm(files, filePatterns, {
|
||||
dot: true,
|
||||
windows: isWindows(),
|
||||
windows: isWin,
|
||||
noext: true
|
||||
})
|
||||
} else {
|
||||
@ -873,7 +867,7 @@ export const getDirnameMaxDepth = ({
|
||||
return ''
|
||||
}
|
||||
|
||||
return normalizePath(output)
|
||||
return normalizeSeparators(output)
|
||||
}
|
||||
|
||||
export const jsonOutput = ({
|
||||
@ -888,6 +882,16 @@ export const jsonOutput = ({
|
||||
return shouldEscape ? result.replace(/"/g, '\\"') : result
|
||||
}
|
||||
|
||||
export const getDirNamesIncludeFilesPattern = ({
|
||||
inputs
|
||||
}: {
|
||||
inputs: Inputs
|
||||
}): string[] => {
|
||||
return inputs.dirNamesIncludeFiles
|
||||
.split(inputs.dirNamesIncludeFilesSeparator)
|
||||
.filter(Boolean)
|
||||
}
|
||||
|
||||
export const getFilePatterns = async ({
|
||||
inputs,
|
||||
workingDirectory
|
||||
@ -897,7 +901,7 @@ export const getFilePatterns = async ({
|
||||
}): Promise<string[]> => {
|
||||
let filePatterns = inputs.files
|
||||
.split(inputs.filesSeparator)
|
||||
.filter(p => p !== '')
|
||||
.filter(Boolean)
|
||||
.join('\n')
|
||||
|
||||
if (inputs.filesFromSourceFile !== '') {
|
||||
|
Loading…
x
Reference in New Issue
Block a user