3
0
Fork 0
mirror of https://github.com/tj-actions/changed-files synced 2025-02-21 05:28:14 +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 86 additions and 86 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:

74
dist/index.js generated vendored
View file

@ -206,7 +206,7 @@ const getCurrentSHA = ({ inputs, workingDirectory }) => __awaiter(void 0, void 0
return currentSha;
});
const getSHAForPushEvent = (inputs, env, workingDirectory, isShallow, hasSubmodule, gitExtraArgs, isTag) => __awaiter(void 0, void 0, void 0, function* () {
let targetBranch = env.GITHUB_REFNAME;
let targetBranch = env.GITHUB_REF_NAME;
const currentBranch = targetBranch;
let initialCommit = false;
if (isShallow) {
@ -295,31 +295,31 @@ const getSHAForPushEvent = (inputs, env, workingDirectory, isShallow, hasSubmodu
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 = yield (0, utils_1.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 = yield (0, utils_1.getParentHeadSha)({ cwd: workingDirectory });
previousSha = yield (0, utils_1.getParentSha)({
cwd: workingDirectory
});
}
if (!previousSha ||
previousSha === '0000000000000000000000000000000000000000') {
previousSha = yield (0, utils_1.getParentHeadSha)({ cwd: workingDirectory });
previousSha = yield (0, utils_1.getParentSha)({
cwd: workingDirectory
});
}
if (previousSha === currentSha) {
if (!(yield (0, utils_1.getParentHeadSha)({ cwd: workingDirectory }))) {
if (!(yield (0, utils_1.getParentSha)({ cwd: workingDirectory }))) {
core.warning('Initial commit detected no previous commit found.');
initialCommit = true;
previousSha = currentSha;
}
else {
previousSha = yield (0, utils_1.getParentHeadSha)({ cwd: workingDirectory });
previousSha = yield (0, utils_1.getParentSha)({
cwd: workingDirectory
});
}
}
else {
@ -585,7 +585,7 @@ const getEnv = () => __awaiter(void 0, void 0, void 0, function* () {
GITHUB_EVENT_PULL_REQUEST_NUMBER: ((_f = eventJson.pull_request) === null || _f === void 0 ? void 0 : _f.number) || '',
GITHUB_EVENT_PULL_REQUEST_BASE_SHA: ((_h = (_g = eventJson.pull_request) === null || _g === void 0 ? void 0 : _g.base) === null || _h === void 0 ? void 0 : _h.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 || ''
};
@ -1160,7 +1160,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.setOutput = exports.getFilePatterns = exports.jsonOutput = exports.getDirnameMaxDepth = exports.canDiffCommits = exports.getPreviousGitTag = exports.verifyCommitSha = exports.getParentHeadSha = exports.gitLsRemote = exports.getHeadSha = exports.gitLog = exports.gitDiff = exports.gitRenamedFiles = exports.gitSubmoduleDiffSHA = exports.getSubmodulePath = exports.gitFetchSubmodules = exports.gitFetch = exports.submoduleExists = exports.isRepoShallow = exports.updateGitGlobalConfig = exports.verifyMinimumGitVersion = void 0;
exports.setOutput = exports.getFilePatterns = exports.jsonOutput = exports.getDirnameMaxDepth = exports.canDiffCommits = exports.getPreviousGitTag = exports.verifyCommitSha = exports.getParentSha = exports.gitLsRemote = exports.getHeadSha = exports.gitLog = exports.gitDiff = exports.gitRenamedFiles = exports.gitSubmoduleDiffSHA = exports.getSubmodulePath = exports.gitFetchSubmodules = exports.gitFetch = exports.submoduleExists = exports.isRepoShallow = exports.updateGitGlobalConfig = exports.verifyMinimumGitVersion = void 0;
/*global AsyncIterableIterator*/
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
@ -1234,7 +1234,7 @@ const versionToNumber = (version) => {
return major * 1000000 + minor * 1000 + patch;
};
const verifyMinimumGitVersion = () => __awaiter(void 0, void 0, void 0, function* () {
const { exitCode, stdout, stderr } = yield exec.getExecOutput('git', ['--version'], { silent: false });
const { exitCode, stdout, stderr } = yield exec.getExecOutput('git', ['--version'], { silent: process.env.ACTION_DEBUG === 'false' });
if (exitCode !== 0) {
throw new Error(stderr || 'An unexpected error occurred');
}
@ -1329,7 +1329,7 @@ const getFilesFromSourceFile = ({ filePaths, excludedFiles = false }) => __await
const updateGitGlobalConfig = ({ name, value }) => __awaiter(void 0, void 0, void 0, function* () {
const { exitCode, stderr } = yield exec.getExecOutput('git', ['config', '--global', name, value], {
ignoreReturnCode: true,
silent: false
silent: process.env.ACTION_DEBUG === 'false'
});
/* istanbul ignore if */
if (exitCode !== 0 || stderr) {
@ -1340,7 +1340,7 @@ exports.updateGitGlobalConfig = updateGitGlobalConfig;
const isRepoShallow = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* () {
const { stdout } = yield exec.getExecOutput('git', ['rev-parse', '--is-shallow-repository'], {
cwd,
silent: false
silent: process.env.ACTION_DEBUG === 'false'
});
return stdout.trim() === 'true';
});
@ -1349,7 +1349,7 @@ const submoduleExists = ({ cwd }) => __awaiter(void 0, void 0, void 0, function*
const { stdout, exitCode } = yield exec.getExecOutput('git', ['submodule', 'status'], {
cwd,
ignoreReturnCode: true,
silent: false
silent: process.env.ACTION_DEBUG === 'false'
});
if (exitCode !== 0) {
return false;
@ -1361,7 +1361,7 @@ const gitFetch = ({ args, cwd }) => __awaiter(void 0, void 0, void 0, function*
const { exitCode } = yield exec.getExecOutput('git', ['fetch', '-q', ...args], {
cwd,
ignoreReturnCode: true,
silent: false
silent: process.env.ACTION_DEBUG === 'false'
});
return exitCode;
});
@ -1370,7 +1370,7 @@ const gitFetchSubmodules = ({ args, cwd }) => __awaiter(void 0, void 0, void 0,
const { exitCode, stderr } = yield exec.getExecOutput('git', ['submodule', 'foreach', 'git', 'fetch', '-q', ...args], {
cwd,
ignoreReturnCode: true,
silent: false
silent: process.env.ACTION_DEBUG === 'false'
});
/* istanbul ignore if */
if (exitCode !== 0) {
@ -1385,7 +1385,7 @@ const getSubmodulePath = ({ cwd }) => __awaiter(void 0, void 0, void 0, function
const { exitCode, stdout, stderr } = yield exec.getExecOutput('git', ['submodule', 'status'], {
cwd,
ignoreReturnCode: true,
silent: false
silent: process.env.ACTION_DEBUG === 'false'
});
if (exitCode !== 0) {
core.warning(stderr || "Couldn't get submodule names");
@ -1401,7 +1401,7 @@ const gitSubmoduleDiffSHA = ({ cwd, parentSha1, parentSha2, submodulePath, diff
var _h, _j, _k, _l;
const { stdout } = yield exec.getExecOutput('git', ['diff', parentSha1, parentSha2, '--', submodulePath], {
cwd,
silent: false
silent: process.env.ACTION_DEBUG === 'false'
});
const subprojectCommitPreRegex = /^(?<preCommit>-)Subproject commit (?<commitHash>.+)$/m;
const subprojectCommitCurRegex = /^(?<curCommit>\+)Subproject commit (?<commitHash>.+)$/m;
@ -1425,7 +1425,7 @@ const gitRenamedFiles = ({ cwd, sha1, sha2, diff, oldNewSeparator, isSubmodule =
], {
cwd,
ignoreReturnCode: true,
silent: false
silent: process.env.ACTION_DEBUG === 'false'
});
if (exitCode !== 0) {
if (isSubmodule) {
@ -1463,7 +1463,7 @@ const gitDiff = ({ cwd, sha1, sha2, diff, diffFilter, filePatterns = [], isSubmo
], {
cwd,
ignoreReturnCode: true,
silent: false
silent: process.env.ACTION_DEBUG === 'false'
});
if (exitCode !== 0) {
if (isSubmodule) {
@ -1498,7 +1498,7 @@ exports.gitDiff = gitDiff;
const gitLog = ({ args, cwd }) => __awaiter(void 0, void 0, void 0, function* () {
const { stdout } = yield exec.getExecOutput('git', ['log', ...args], {
cwd,
silent: false
silent: process.env.ACTION_DEBUG === 'false'
});
return stdout.trim();
});
@ -1506,7 +1506,7 @@ exports.gitLog = gitLog;
const getHeadSha = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* () {
const { stdout } = yield exec.getExecOutput('git', ['rev-parse', 'HEAD'], {
cwd,
silent: false
silent: process.env.ACTION_DEBUG === 'false'
});
return stdout.trim();
});
@ -1514,7 +1514,7 @@ exports.getHeadSha = getHeadSha;
const gitLsRemote = ({ cwd, args }) => __awaiter(void 0, void 0, void 0, function* () {
const { stdout } = yield exec.getExecOutput('git', ['ls-remote', 'origin', ...args], {
cwd,
silent: false
silent: process.env.ACTION_DEBUG === 'false'
});
const output = stdout.trim().split('\t');
if (output.length === 0) {
@ -1523,19 +1523,19 @@ const gitLsRemote = ({ cwd, args }) => __awaiter(void 0, void 0, void 0, functio
return output[0];
});
exports.gitLsRemote = gitLsRemote;
const getParentHeadSha = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* () {
const { stdout } = yield exec.getExecOutput('git', ['rev-parse', 'HEAD^'], {
const getParentSha = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* () {
const { stdout } = yield exec.getExecOutput('git', ['rev-list', '-n', '1', 'HEAD^'], {
cwd,
silent: false
silent: process.env.ACTION_DEBUG === 'false'
});
return stdout.trim();
});
exports.getParentHeadSha = getParentHeadSha;
exports.getParentSha = getParentSha;
const verifyCommitSha = ({ sha, cwd, showAsErrorMessage = true }) => __awaiter(void 0, void 0, void 0, function* () {
const { exitCode, stderr } = yield exec.getExecOutput('git', ['rev-parse', '--verify', `${sha}^{commit}`], {
cwd,
ignoreReturnCode: true,
silent: false
silent: process.env.ACTION_DEBUG === 'false'
});
if (exitCode !== 0) {
if (showAsErrorMessage) {
@ -1554,7 +1554,7 @@ exports.verifyCommitSha = verifyCommitSha;
const getPreviousGitTag = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* () {
const { stdout } = yield exec.getExecOutput('git', ['tag', '--sort=-version:refname'], {
cwd,
silent: false
silent: process.env.ACTION_DEBUG === 'false'
});
const tags = stdout.trim().split('\n');
if (tags.length < 2) {
@ -1564,7 +1564,7 @@ const getPreviousGitTag = ({ cwd }) => __awaiter(void 0, void 0, void 0, functio
const previousTag = tags[1];
const { stdout: stdout2 } = yield exec.getExecOutput('git', ['rev-parse', previousTag], {
cwd,
silent: false
silent: process.env.ACTION_DEBUG === 'false'
});
const sha = stdout2.trim();
return { tag: previousTag, sha };
@ -1574,7 +1574,7 @@ const canDiffCommits = ({ cwd, sha1, sha2, diff }) => __awaiter(void 0, void 0,
const { exitCode, stderr } = yield exec.getExecOutput('git', ['diff', '--name-only', '--ignore-submodules=all', `${sha1}${diff}${sha2}`], {
cwd,
ignoreReturnCode: true,
silent: false
silent: process.env.ACTION_DEBUG === 'false'
});
if (exitCode !== 0) {
core.warning(stderr || `Unable find merge base between ${sha1} and ${sha2}`);

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

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

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^'], {
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'
}
)