Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9124514c3 | ||
|
|
90ef0b1b22 | ||
|
|
c648759d89 | ||
|
|
b9ea510e42 |
35
.github/workflows/test.yml
vendored
35
.github/workflows/test.yml
vendored
@@ -869,6 +869,41 @@ jobs:
|
||||
exit 1
|
||||
shell:
|
||||
bash
|
||||
- name: Run changed-files for old new filenames test rename 2 output as deleted and added
|
||||
id: changed-files-all-old-new-renamed-files-2-output-as-deleted-and-added
|
||||
uses: ./
|
||||
with:
|
||||
base_sha: 4d04215
|
||||
sha: fe238e6
|
||||
fetch_depth: 60000
|
||||
include_all_old_new_renamed_files: true
|
||||
output_renamed_files_as_deleted_and_added: true
|
||||
- name: Show output
|
||||
run: |
|
||||
echo '${{ toJSON(steps.changed-files-all-old-new-renamed-files-2-output-as-deleted-and-added.outputs) }}'
|
||||
shell:
|
||||
bash
|
||||
- name: Check all_old_new_renamed_files output
|
||||
if: "!contains(steps.changed-files-all-old-new-renamed-files-2-output-as-deleted-and-added.outputs.all_old_new_renamed_files, 'test/test rename 2.txt,test/test rename-2.txt')"
|
||||
run: |
|
||||
echo "Invalid output: Expected to include (test/test rename 2.txt test/test rename-2.txt) got (${{ steps.changed-files-all-old-new-renamed-files-2-output-as-deleted-and-added.outputs.all_old_new_renamed_files }})"
|
||||
exit 1
|
||||
shell:
|
||||
bash
|
||||
- name: Check deleted_files output
|
||||
if: "!contains(steps.changed-files-all-old-new-renamed-files-2-output-as-deleted-and-added.outputs.deleted_files, 'test/test rename 2.txt')"
|
||||
run: |
|
||||
echo "Invalid output: Expected to include (test/test rename 2.txt) got (${{ steps.changed-files-all-old-new-renamed-files-2-output-as-deleted-and-added.outputs.deleted_files }})"
|
||||
exit 1
|
||||
shell:
|
||||
bash
|
||||
- name: Check added_files output
|
||||
if: "!contains(steps.changed-files-all-old-new-renamed-files-2-output-as-deleted-and-added.outputs.added_files, 'test/test rename-2.txt')"
|
||||
run: |
|
||||
echo "Invalid output: Expected to include (test/test rename-2.txt) got (${{ steps.changed-files-all-old-new-renamed-files-2-output-as-deleted-and-added.outputs.added_files }})"
|
||||
exit 1
|
||||
shell:
|
||||
bash
|
||||
- name: Run changed-files with specific files
|
||||
id: changed-files-specific
|
||||
uses: ./
|
||||
|
||||
44
HISTORY.md
44
HISTORY.md
@@ -1,5 +1,49 @@
|
||||
# Changelog
|
||||
|
||||
# [36.2.0](https://github.com/tj-actions/changed-files/compare/v36.1.0...v36.2.0) - (2023-06-14)
|
||||
|
||||
## <!-- 0 -->🚀 Features
|
||||
|
||||
- Switch to use name status ([#1230](https://github.com/tj-actions/changed-files/issues/1230)) ([174a2a6](https://github.com/tj-actions/changed-files/commit/174a2a6360b54a2019877c254c4be78106efc94f)) - (Tonye Jack)
|
||||
|
||||
## <!-- 26 -->🔄 Update
|
||||
|
||||
- Updated README.md ([#1255](https://github.com/tj-actions/changed-files/issues/1255))
|
||||
|
||||
Co-authored-by: jackton1 <jackton1@users.noreply.github.com> ([2c6893c](https://github.com/tj-actions/changed-files/commit/2c6893c21a91f8238df9e0ed2f3e4488efc0629f)) - (tj-actions[bot])
|
||||
- Update action.yml ([17ca5bb](https://github.com/tj-actions/changed-files/commit/17ca5bb3e554d4d9b631e09414186b64b6e64cd6)) - (Tonye Jack)
|
||||
- Updated README.md ([#1249](https://github.com/tj-actions/changed-files/issues/1249))
|
||||
|
||||
Co-authored-by: jackton1 <jackton1@users.noreply.github.com> ([a625ca3](https://github.com/tj-actions/changed-files/commit/a625ca325f498d75648b0ec941834edc16e71a40)) - (tj-actions[bot])
|
||||
- Updated README.md ([#1248](https://github.com/tj-actions/changed-files/issues/1248))
|
||||
|
||||
Co-authored-by: jackton1 <jackton1@users.noreply.github.com>
|
||||
Co-authored-by: Tonye Jack <jtonye@ymail.com> ([752970e](https://github.com/tj-actions/changed-files/commit/752970edd01e2a1b9e1a9ef37207bd59a34c90f4)) - (tj-actions[bot])
|
||||
- Update action.yml ([7b64c76](https://github.com/tj-actions/changed-files/commit/7b64c76932d2ddd0a2be638832dc8f72eacec74c)) - (Tonye Jack)
|
||||
- Updated README.md ([#1246](https://github.com/tj-actions/changed-files/issues/1246))
|
||||
|
||||
Co-authored-by: repo-ranger[bot] <repo-ranger[bot]@users.noreply.github.com> ([9333a5c](https://github.com/tj-actions/changed-files/commit/9333a5cf0c1a85e3dd5876284bb075ade076a9e0)) - (tj-actions[bot])
|
||||
|
||||
## <!-- 7 -->⚙️ Miscellaneous Tasks
|
||||
|
||||
- **deps:** Update peter-evans/create-pull-request action to v5.0.2 ([#1256](https://github.com/tj-actions/changed-files/issues/1256)) ([2d0b52f](https://github.com/tj-actions/changed-files/commit/2d0b52f4408b791c0c5c1eca405d8461b320dd01)) - (renovate[bot])
|
||||
- **deps:** Update typescript-eslint monorepo to v5.59.11 ([#1253](https://github.com/tj-actions/changed-files/issues/1253)) ([d0e3a7c](https://github.com/tj-actions/changed-files/commit/d0e3a7c3aa15c15ace59f95a9fda1bcadf9ab3e2)) - (renovate[bot])
|
||||
- **deps:** Lock file maintenance ([#1252](https://github.com/tj-actions/changed-files/issues/1252)) ([61845c2](https://github.com/tj-actions/changed-files/commit/61845c2b19ec2ad7e3d79a6955e192e66d41cb80)) - (renovate[bot])
|
||||
- **deps:** Update tj-actions/verify-changed-files action to v15 ([#1251](https://github.com/tj-actions/changed-files/issues/1251)) ([417f924](https://github.com/tj-actions/changed-files/commit/417f924dea3b9800ea861d576eee55162ab6607c)) - (renovate[bot])
|
||||
- **deps:** Lock file maintenance ([#1250](https://github.com/tj-actions/changed-files/issues/1250)) ([c51a48d](https://github.com/tj-actions/changed-files/commit/c51a48d4f6bf95820aa0f9e3f3e6516bd427ae7a)) - (renovate[bot])
|
||||
- Update README.md ([6d9ee62](https://github.com/tj-actions/changed-files/commit/6d9ee62035acb0c3942fba9757033c677246f2f4)) - (Tonye Jack)
|
||||
- Update README.md ([b27dcc2](https://github.com/tj-actions/changed-files/commit/b27dcc252ada558d34ecd368bd253994df77acb1)) - (Tonye Jack)
|
||||
- **deps:** Update dependency @types/uuid to v9.0.2 ([#1247](https://github.com/tj-actions/changed-files/issues/1247)) ([b60e479](https://github.com/tj-actions/changed-files/commit/b60e479ceab551d9a8f832d5a989eb3e492d4bf4)) - (renovate[bot])
|
||||
- Update README.md ([#1237](https://github.com/tj-actions/changed-files/issues/1237)) ([8ec721e](https://github.com/tj-actions/changed-files/commit/8ec721eb3b7d57b7afc0d63748bd7242292989b1)) - (tj-actions[bot])
|
||||
- Update README.md ([#1240](https://github.com/tj-actions/changed-files/issues/1240)) ([7d1d4d2](https://github.com/tj-actions/changed-files/commit/7d1d4d2cce628fd1797af3acb779dd1d26b61d31)) - (tj-actions[bot])
|
||||
|
||||
## <!-- 9 -->⬆️ Upgrades
|
||||
|
||||
- Upgraded to v36.1.0 ([#1245](https://github.com/tj-actions/changed-files/issues/1245))
|
||||
|
||||
Co-authored-by: jackton1 <jackton1@users.noreply.github.com>
|
||||
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com> ([ab84931](https://github.com/tj-actions/changed-files/commit/ab8493166b33b74edc5101f3e814b63cd87f05ab)) - (tj-actions[bot])
|
||||
|
||||
# [36.1.0](https://github.com/tj-actions/changed-files/compare/v36.0.18...v36.1.0) - (2023-06-08)
|
||||
|
||||
## <!-- 0 -->🚀 Features
|
||||
|
||||
@@ -225,6 +225,7 @@ Support this project with a :star:
|
||||
| old\_new\_files\_separator | string | false | `" "` | Split character for old and <br>new renamed filename pairs. |
|
||||
| old\_new\_separator | string | false | `","` | Split character for old and <br>new filename pairs. |
|
||||
| output\_dir | string | false | `".github/outputs"` | Directory to store output files. |
|
||||
| output\_renamed\_files\_as\_deleted\_and\_added | string | false | `"false"` | Output renamed files as deleted <br>and added files. |
|
||||
| path | string | false | `"."` | Specify a relative path under <br>`$GITHUB_WORKSPACE` to locate the repository. |
|
||||
| quotepath | string | false | `"true"` | Use non ascii characters to <br>match files and output the <br>filenames completely verbatim by setting <br>this to `false` |
|
||||
| separator | string | false | `" "` | Split character for output strings |
|
||||
|
||||
@@ -117,6 +117,10 @@ inputs:
|
||||
description: "Directory to store output files."
|
||||
required: false
|
||||
default: ".github/outputs"
|
||||
output_renamed_files_as_deleted_and_added:
|
||||
description: "Output renamed files as deleted and added files."
|
||||
required: false
|
||||
default: "false"
|
||||
|
||||
outputs:
|
||||
added_files:
|
||||
|
||||
70
dist/index.js
generated
vendored
70
dist/index.js
generated
vendored
@@ -95,12 +95,13 @@ var ChangeTypeEnum;
|
||||
ChangeTypeEnum["Unmerged"] = "U";
|
||||
ChangeTypeEnum["Unknown"] = "X";
|
||||
})(ChangeTypeEnum || (exports.ChangeTypeEnum = ChangeTypeEnum = {}));
|
||||
const getAllDiffFiles = ({ workingDirectory, hasSubmodule, diffResult, submodulePaths }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const getAllDiffFiles = ({ workingDirectory, hasSubmodule, diffResult, submodulePaths, outputRenamedFilesAsDeletedAndAdded }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const files = yield (0, utils_1.getAllChangedFiles)({
|
||||
cwd: workingDirectory,
|
||||
sha1: diffResult.previousSha,
|
||||
sha2: diffResult.currentSha,
|
||||
diff: diffResult.diff
|
||||
diff: diffResult.diff,
|
||||
outputRenamedFilesAsDeletedAndAdded
|
||||
});
|
||||
if (hasSubmodule) {
|
||||
for (const submodulePath of submodulePaths) {
|
||||
@@ -119,7 +120,8 @@ const getAllDiffFiles = ({ workingDirectory, hasSubmodule, diffResult, submodule
|
||||
sha2: submoduleShaResult.currentSha,
|
||||
diff: diffResult.diff,
|
||||
isSubmodule: true,
|
||||
parentDir: submodulePath
|
||||
parentDir: submodulePath,
|
||||
outputRenamedFilesAsDeletedAndAdded
|
||||
});
|
||||
for (const changeType of Object.keys(submoduleFiles)) {
|
||||
if (!files[changeType]) {
|
||||
@@ -272,7 +274,7 @@ const getCurrentSHA = ({ env, inputs, workingDirectory }) => __awaiter(void 0, v
|
||||
core.debug(`Current SHA: ${currentSha}`);
|
||||
return currentSha;
|
||||
});
|
||||
const getSHAForPushEvent = (inputs, env, workingDirectory, isShallow, hasSubmodule, gitExtraArgs, isTag) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const getSHAForPushEvent = (inputs, env, workingDirectory, isShallow, hasSubmodule, gitFetchExtraArgs, isTag) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
let targetBranch = env.GITHUB_REF_NAME;
|
||||
const currentBranch = targetBranch;
|
||||
let initialCommit = false;
|
||||
@@ -284,7 +286,7 @@ const getSHAForPushEvent = (inputs, env, workingDirectory, isShallow, hasSubmodu
|
||||
yield (0, utils_1.gitFetch)({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
...gitExtraArgs,
|
||||
...gitFetchExtraArgs,
|
||||
'-u',
|
||||
'--progress',
|
||||
`--deepen=${inputs.fetchDepth}`,
|
||||
@@ -297,7 +299,7 @@ const getSHAForPushEvent = (inputs, env, workingDirectory, isShallow, hasSubmodu
|
||||
yield (0, utils_1.gitFetch)({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
...gitExtraArgs,
|
||||
...gitFetchExtraArgs,
|
||||
'-u',
|
||||
'--progress',
|
||||
`--deepen=${inputs.fetchDepth}`,
|
||||
@@ -310,7 +312,7 @@ const getSHAForPushEvent = (inputs, env, workingDirectory, isShallow, hasSubmodu
|
||||
yield (0, utils_1.gitFetchSubmodules)({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
...gitExtraArgs,
|
||||
...gitFetchExtraArgs,
|
||||
'-u',
|
||||
'--progress',
|
||||
`--deepen=${inputs.fetchDepth}`
|
||||
@@ -414,7 +416,7 @@ const getSHAForPushEvent = (inputs, env, workingDirectory, isShallow, hasSubmodu
|
||||
};
|
||||
});
|
||||
exports.getSHAForPushEvent = getSHAForPushEvent;
|
||||
const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, hasSubmodule, gitExtraArgs) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, hasSubmodule, gitFetchExtraArgs) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
let targetBranch = env.GITHUB_EVENT_PULL_REQUEST_BASE_REF;
|
||||
const currentBranch = env.GITHUB_EVENT_PULL_REQUEST_HEAD_REF;
|
||||
if (inputs.sinceLastRemoteCommit) {
|
||||
@@ -425,7 +427,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
|
||||
let prFetchExitCode = yield (0, utils_1.gitFetch)({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
...gitExtraArgs,
|
||||
...gitFetchExtraArgs,
|
||||
'-u',
|
||||
'--progress',
|
||||
'origin',
|
||||
@@ -436,7 +438,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
|
||||
prFetchExitCode = yield (0, utils_1.gitFetch)({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
...gitExtraArgs,
|
||||
...gitFetchExtraArgs,
|
||||
'-u',
|
||||
'--progress',
|
||||
`--deepen=${inputs.fetchDepth}`,
|
||||
@@ -453,7 +455,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
|
||||
yield (0, utils_1.gitFetch)({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
...gitExtraArgs,
|
||||
...gitFetchExtraArgs,
|
||||
'-u',
|
||||
'--progress',
|
||||
`--deepen=${inputs.fetchDepth}`,
|
||||
@@ -465,7 +467,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
|
||||
yield (0, utils_1.gitFetchSubmodules)({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
...gitExtraArgs,
|
||||
...gitFetchExtraArgs,
|
||||
'-u',
|
||||
'--progress',
|
||||
`--deepen=${inputs.fetchDepth}`
|
||||
@@ -500,12 +502,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
|
||||
}
|
||||
if (!previousSha) {
|
||||
if (inputs.sinceLastRemoteCommit) {
|
||||
previousSha =
|
||||
env.GITHUB_EVENT_BEFORE ||
|
||||
(yield (0, utils_1.getRemoteBranchHeadSha)({
|
||||
cwd: workingDirectory,
|
||||
branch: currentBranch
|
||||
}));
|
||||
previousSha = env.GITHUB_EVENT_BEFORE;
|
||||
if (!previousSha ||
|
||||
(previousSha &&
|
||||
(yield (0, utils_1.verifyCommitSha)({ sha: previousSha, cwd: workingDirectory })) !==
|
||||
@@ -534,7 +531,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
|
||||
yield (0, utils_1.gitFetch)({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
...gitExtraArgs,
|
||||
...gitFetchExtraArgs,
|
||||
'-u',
|
||||
'--progress',
|
||||
`--deepen=${inputs.fetchDepth}`,
|
||||
@@ -776,6 +773,7 @@ const getInputs = () => {
|
||||
required: false
|
||||
});
|
||||
const outputDir = core.getInput('output_dir', { required: false });
|
||||
const outputRenamedFilesAsDeletedAndAdded = core.getBooleanInput('output_renamed_files_as_deleted_and_added', { required: false });
|
||||
const inputs = {
|
||||
files,
|
||||
filesSeparator,
|
||||
@@ -803,7 +801,8 @@ const getInputs = () => {
|
||||
escapeJson,
|
||||
sinceLastRemoteCommit,
|
||||
writeOutputFiles,
|
||||
outputDir
|
||||
outputDir,
|
||||
outputRenamedFilesAsDeletedAndAdded
|
||||
};
|
||||
if (fetchDepth) {
|
||||
inputs.fetchDepth = Math.max(parseInt(fetchDepth, 10), 2);
|
||||
@@ -893,23 +892,24 @@ function run() {
|
||||
const workingDirectory = path_1.default.resolve(env.GITHUB_WORKSPACE || process.cwd(), inputs.path);
|
||||
const isShallow = yield (0, utils_1.isRepoShallow)({ cwd: workingDirectory });
|
||||
const hasSubmodule = yield (0, utils_1.submoduleExists)({ cwd: workingDirectory });
|
||||
let gitExtraArgs = ['--no-tags', '--prune', '--recurse-submodules'];
|
||||
let gitFetchExtraArgs = ['--no-tags', '--prune', '--recurse-submodules'];
|
||||
const isTag = (_a = env.GITHUB_REF) === null || _a === void 0 ? void 0 : _a.startsWith('refs/tags/');
|
||||
const outputRenamedFilesAsDeletedAndAdded = inputs.outputRenamedFilesAsDeletedAndAdded;
|
||||
let submodulePaths = [];
|
||||
if (hasSubmodule) {
|
||||
submodulePaths = yield (0, utils_1.getSubmodulePath)({ cwd: workingDirectory });
|
||||
}
|
||||
if (isTag) {
|
||||
gitExtraArgs = ['--prune', '--no-recurse-submodules'];
|
||||
gitFetchExtraArgs = ['--prune', '--no-recurse-submodules'];
|
||||
}
|
||||
let diffResult;
|
||||
if (!env.GITHUB_EVENT_PULL_REQUEST_BASE_REF) {
|
||||
core.info(`Running on a ${env.GITHUB_EVENT_NAME || 'push'} event...`);
|
||||
diffResult = yield (0, commitSha_1.getSHAForPushEvent)(inputs, env, workingDirectory, isShallow, hasSubmodule, gitExtraArgs, isTag);
|
||||
diffResult = yield (0, commitSha_1.getSHAForPushEvent)(inputs, env, workingDirectory, isShallow, hasSubmodule, gitFetchExtraArgs, isTag);
|
||||
}
|
||||
else {
|
||||
core.info(`Running on a ${env.GITHUB_EVENT_NAME || 'pull_request'} event...`);
|
||||
diffResult = yield (0, commitSha_1.getSHAForPullRequestEvent)(inputs, env, workingDirectory, isShallow, hasSubmodule, gitExtraArgs);
|
||||
diffResult = yield (0, commitSha_1.getSHAForPullRequestEvent)(inputs, env, workingDirectory, isShallow, hasSubmodule, gitFetchExtraArgs);
|
||||
}
|
||||
if (diffResult.initialCommit) {
|
||||
core.info('This is the first commit for this repository; exiting...');
|
||||
@@ -926,7 +926,8 @@ function run() {
|
||||
workingDirectory,
|
||||
hasSubmodule,
|
||||
diffResult,
|
||||
submodulePaths
|
||||
submodulePaths,
|
||||
outputRenamedFilesAsDeletedAndAdded
|
||||
});
|
||||
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`);
|
||||
const allFilteredDiffFiles = yield (0, utils_1.getFilteredChangedFiles)({
|
||||
@@ -1055,7 +1056,7 @@ function run() {
|
||||
core.debug(`All other changed files: ${allOtherChangedFiles}`);
|
||||
const otherChangedFiles = allOtherChangedFiles
|
||||
.split(inputs.separator)
|
||||
.filter(filePath => !allChangedFiles.split(inputs.separator).includes(filePath));
|
||||
.filter((filePath) => !allChangedFiles.split(inputs.separator).includes(filePath));
|
||||
const onlyChanged = otherChangedFiles.length === 0 &&
|
||||
allChangedFiles.length > 0 &&
|
||||
filePatterns.length > 0;
|
||||
@@ -1104,7 +1105,7 @@ function run() {
|
||||
});
|
||||
const otherModifiedFiles = allOtherModifiedFiles
|
||||
.split(inputs.separator)
|
||||
.filter(filePath => !allModifiedFiles.split(inputs.separator).includes(filePath));
|
||||
.filter((filePath) => !allModifiedFiles.split(inputs.separator).includes(filePath));
|
||||
const onlyModified = otherModifiedFiles.length === 0 &&
|
||||
allModifiedFiles.length > 0 &&
|
||||
filePatterns.length > 0;
|
||||
@@ -1530,7 +1531,7 @@ const gitRenamedFiles = ({ cwd, sha1, sha2, diff, oldNewSeparator, isSubmodule =
|
||||
});
|
||||
});
|
||||
exports.gitRenamedFiles = gitRenamedFiles;
|
||||
const getAllChangedFiles = ({ cwd, sha1, sha2, diff, isSubmodule = false, parentDir = '' }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const getAllChangedFiles = ({ cwd, sha1, sha2, diff, isSubmodule = false, parentDir = '', outputRenamedFilesAsDeletedAndAdded = false }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const { exitCode, stdout, stderr } = yield exec.getExecOutput('git', [
|
||||
'diff',
|
||||
'--name-status',
|
||||
@@ -1565,12 +1566,21 @@ const getAllChangedFiles = ({ cwd, sha1, sha2, diff, isSubmodule = false, parent
|
||||
}
|
||||
const lines = stdout.split('\n').filter(Boolean);
|
||||
for (const line of lines) {
|
||||
const [changeType, filePath] = line.split('\t');
|
||||
const [changeType, filePath, newPath = ''] = line.split('\t');
|
||||
const normalizedFilePath = isSubmodule
|
||||
? normalizePath(path.join(parentDir, filePath))
|
||||
: normalizePath(filePath);
|
||||
const normalizedNewPath = isSubmodule
|
||||
? normalizePath(path.join(parentDir, newPath))
|
||||
: normalizePath(newPath);
|
||||
if (changeType.startsWith('R')) {
|
||||
changedFiles[changedFiles_1.ChangeTypeEnum.Renamed].push(normalizedFilePath);
|
||||
if (outputRenamedFilesAsDeletedAndAdded) {
|
||||
changedFiles[changedFiles_1.ChangeTypeEnum.Deleted].push(normalizedFilePath);
|
||||
changedFiles[changedFiles_1.ChangeTypeEnum.Added].push(normalizedNewPath);
|
||||
}
|
||||
else {
|
||||
changedFiles[changedFiles_1.ChangeTypeEnum.Renamed].push(normalizedFilePath);
|
||||
}
|
||||
}
|
||||
else {
|
||||
changedFiles[changeType].push(normalizedFilePath);
|
||||
|
||||
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
@@ -88,18 +88,21 @@ export const getAllDiffFiles = async ({
|
||||
workingDirectory,
|
||||
hasSubmodule,
|
||||
diffResult,
|
||||
submodulePaths
|
||||
submodulePaths,
|
||||
outputRenamedFilesAsDeletedAndAdded
|
||||
}: {
|
||||
workingDirectory: string
|
||||
hasSubmodule: boolean
|
||||
diffResult: DiffResult
|
||||
submodulePaths: string[]
|
||||
outputRenamedFilesAsDeletedAndAdded: boolean
|
||||
}): Promise<ChangedFiles> => {
|
||||
const files = await getAllChangedFiles({
|
||||
cwd: workingDirectory,
|
||||
sha1: diffResult.previousSha,
|
||||
sha2: diffResult.currentSha,
|
||||
diff: diffResult.diff
|
||||
diff: diffResult.diff,
|
||||
outputRenamedFilesAsDeletedAndAdded
|
||||
})
|
||||
|
||||
if (hasSubmodule) {
|
||||
@@ -124,7 +127,8 @@ export const getAllDiffFiles = async ({
|
||||
sha2: submoduleShaResult.currentSha,
|
||||
diff: diffResult.diff,
|
||||
isSubmodule: true,
|
||||
parentDir: submodulePath
|
||||
parentDir: submodulePath,
|
||||
outputRenamedFilesAsDeletedAndAdded
|
||||
})
|
||||
|
||||
for (const changeType of Object.keys(
|
||||
|
||||
@@ -85,7 +85,7 @@ export const getSHAForPushEvent = async (
|
||||
workingDirectory: string,
|
||||
isShallow: boolean,
|
||||
hasSubmodule: boolean,
|
||||
gitExtraArgs: string[],
|
||||
gitFetchExtraArgs: string[],
|
||||
isTag: boolean
|
||||
): Promise<DiffResult> => {
|
||||
let targetBranch = env.GITHUB_REF_NAME
|
||||
@@ -102,7 +102,7 @@ export const getSHAForPushEvent = async (
|
||||
await gitFetch({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
...gitExtraArgs,
|
||||
...gitFetchExtraArgs,
|
||||
'-u',
|
||||
'--progress',
|
||||
`--deepen=${inputs.fetchDepth}`,
|
||||
@@ -114,7 +114,7 @@ export const getSHAForPushEvent = async (
|
||||
await gitFetch({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
...gitExtraArgs,
|
||||
...gitFetchExtraArgs,
|
||||
'-u',
|
||||
'--progress',
|
||||
`--deepen=${inputs.fetchDepth}`,
|
||||
@@ -128,7 +128,7 @@ export const getSHAForPushEvent = async (
|
||||
await gitFetchSubmodules({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
...gitExtraArgs,
|
||||
...gitFetchExtraArgs,
|
||||
'-u',
|
||||
'--progress',
|
||||
`--deepen=${inputs.fetchDepth}`
|
||||
@@ -263,7 +263,7 @@ export const getSHAForPullRequestEvent = async (
|
||||
workingDirectory: string,
|
||||
isShallow: boolean,
|
||||
hasSubmodule: boolean,
|
||||
gitExtraArgs: string[]
|
||||
gitFetchExtraArgs: string[]
|
||||
): Promise<DiffResult> => {
|
||||
let targetBranch = env.GITHUB_EVENT_PULL_REQUEST_BASE_REF
|
||||
const currentBranch = env.GITHUB_EVENT_PULL_REQUEST_HEAD_REF
|
||||
@@ -277,7 +277,7 @@ export const getSHAForPullRequestEvent = async (
|
||||
let prFetchExitCode = await gitFetch({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
...gitExtraArgs,
|
||||
...gitFetchExtraArgs,
|
||||
'-u',
|
||||
'--progress',
|
||||
'origin',
|
||||
@@ -289,7 +289,7 @@ export const getSHAForPullRequestEvent = async (
|
||||
prFetchExitCode = await gitFetch({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
...gitExtraArgs,
|
||||
...gitFetchExtraArgs,
|
||||
'-u',
|
||||
'--progress',
|
||||
`--deepen=${inputs.fetchDepth}`,
|
||||
@@ -310,7 +310,7 @@ export const getSHAForPullRequestEvent = async (
|
||||
await gitFetch({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
...gitExtraArgs,
|
||||
...gitFetchExtraArgs,
|
||||
'-u',
|
||||
'--progress',
|
||||
`--deepen=${inputs.fetchDepth}`,
|
||||
@@ -323,7 +323,7 @@ export const getSHAForPullRequestEvent = async (
|
||||
await gitFetchSubmodules({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
...gitExtraArgs,
|
||||
...gitFetchExtraArgs,
|
||||
'-u',
|
||||
'--progress',
|
||||
`--deepen=${inputs.fetchDepth}`
|
||||
@@ -370,12 +370,7 @@ export const getSHAForPullRequestEvent = async (
|
||||
|
||||
if (!previousSha) {
|
||||
if (inputs.sinceLastRemoteCommit) {
|
||||
previousSha =
|
||||
env.GITHUB_EVENT_BEFORE ||
|
||||
(await getRemoteBranchHeadSha({
|
||||
cwd: workingDirectory,
|
||||
branch: currentBranch
|
||||
}))
|
||||
previousSha = env.GITHUB_EVENT_BEFORE
|
||||
|
||||
if (
|
||||
!previousSha ||
|
||||
@@ -415,7 +410,7 @@ export const getSHAForPullRequestEvent = async (
|
||||
await gitFetch({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
...gitExtraArgs,
|
||||
...gitFetchExtraArgs,
|
||||
'-u',
|
||||
'--progress',
|
||||
`--deepen=${inputs.fetchDepth}`,
|
||||
|
||||
@@ -30,6 +30,7 @@ export type Inputs = {
|
||||
sinceLastRemoteCommit: boolean
|
||||
writeOutputFiles: boolean
|
||||
outputDir: string
|
||||
outputRenamedFilesAsDeletedAndAdded: boolean
|
||||
}
|
||||
|
||||
export const getInputs = (): Inputs => {
|
||||
@@ -111,6 +112,10 @@ export const getInputs = (): Inputs => {
|
||||
required: false
|
||||
})
|
||||
const outputDir = core.getInput('output_dir', {required: false})
|
||||
const outputRenamedFilesAsDeletedAndAdded = core.getBooleanInput(
|
||||
'output_renamed_files_as_deleted_and_added',
|
||||
{required: false}
|
||||
)
|
||||
|
||||
const inputs: Inputs = {
|
||||
files,
|
||||
@@ -139,7 +144,8 @@ export const getInputs = (): Inputs => {
|
||||
escapeJson,
|
||||
sinceLastRemoteCommit,
|
||||
writeOutputFiles,
|
||||
outputDir
|
||||
outputDir,
|
||||
outputRenamedFilesAsDeletedAndAdded
|
||||
}
|
||||
|
||||
if (fetchDepth) {
|
||||
|
||||
19
src/main.ts
19
src/main.ts
@@ -59,8 +59,10 @@ export async function run(): Promise<void> {
|
||||
)
|
||||
const isShallow = await isRepoShallow({cwd: workingDirectory})
|
||||
const hasSubmodule = await submoduleExists({cwd: workingDirectory})
|
||||
let gitExtraArgs = ['--no-tags', '--prune', '--recurse-submodules']
|
||||
let gitFetchExtraArgs = ['--no-tags', '--prune', '--recurse-submodules']
|
||||
const isTag = env.GITHUB_REF?.startsWith('refs/tags/')
|
||||
const outputRenamedFilesAsDeletedAndAdded =
|
||||
inputs.outputRenamedFilesAsDeletedAndAdded
|
||||
let submodulePaths: string[] = []
|
||||
|
||||
if (hasSubmodule) {
|
||||
@@ -68,7 +70,7 @@ export async function run(): Promise<void> {
|
||||
}
|
||||
|
||||
if (isTag) {
|
||||
gitExtraArgs = ['--prune', '--no-recurse-submodules']
|
||||
gitFetchExtraArgs = ['--prune', '--no-recurse-submodules']
|
||||
}
|
||||
|
||||
let diffResult: DiffResult
|
||||
@@ -81,7 +83,7 @@ export async function run(): Promise<void> {
|
||||
workingDirectory,
|
||||
isShallow,
|
||||
hasSubmodule,
|
||||
gitExtraArgs,
|
||||
gitFetchExtraArgs,
|
||||
isTag
|
||||
)
|
||||
} else {
|
||||
@@ -94,7 +96,7 @@ export async function run(): Promise<void> {
|
||||
workingDirectory,
|
||||
isShallow,
|
||||
hasSubmodule,
|
||||
gitExtraArgs
|
||||
gitFetchExtraArgs
|
||||
)
|
||||
}
|
||||
|
||||
@@ -118,7 +120,8 @@ export async function run(): Promise<void> {
|
||||
workingDirectory,
|
||||
hasSubmodule,
|
||||
diffResult,
|
||||
submodulePaths
|
||||
submodulePaths,
|
||||
outputRenamedFilesAsDeletedAndAdded
|
||||
})
|
||||
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`)
|
||||
|
||||
@@ -261,7 +264,8 @@ export async function run(): Promise<void> {
|
||||
const otherChangedFiles = allOtherChangedFiles
|
||||
.split(inputs.separator)
|
||||
.filter(
|
||||
filePath => !allChangedFiles.split(inputs.separator).includes(filePath)
|
||||
(filePath: string) =>
|
||||
!allChangedFiles.split(inputs.separator).includes(filePath)
|
||||
)
|
||||
|
||||
const onlyChanged =
|
||||
@@ -320,7 +324,8 @@ export async function run(): Promise<void> {
|
||||
const otherModifiedFiles = allOtherModifiedFiles
|
||||
.split(inputs.separator)
|
||||
.filter(
|
||||
filePath => !allModifiedFiles.split(inputs.separator).includes(filePath)
|
||||
(filePath: string) =>
|
||||
!allModifiedFiles.split(inputs.separator).includes(filePath)
|
||||
)
|
||||
|
||||
const onlyModified =
|
||||
|
||||
16
src/utils.ts
16
src/utils.ts
@@ -410,7 +410,8 @@ export const getAllChangedFiles = async ({
|
||||
sha2,
|
||||
diff,
|
||||
isSubmodule = false,
|
||||
parentDir = ''
|
||||
parentDir = '',
|
||||
outputRenamedFilesAsDeletedAndAdded = false
|
||||
}: {
|
||||
cwd: string
|
||||
sha1: string
|
||||
@@ -418,6 +419,7 @@ export const getAllChangedFiles = async ({
|
||||
diff: string
|
||||
isSubmodule?: boolean
|
||||
parentDir?: string
|
||||
outputRenamedFilesAsDeletedAndAdded?: boolean
|
||||
}): Promise<ChangedFiles> => {
|
||||
const {exitCode, stdout, stderr} = await exec.getExecOutput(
|
||||
'git',
|
||||
@@ -466,13 +468,21 @@ export const getAllChangedFiles = async ({
|
||||
const lines = stdout.split('\n').filter(Boolean)
|
||||
|
||||
for (const line of lines) {
|
||||
const [changeType, filePath] = line.split('\t')
|
||||
const [changeType, filePath, newPath = ''] = line.split('\t')
|
||||
const normalizedFilePath = isSubmodule
|
||||
? normalizePath(path.join(parentDir, filePath))
|
||||
: normalizePath(filePath)
|
||||
const normalizedNewPath = isSubmodule
|
||||
? normalizePath(path.join(parentDir, newPath))
|
||||
: normalizePath(newPath)
|
||||
|
||||
if (changeType.startsWith('R')) {
|
||||
changedFiles[ChangeTypeEnum.Renamed].push(normalizedFilePath)
|
||||
if (outputRenamedFilesAsDeletedAndAdded) {
|
||||
changedFiles[ChangeTypeEnum.Deleted].push(normalizedFilePath)
|
||||
changedFiles[ChangeTypeEnum.Added].push(normalizedNewPath)
|
||||
} else {
|
||||
changedFiles[ChangeTypeEnum.Renamed].push(normalizedFilePath)
|
||||
}
|
||||
} else {
|
||||
changedFiles[changeType as ChangeTypeEnum].push(normalizedFilePath)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user