fix/resolve bug fetching more history (#1176)

Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Tonye Jack
2023-05-25 21:14:24 -06:00
committed by GitHub
parent 77f872a759
commit 25eaddf37a
7 changed files with 71 additions and 55 deletions

View File

@@ -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,

View File

@@ -41,6 +41,7 @@ export const getEnv = async (): Promise<Env> => {
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 {

View File

@@ -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) {

View File

@@ -93,7 +93,7 @@ export const verifyMinimumGitVersion = async (): Promise<void> => {
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<boolean> => {
['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<string> => {
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<string> => {
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<string> => {
['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'
}
)