3
0
Fork 0
mirror of https://github.com/tj-actions/changed-files synced 2025-01-17 19:17:45 +00:00

fix: incorrect branch name for issue_comment event (#1625)

Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
Tonye Jack 2023-10-02 17:35:05 -06:00 committed by GitHub
parent 15f38d6693
commit 3415b43780
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 141 additions and 2 deletions

View file

@ -34,6 +34,59 @@ jobs:
shell:
bash
- name: Run changed-files for old new filenames test rename
id: changed-files-all-old-new-renamed-files
uses: ./
with:
base_sha: d1c0ee4
sha: 4d04215
fetch_depth: 60000
include_all_old_new_renamed_files: true
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-all-old-new-renamed-files.outputs) }}'
shell:
bash
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-all-old-new-renamed-files.outputs) }}'
shell:
bash
- name: Check all_old_new_renamed_files output on non windows platform
if: "!contains(steps.changed-files-all-old-new-renamed-files.outputs.all_old_new_renamed_files, 'test/test rename 1.txt,test/test rename-1.txt') && runner.os != 'Windows'"
run: |
echo "Invalid output: Expected to include (test/test rename 1.txt,test/test rename-1.txt) got (${{ steps.changed-files-all-old-new-renamed-files.outputs.all_old_new_renamed_files }})"
exit 1
shell:
bash
- name: Check all_old_new_renamed_files output on windows platform
if: "!contains(steps.changed-files-all-old-new-renamed-files.outputs.all_old_new_renamed_files, 'test\\test rename 1.txt,test\\test rename-1.txt') && runner.os == 'Windows'"
run: |
echo "Invalid output: Expected to not include (test\\test rename 1.txt,test\\test rename-1.txt) got (${{ steps.changed-files-all-old-new-renamed-files.outputs.all_old_new_renamed_files }})"
exit 1
shell:
bash
- name: Check the renamed_files output on non windows platform
if: "!contains(steps.changed-files-all-old-new-renamed-files.outputs.renamed_files, 'test/test rename-1.txt') && runner.os != 'Windows'"
run: |
echo "Invalid output: Expected to include (test/test rename-1.txt) got (${{ steps.changed-files-all-old-new-renamed-files.outputs.renamed_files }})"
exit 1
shell:
bash
- name: Check the renamed_files output on windows platform
if: "!contains(steps.changed-files-all-old-new-renamed-files.outputs.renamed_files, 'test\\test rename-1.txt') && runner.os == 'Windows'"
run: |
echo "Invalid output: Expected to not include (test\\test rename-1.txt) got (${{ steps.changed-files-all-old-new-renamed-files.outputs.renamed_files }})"
exit 1
shell:
bash
issue_commented:
# This job only runs for issue comments
name: Issue comment
@ -63,4 +116,57 @@ jobs:
run: |
echo '${{ toJSON(steps.changed-files.outputs) }}'
shell:
bash
bash
- name: Run changed-files for old new filenames test rename
id: changed-files-all-old-new-renamed-files
uses: ./
with:
base_sha: d1c0ee4
sha: 4d04215
fetch_depth: 60000
include_all_old_new_renamed_files: true
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-all-old-new-renamed-files.outputs) }}'
shell:
bash
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-all-old-new-renamed-files.outputs) }}'
shell:
bash
- name: Check all_old_new_renamed_files output on non windows platform
if: "!contains(steps.changed-files-all-old-new-renamed-files.outputs.all_old_new_renamed_files, 'test/test rename 1.txt,test/test rename-1.txt') && runner.os != 'Windows'"
run: |
echo "Invalid output: Expected to include (test/test rename 1.txt,test/test rename-1.txt) got (${{ steps.changed-files-all-old-new-renamed-files.outputs.all_old_new_renamed_files }})"
exit 1
shell:
bash
- name: Check all_old_new_renamed_files output on windows platform
if: "!contains(steps.changed-files-all-old-new-renamed-files.outputs.all_old_new_renamed_files, 'test\\test rename 1.txt,test\\test rename-1.txt') && runner.os == 'Windows'"
run: |
echo "Invalid output: Expected to not include (test\\test rename 1.txt,test\\test rename-1.txt) got (${{ steps.changed-files-all-old-new-renamed-files.outputs.all_old_new_renamed_files }})"
exit 1
shell:
bash
- name: Check the renamed_files output on non windows platform
if: "!contains(steps.changed-files-all-old-new-renamed-files.outputs.renamed_files, 'test/test rename-1.txt') && runner.os != 'Windows'"
run: |
echo "Invalid output: Expected to include (test/test rename-1.txt) got (${{ steps.changed-files-all-old-new-renamed-files.outputs.renamed_files }})"
exit 1
shell:
bash
- name: Check the renamed_files output on windows platform
if: "!contains(steps.changed-files-all-old-new-renamed-files.outputs.renamed_files, 'test\\test rename-1.txt') && runner.os == 'Windows'"
run: |
echo "Invalid output: Expected to not include (test\\test rename-1.txt) got (${{ steps.changed-files-all-old-new-renamed-files.outputs.renamed_files }})"
exit 1
shell:
bash

BIN
dist/index.js generated vendored

Binary file not shown.

BIN
dist/index.js.map generated vendored

Binary file not shown.

View file

@ -5,6 +5,7 @@ import {Env} from './env'
import {Inputs} from './inputs'
import {
canDiffCommits,
getCurrentBranchName,
getHeadSha,
getParentSha,
getPreviousGitTag,
@ -90,7 +91,7 @@ export const getSHAForNonPullRequestEvent = async (
isTag: boolean
): Promise<DiffResult> => {
let targetBranch = env.GITHUB_REF_NAME
const currentBranch = targetBranch
let currentBranch = targetBranch
let initialCommit = false
if (!inputs.skipInitialFetch) {
@ -163,6 +164,16 @@ export const getSHAForNonPullRequestEvent = async (
const currentSha = await getCurrentSHA({inputs, workingDirectory})
let previousSha = inputs.baseSha
const diff = '..'
const currentBranchName = await getCurrentBranchName({cwd: workingDirectory})
if (
currentBranchName &&
currentBranchName !== 'HEAD' &&
(currentBranchName !== targetBranch || currentBranchName !== currentBranch)
) {
targetBranch = currentBranchName
currentBranch = currentBranchName
}
if (previousSha && currentSha && currentBranch && targetBranch) {
if (previousSha === currentSha) {

View file

@ -696,6 +696,28 @@ export const getRemoteBranchHeadSha = async ({
return stdout.trim()
}
export const getCurrentBranchName = async ({
cwd
}: {
cwd: string
}): Promise<string> => {
const {stdout, exitCode} = await exec.getExecOutput(
'git',
['rev-parse', '--abbrev-ref', 'HEAD'],
{
cwd,
ignoreReturnCode: true,
silent: !core.isDebug()
}
)
if (exitCode !== 0) {
return ''
}
return stdout.trim()
}
export const getParentSha = async ({cwd}: {cwd: string}): Promise<string> => {
const {stdout, exitCode} = await exec.getExecOutput(
'git',