fix: update test to include push event (#1173)
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:
@@ -5,7 +5,7 @@ import {Inputs} from './inputs'
|
||||
import {
|
||||
canDiffCommits,
|
||||
getHeadSha,
|
||||
getParentHeadSha,
|
||||
getParentSha,
|
||||
getPreviousGitTag,
|
||||
gitFetch,
|
||||
gitFetchSubmodules,
|
||||
@@ -74,7 +74,7 @@ export const getSHAForPushEvent = async (
|
||||
gitExtraArgs: string[],
|
||||
isTag: boolean
|
||||
): Promise<DiffResult> => {
|
||||
let targetBranch = env.GITHUB_REFNAME
|
||||
let targetBranch = env.GITHUB_REF_NAME
|
||||
const currentBranch = targetBranch
|
||||
let initialCommit = false
|
||||
|
||||
@@ -174,33 +174,33 @@ export const getSHAForPushEvent = async (
|
||||
previousSha = sha
|
||||
targetBranch = tag
|
||||
} else {
|
||||
if (inputs.sinceLastRemoteCommit) {
|
||||
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 getParentHeadSha({cwd: workingDirectory})
|
||||
}
|
||||
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 {
|
||||
core.debug('Getting previous SHA for last commit...')
|
||||
previousSha = await getParentHeadSha({cwd: workingDirectory})
|
||||
previousSha = await getParentSha({
|
||||
cwd: workingDirectory
|
||||
})
|
||||
}
|
||||
|
||||
if (
|
||||
!previousSha ||
|
||||
previousSha === '0000000000000000000000000000000000000000'
|
||||
) {
|
||||
previousSha = await getParentHeadSha({cwd: workingDirectory})
|
||||
previousSha = await getParentSha({
|
||||
cwd: workingDirectory
|
||||
})
|
||||
}
|
||||
|
||||
if (previousSha === currentSha) {
|
||||
if (!(await getParentHeadSha({cwd: workingDirectory}))) {
|
||||
if (!(await getParentSha({cwd: workingDirectory}))) {
|
||||
core.warning('Initial commit detected no previous commit found.')
|
||||
initialCommit = true
|
||||
previousSha = currentSha
|
||||
} else {
|
||||
previousSha = await getParentHeadSha({cwd: workingDirectory})
|
||||
previousSha = await getParentSha({
|
||||
cwd: workingDirectory
|
||||
})
|
||||
}
|
||||
} else {
|
||||
if (!previousSha) {
|
||||
|
||||
@@ -5,7 +5,7 @@ export type Env = {
|
||||
GITHUB_EVENT_PULL_REQUEST_HEAD_REF: string
|
||||
GITHUB_EVENT_PULL_REQUEST_BASE_REF: string
|
||||
GITHUB_EVENT_BEFORE: string
|
||||
GITHUB_REFNAME: string
|
||||
GITHUB_REF_NAME: string
|
||||
GITHUB_REF: string
|
||||
GITHUB_EVENT_BASE_REF: string
|
||||
GITHUB_EVENT_HEAD_REPO_FORK: string
|
||||
@@ -41,7 +41,6 @@ export const getEnv = async (): Promise<Env> => {
|
||||
if (eventPath) {
|
||||
eventJson = JSON.parse(await fs.readFile(eventPath, {encoding: 'utf8'}))
|
||||
}
|
||||
|
||||
core.debug(`Event: ${JSON.stringify(eventJson, null, 2)}`)
|
||||
|
||||
return {
|
||||
@@ -53,7 +52,7 @@ export const getEnv = async (): Promise<Env> => {
|
||||
GITHUB_EVENT_PULL_REQUEST_NUMBER: eventJson.pull_request?.number || '',
|
||||
GITHUB_EVENT_PULL_REQUEST_BASE_SHA: eventJson.pull_request?.base?.sha || '',
|
||||
GITHUB_EVENT_FORCED: eventJson.forced || '',
|
||||
GITHUB_REFNAME: process.env.GITHUB_REFNAME || '',
|
||||
GITHUB_REF_NAME: process.env.GITHUB_REF_NAME || '',
|
||||
GITHUB_REF: process.env.GITHUB_REF || '',
|
||||
GITHUB_WORKSPACE: process.env.GITHUB_WORKSPACE || ''
|
||||
}
|
||||
|
||||
52
src/utils.ts
52
src/utils.ts
@@ -93,7 +93,7 @@ export const verifyMinimumGitVersion = async (): Promise<void> => {
|
||||
const {exitCode, stdout, stderr} = await exec.getExecOutput(
|
||||
'git',
|
||||
['--version'],
|
||||
{silent: false}
|
||||
{silent: process.env.ACTION_DEBUG === 'false'}
|
||||
)
|
||||
|
||||
if (exitCode !== 0) {
|
||||
@@ -177,7 +177,7 @@ export const updateGitGlobalConfig = async ({
|
||||
['config', '--global', name, value],
|
||||
{
|
||||
ignoreReturnCode: true,
|
||||
silent: false
|
||||
silent: process.env.ACTION_DEBUG === 'false'
|
||||
}
|
||||
)
|
||||
|
||||
@@ -193,7 +193,7 @@ export const isRepoShallow = async ({cwd}: {cwd: string}): Promise<boolean> => {
|
||||
['rev-parse', '--is-shallow-repository'],
|
||||
{
|
||||
cwd,
|
||||
silent: false
|
||||
silent: process.env.ACTION_DEBUG === 'false'
|
||||
}
|
||||
)
|
||||
|
||||
@@ -211,7 +211,7 @@ export const submoduleExists = async ({
|
||||
{
|
||||
cwd,
|
||||
ignoreReturnCode: true,
|
||||
silent: false
|
||||
silent: process.env.ACTION_DEBUG === 'false'
|
||||
}
|
||||
)
|
||||
|
||||
@@ -232,7 +232,7 @@ export const gitFetch = async ({
|
||||
const {exitCode} = await exec.getExecOutput('git', ['fetch', '-q', ...args], {
|
||||
cwd,
|
||||
ignoreReturnCode: true,
|
||||
silent: false
|
||||
silent: process.env.ACTION_DEBUG === 'false'
|
||||
})
|
||||
|
||||
return exitCode
|
||||
@@ -251,7 +251,7 @@ export const gitFetchSubmodules = async ({
|
||||
{
|
||||
cwd,
|
||||
ignoreReturnCode: true,
|
||||
silent: false
|
||||
silent: process.env.ACTION_DEBUG === 'false'
|
||||
}
|
||||
)
|
||||
|
||||
@@ -276,7 +276,7 @@ export const getSubmodulePath = async ({
|
||||
{
|
||||
cwd,
|
||||
ignoreReturnCode: true,
|
||||
silent: false
|
||||
silent: process.env.ACTION_DEBUG === 'false'
|
||||
}
|
||||
)
|
||||
|
||||
@@ -309,7 +309,7 @@ export const gitSubmoduleDiffSHA = async ({
|
||||
['diff', parentSha1, parentSha2, '--', submodulePath],
|
||||
{
|
||||
cwd,
|
||||
silent: false
|
||||
silent: process.env.ACTION_DEBUG === 'false'
|
||||
}
|
||||
)
|
||||
|
||||
@@ -362,7 +362,7 @@ export const gitRenamedFiles = async ({
|
||||
{
|
||||
cwd,
|
||||
ignoreReturnCode: true,
|
||||
silent: false
|
||||
silent: process.env.ACTION_DEBUG === 'false'
|
||||
}
|
||||
)
|
||||
|
||||
@@ -434,7 +434,7 @@ export const gitDiff = async ({
|
||||
{
|
||||
cwd,
|
||||
ignoreReturnCode: true,
|
||||
silent: false
|
||||
silent: process.env.ACTION_DEBUG === 'false'
|
||||
}
|
||||
)
|
||||
|
||||
@@ -486,7 +486,7 @@ export const gitLog = async ({
|
||||
}): Promise<string> => {
|
||||
const {stdout} = await exec.getExecOutput('git', ['log', ...args], {
|
||||
cwd,
|
||||
silent: false
|
||||
silent: process.env.ACTION_DEBUG === 'false'
|
||||
})
|
||||
|
||||
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: false
|
||||
silent: process.env.ACTION_DEBUG === 'false'
|
||||
})
|
||||
|
||||
return stdout.trim()
|
||||
@@ -513,7 +513,7 @@ export const gitLsRemote = async ({
|
||||
['ls-remote', 'origin', ...args],
|
||||
{
|
||||
cwd,
|
||||
silent: false
|
||||
silent: process.env.ACTION_DEBUG === 'false'
|
||||
}
|
||||
)
|
||||
const output = stdout.trim().split('\t')
|
||||
@@ -525,15 +525,15 @@ export const gitLsRemote = async ({
|
||||
return output[0]
|
||||
}
|
||||
|
||||
export const getParentHeadSha = async ({
|
||||
cwd
|
||||
}: {
|
||||
cwd: string
|
||||
}): Promise<string> => {
|
||||
const {stdout} = await exec.getExecOutput('git', ['rev-parse', 'HEAD^'], {
|
||||
cwd,
|
||||
silent: false
|
||||
})
|
||||
export const getParentSha = async ({cwd}: {cwd: string}): Promise<string> => {
|
||||
const {stdout} = await exec.getExecOutput(
|
||||
'git',
|
||||
['rev-list', '-n', '1', 'HEAD^'],
|
||||
{
|
||||
cwd,
|
||||
silent: process.env.ACTION_DEBUG === 'false'
|
||||
}
|
||||
)
|
||||
|
||||
return stdout.trim()
|
||||
}
|
||||
@@ -553,7 +553,7 @@ export const verifyCommitSha = async ({
|
||||
{
|
||||
cwd,
|
||||
ignoreReturnCode: true,
|
||||
silent: false
|
||||
silent: process.env.ACTION_DEBUG === 'false'
|
||||
}
|
||||
)
|
||||
|
||||
@@ -583,7 +583,7 @@ export const getPreviousGitTag = async ({
|
||||
['tag', '--sort=-version:refname'],
|
||||
{
|
||||
cwd,
|
||||
silent: false
|
||||
silent: process.env.ACTION_DEBUG === 'false'
|
||||
}
|
||||
)
|
||||
|
||||
@@ -601,7 +601,7 @@ export const getPreviousGitTag = async ({
|
||||
['rev-parse', previousTag],
|
||||
{
|
||||
cwd,
|
||||
silent: false
|
||||
silent: process.env.ACTION_DEBUG === 'false'
|
||||
}
|
||||
)
|
||||
|
||||
@@ -627,7 +627,7 @@ export const canDiffCommits = async ({
|
||||
{
|
||||
cwd,
|
||||
ignoreReturnCode: true,
|
||||
silent: false
|
||||
silent: process.env.ACTION_DEBUG === 'false'
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user