From 25eaddf37ae893cec889065e9a60439c8af6f089 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 25 May 2023 21:14:24 -0600 Subject: [PATCH] fix/resolve bug fetching more history (#1176) Co-authored-by: GitHub Action --- .github/workflows/test.yml | 10 +++++----- dist/index.js | Bin 317187 -> 317473 bytes dist/index.js.map | Bin 372627 -> 372949 bytes src/commitSha.ts | 21 +++++++++++++++------ src/env.ts | 1 + src/inputs.ts | 2 +- src/utils.ts | 36 ++++++++++++++++++------------------ 7 files changed, 40 insertions(+), 30 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 77bbe972..db99a2a3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -689,16 +689,16 @@ jobs: echo '${{ toJSON(steps.changed-files-json.outputs.all_changed_files) }}' shell: bash - - name: Run changed-files with json raw format - id: changed-files-json-raw-format + - name: Run changed-files with json unescaped format + id: changed-files-json-unescaped uses: ./ with: json: true - json_raw_format: true + escape_json: false - name: Show output run: | - echo '${{ toJSON(steps.changed-files-json-raw-format.outputs) }}' - echo '${{ toJSON(steps.changed-files-json-raw-format.outputs.all_changed_files) }}' + echo '${{ toJSON(steps.changed-files-json-unescaped.outputs) }}' + echo '${{ toJSON(steps.changed-files-json-unescaped.outputs.all_changed_files) }}' shell: bash - name: Run changed-files with comma separator diff --git a/dist/index.js b/dist/index.js index 6343d59305b28218e6bb04091b9f555213f3ce9e..701bc0324b54ee3187bda680192cb3ec0fec0287 100644 GIT binary patch delta 830 zcmZo(C%kZj@CJ9C$@hEMC#MIhOrG_ddvlG>3fAfC@)_AC3wUx(zHIbrdci|RPDYK% zjSUi$|QT2PdqoLXG0mzr0mqmWmclcS?xq&eBZTy*ojSVM76-^7v(z1+kKjmi9_ z63jrk&1$8)14V*D{rp^m;$2*wLfsV+r{#KuS_qf1jgX12&!dO&HesIfn z^O-9(jMyYM$6pJ@Dlz%P7oF+4E{yEcFNiV;ZsxyXk6l^(HPOvgH~q0nZh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#mcDK*xbC(at zMkj{K$#o15U6d-h93rH0Gzm!Yb@(}$!X%_f^Z;f2y^KaF!l4z+N~a_QGEJCucL%tH=s*7c5T7y_*-Re(Qc=78a?!}3n#zrAo-6C78@gWsj>)IOYwc& z%Lo=kl{7sG-zv@dk-_OhEXg^cQqQYL2+I-cRlgy*=@_Q;Rn|!^K0$|EO1RQEd5T>* WVqF_ZL7!SUhbTpqjTg@C4KF_v!3X{T diff --git a/src/commitSha.ts b/src/commitSha.ts index 9bece7c0..cb932c9c 100644 --- a/src/commitSha.ts +++ b/src/commitSha.ts @@ -137,7 +137,7 @@ export const getSHAForPushEvent = async ( } await verifyCommitSha({sha: previousSha, cwd: workingDirectory}) - core.info(`Previous SHA: ${previousSha}`) + core.debug(`Previous SHA: ${previousSha}`) return { previousSha, @@ -177,10 +177,6 @@ export const getSHAForPushEvent = async ( core.debug('Getting previous SHA for last remote commit...') if (env.GITHUB_EVENT_FORCED === 'false' || !env.GITHUB_EVENT_FORCED) { previousSha = env.GITHUB_EVENT_BEFORE - } else { - previousSha = await getParentSha({ - cwd: workingDirectory - }) } if ( @@ -190,6 +186,19 @@ export const getSHAForPushEvent = async ( previousSha = await getParentSha({ cwd: workingDirectory }) + } else if ( + (await verifyCommitSha({ + sha: previousSha, + cwd: workingDirectory, + showAsErrorMessage: false + })) !== 0 + ) { + core.warning( + `Previous commit ${previousSha} is not valid. Using parent commit.` + ) + previousSha = await getParentSha({ + cwd: workingDirectory + }) } if (previousSha === currentSha) { @@ -322,7 +331,7 @@ export const getSHAForPullRequestEvent = async ( } await verifyCommitSha({sha: currentSha, cwd: workingDirectory}) - core.info(`Previous SHA: ${previousSha}`) + core.debug(`Previous SHA: ${previousSha}`) return { previousSha, diff --git a/src/env.ts b/src/env.ts index dd59eaa5..02226c70 100644 --- a/src/env.ts +++ b/src/env.ts @@ -41,6 +41,7 @@ export const getEnv = async (): Promise => { if (eventPath) { eventJson = JSON.parse(await fs.readFile(eventPath, {encoding: 'utf8'})) } + core.debug(`Env: ${JSON.stringify(process.env, null, 2)}`) core.debug(`Event: ${JSON.stringify(eventJson, null, 2)}`) return { diff --git a/src/inputs.ts b/src/inputs.ts index 75625b51..bca5e600 100644 --- a/src/inputs.ts +++ b/src/inputs.ts @@ -135,7 +135,7 @@ export const getInputs = (): Inputs => { } if (fetchDepth) { - inputs.fetchDepth = parseInt(fetchDepth, 10) + inputs.fetchDepth = Math.max(parseInt(fetchDepth, 10), 2) } if (dirNamesMaxDepth) { diff --git a/src/utils.ts b/src/utils.ts index fe45c905..522edbb9 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -93,7 +93,7 @@ export const verifyMinimumGitVersion = async (): Promise => { const {exitCode, stdout, stderr} = await exec.getExecOutput( 'git', ['--version'], - {silent: process.env.ACTION_DEBUG === 'false'} + {silent: process.env.RUNNER_DEBUG !== '1'} ) if (exitCode !== 0) { @@ -177,7 +177,7 @@ export const updateGitGlobalConfig = async ({ ['config', '--global', name, value], { ignoreReturnCode: true, - silent: process.env.ACTION_DEBUG === 'false' + silent: process.env.RUNNER_DEBUG !== '1' } ) @@ -193,7 +193,7 @@ export const isRepoShallow = async ({cwd}: {cwd: string}): Promise => { ['rev-parse', '--is-shallow-repository'], { cwd, - silent: process.env.ACTION_DEBUG === 'false' + silent: process.env.RUNNER_DEBUG !== '1' } ) @@ -211,7 +211,7 @@ export const submoduleExists = async ({ { cwd, ignoreReturnCode: true, - silent: process.env.ACTION_DEBUG === 'false' + silent: process.env.RUNNER_DEBUG !== '1' } ) @@ -232,7 +232,7 @@ export const gitFetch = async ({ const {exitCode} = await exec.getExecOutput('git', ['fetch', '-q', ...args], { cwd, ignoreReturnCode: true, - silent: process.env.ACTION_DEBUG === 'false' + silent: process.env.RUNNER_DEBUG !== '1' }) return exitCode @@ -251,7 +251,7 @@ export const gitFetchSubmodules = async ({ { cwd, ignoreReturnCode: true, - silent: process.env.ACTION_DEBUG === 'false' + silent: process.env.RUNNER_DEBUG !== '1' } ) @@ -276,7 +276,7 @@ export const getSubmodulePath = async ({ { cwd, ignoreReturnCode: true, - silent: process.env.ACTION_DEBUG === 'false' + silent: process.env.RUNNER_DEBUG !== '1' } ) @@ -309,7 +309,7 @@ export const gitSubmoduleDiffSHA = async ({ ['diff', parentSha1, parentSha2, '--', submodulePath], { cwd, - silent: process.env.ACTION_DEBUG === 'false' + silent: process.env.RUNNER_DEBUG !== '1' } ) @@ -362,7 +362,7 @@ export const gitRenamedFiles = async ({ { cwd, ignoreReturnCode: true, - silent: process.env.ACTION_DEBUG === 'false' + silent: process.env.RUNNER_DEBUG !== '1' } ) @@ -434,7 +434,7 @@ export const gitDiff = async ({ { cwd, ignoreReturnCode: true, - silent: process.env.ACTION_DEBUG === 'false' + silent: process.env.RUNNER_DEBUG !== '1' } ) @@ -486,7 +486,7 @@ export const gitLog = async ({ }): Promise => { const {stdout} = await exec.getExecOutput('git', ['log', ...args], { cwd, - silent: process.env.ACTION_DEBUG === 'false' + silent: process.env.RUNNER_DEBUG !== '1' }) return stdout.trim() @@ -495,7 +495,7 @@ export const gitLog = async ({ export const getHeadSha = async ({cwd}: {cwd: string}): Promise => { const {stdout} = await exec.getExecOutput('git', ['rev-parse', 'HEAD'], { cwd, - silent: process.env.ACTION_DEBUG === 'false' + silent: process.env.RUNNER_DEBUG !== '1' }) return stdout.trim() @@ -513,7 +513,7 @@ export const gitLsRemote = async ({ ['ls-remote', 'origin', ...args], { cwd, - silent: process.env.ACTION_DEBUG === 'false' + silent: process.env.RUNNER_DEBUG !== '1' } ) const output = stdout.trim().split('\t') @@ -531,7 +531,7 @@ export const getParentSha = async ({cwd}: {cwd: string}): Promise => { ['rev-list', '-n', '1', 'HEAD^'], { cwd, - silent: process.env.ACTION_DEBUG === 'false' + silent: process.env.RUNNER_DEBUG !== '1' } ) @@ -553,7 +553,7 @@ export const verifyCommitSha = async ({ { cwd, ignoreReturnCode: true, - silent: process.env.ACTION_DEBUG === 'false' + silent: process.env.RUNNER_DEBUG !== '1' } ) @@ -583,7 +583,7 @@ export const getPreviousGitTag = async ({ ['tag', '--sort=-version:refname'], { cwd, - silent: process.env.ACTION_DEBUG === 'false' + silent: process.env.RUNNER_DEBUG !== '1' } ) @@ -601,7 +601,7 @@ export const getPreviousGitTag = async ({ ['rev-parse', previousTag], { cwd, - silent: process.env.ACTION_DEBUG === 'false' + silent: process.env.RUNNER_DEBUG !== '1' } ) @@ -627,7 +627,7 @@ export const canDiffCommits = async ({ { cwd, ignoreReturnCode: true, - silent: process.env.ACTION_DEBUG === 'false' + silent: process.env.RUNNER_DEBUG !== '1' } )