3
0
Fork 0
mirror of https://github.com/tj-actions/changed-files synced 2024-12-17 13:47:20 +00:00

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:
Tonye Jack 2023-05-25 17:39:26 -06:00 committed by GitHub
parent 30e1bb07d4
commit abef388dd9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 48 deletions

View file

@ -26,7 +26,6 @@ jobs:
build:
runs-on: ubuntu-latest
if: github.event_name != 'push'
steps:
- uses: actions/checkout@v3
with:
@ -50,6 +49,7 @@ jobs:
- name: Run eslint on changed files
uses: tj-actions/eslint-changed-files@v18
if: github.event_name != 'push'
with:
token: ${{ secrets.PAT_TOKEN }}
config_path: ".eslintrc.json"
@ -62,13 +62,14 @@ jobs:
- name: Verify Changed files
uses: tj-actions/verify-changed-files@v14
id: changed_files
if: github.event_name != 'push'
with:
files: |
src
dist
- name: Commit files
if: steps.changed_files.outputs.files_changed == 'true'
if: steps.changed_files.outputs.files_changed == 'true' && github.event_name != 'push'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
@ -76,7 +77,7 @@ jobs:
git commit -m "Added missing changes and modified dist assets."
- name: Push changes
if: steps.changed_files.outputs.files_changed == 'true'
if: steps.changed_files.outputs.files_changed == 'true' && github.event_name == 'pull_request'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.PAT_TOKEN }}
@ -1160,7 +1161,7 @@ jobs:
main-branch-name: ${{ steps.branch-name.outputs.base_ref_branch }}
workflow-id: 'test.yml'
- name: Run changed-files with a custom base sha
if: github.event_name == 'pull_request' && github.event.action != 'closed' && matrix.fetch-depth == 0
if: github.event_name != 'push' && github.event.action != 'closed' && matrix.fetch-depth == 0
id: changed-files-custom-base-sha
uses: ./
with:

BIN
dist/index.js generated vendored

Binary file not shown.

BIN
dist/index.js.map generated vendored

Binary file not shown.

View file

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

View file

@ -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 || ''
}

View file

@ -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^'], {
export const getParentSha = async ({cwd}: {cwd: string}): Promise<string> => {
const {stdout} = await exec.getExecOutput(
'git',
['rev-list', '-n', '1', 'HEAD^'],
{
cwd,
silent: false
})
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'
}
)