feat: add support for skipping initial fetch (#1353)

Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Tonye Jack 2023-07-09 03:19:14 -06:00 committed by GitHub
parent 00b3d3d9e7
commit 2f49eb9ee1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 89 additions and 59 deletions

View File

@ -124,6 +124,10 @@ inputs:
description: "Depth of additional branch history fetched. **NOTE**: This can be adjusted to resolve errors with insufficient history." description: "Depth of additional branch history fetched. **NOTE**: This can be adjusted to resolve errors with insufficient history."
required: false required: false
default: "50" default: "50"
skip_initial_fetch:
description: "Skip the initial fetch to improve performance."
required: false
default: "false"
since_last_remote_commit: since_last_remote_commit:
description: "Use the last commit on the remote branch as the `base_sha`. Defaults to the last non-merge commit on the target branch for pull request events and the previous remote commit of the current branch for push events." description: "Use the last commit on the remote branch as the `base_sha`. Defaults to the last non-merge commit on the target branch for pull request events and the previous remote commit of the current branch for push events."
required: false required: false

62
dist/index.js generated vendored
View File

@ -724,7 +724,7 @@ const getSHAForPushEvent = (inputs, env, workingDirectory, isShallow, hasSubmodu
let targetBranch = env.GITHUB_REF_NAME; let targetBranch = env.GITHUB_REF_NAME;
const currentBranch = targetBranch; const currentBranch = targetBranch;
let initialCommit = false; let initialCommit = false;
if (isShallow) { if (isShallow && !inputs.skipInitialFetch) {
core.info('Repository is shallow, fetching more history...'); core.info('Repository is shallow, fetching more history...');
if (isTag) { if (isTag) {
const sourceBranch = env.GITHUB_EVENT_BASE_REF.replace('refs/heads/', '') || const sourceBranch = env.GITHUB_EVENT_BASE_REF.replace('refs/heads/', '') ||
@ -868,7 +868,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
if (inputs.sinceLastRemoteCommit) { if (inputs.sinceLastRemoteCommit) {
targetBranch = currentBranch; targetBranch = currentBranch;
} }
if (isShallow) { if (isShallow && !inputs.skipInitialFetch) {
core.info('Repository is shallow, fetching more history...'); core.info('Repository is shallow, fetching more history...');
let prFetchExitCode = yield (0, utils_1.gitFetch)({ let prFetchExitCode = yield (0, utils_1.gitFetch)({
cwd: workingDirectory, cwd: workingDirectory,
@ -1246,6 +1246,9 @@ const getInputs = () => {
const recoverDeletedFilesToDestination = core.getInput('recover_deleted_files_to_destination', { required: false }); const recoverDeletedFilesToDestination = core.getInput('recover_deleted_files_to_destination', { required: false });
const token = core.getInput('token', { required: false }); const token = core.getInput('token', { required: false });
const apiUrl = core.getInput('api_url', { required: false }); const apiUrl = core.getInput('api_url', { required: false });
const skipInitialFetch = core.getBooleanInput('skip_initial_fetch', {
required: false
});
const inputs = { const inputs = {
files, files,
filesSeparator, filesSeparator,
@ -1285,7 +1288,8 @@ const getInputs = () => {
outputDir, outputDir,
outputRenamedFilesAsDeletedAndAdded, outputRenamedFilesAsDeletedAndAdded,
token, token,
apiUrl apiUrl,
skipInitialFetch
}; };
if (fetchDepth) { if (fetchDepth) {
inputs.fetchDepth = Math.max(parseInt(fetchDepth, 10), 2); inputs.fetchDepth = Math.max(parseInt(fetchDepth, 10), 2);
@ -1350,7 +1354,7 @@ const commitSha_1 = __nccwpck_require__(8613);
const env_1 = __nccwpck_require__(9763); const env_1 = __nccwpck_require__(9763);
const inputs_1 = __nccwpck_require__(6180); const inputs_1 = __nccwpck_require__(6180);
const utils_1 = __nccwpck_require__(918); const utils_1 = __nccwpck_require__(918);
const getChangedFilesFromLocalGit = ({ inputs, env, workingDirectory }) => __awaiter(void 0, void 0, void 0, function* () { const getChangedFilesFromLocalGit = ({ inputs, env, workingDirectory, filePatterns, yamlFilePatterns }) => __awaiter(void 0, void 0, void 0, function* () {
var _a; var _a;
yield (0, utils_1.verifyMinimumGitVersion)(); yield (0, utils_1.verifyMinimumGitVersion)();
let quotePathValue = 'on'; let quotePathValue = 'on';
@ -1404,11 +1408,6 @@ const getChangedFilesFromLocalGit = ({ inputs, env, workingDirectory }) => __awa
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`); core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`);
core.info('All Done!'); core.info('All Done!');
core.endGroup(); core.endGroup();
const filePatterns = yield (0, utils_1.getFilePatterns)({
inputs,
workingDirectory
});
core.debug(`File patterns: ${filePatterns}`);
if (filePatterns.length > 0) { if (filePatterns.length > 0) {
core.startGroup('changed-files-patterns'); core.startGroup('changed-files-patterns');
yield (0, changedFilesOutput_1.setChangedFilesOutput)({ yield (0, changedFilesOutput_1.setChangedFilesOutput)({
@ -1421,11 +1420,6 @@ const getChangedFilesFromLocalGit = ({ inputs, env, workingDirectory }) => __awa
core.info('All Done!'); core.info('All Done!');
core.endGroup(); core.endGroup();
} }
const yamlFilePatterns = yield (0, utils_1.getYamlFilePatterns)({
inputs,
workingDirectory
});
core.debug(`Yaml file patterns: ${JSON.stringify(yamlFilePatterns)}`);
if (Object.keys(yamlFilePatterns).length > 0) { if (Object.keys(yamlFilePatterns).length > 0) {
for (const key of Object.keys(yamlFilePatterns)) { for (const key of Object.keys(yamlFilePatterns)) {
core.startGroup(`changed-files-yaml-${key}`); core.startGroup(`changed-files-yaml-${key}`);
@ -1476,18 +1470,13 @@ const getChangedFilesFromLocalGit = ({ inputs, env, workingDirectory }) => __awa
core.endGroup(); core.endGroup();
} }
}); });
const getChangedFilesFromRESTAPI = ({ inputs, env, workingDirectory }) => __awaiter(void 0, void 0, void 0, function* () { const getChangedFilesFromRESTAPI = ({ inputs, env, workingDirectory, filePatterns, yamlFilePatterns }) => __awaiter(void 0, void 0, void 0, function* () {
const allDiffFiles = yield (0, changedFiles_1.getChangedFilesFromGithubAPI)({ const allDiffFiles = yield (0, changedFiles_1.getChangedFilesFromGithubAPI)({
inputs, inputs,
env env
}); });
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`); core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`);
core.info('All Done!'); core.info('All Done!');
const filePatterns = yield (0, utils_1.getFilePatterns)({
inputs,
workingDirectory
});
core.debug(`File patterns: ${filePatterns}`);
if (filePatterns.length > 0) { if (filePatterns.length > 0) {
core.startGroup('changed-files-patterns'); core.startGroup('changed-files-patterns');
yield (0, changedFilesOutput_1.setChangedFilesOutput)({ yield (0, changedFilesOutput_1.setChangedFilesOutput)({
@ -1499,11 +1488,6 @@ const getChangedFilesFromRESTAPI = ({ inputs, env, workingDirectory }) => __awai
core.info('All Done!'); core.info('All Done!');
core.endGroup(); core.endGroup();
} }
const yamlFilePatterns = yield (0, utils_1.getYamlFilePatterns)({
inputs,
workingDirectory
});
core.debug(`Yaml file patterns: ${JSON.stringify(yamlFilePatterns)}`);
if (Object.keys(yamlFilePatterns).length > 0) { if (Object.keys(yamlFilePatterns).length > 0) {
for (const key of Object.keys(yamlFilePatterns)) { for (const key of Object.keys(yamlFilePatterns)) {
core.startGroup(`changed-files-yaml-${key}`); core.startGroup(`changed-files-yaml-${key}`);
@ -1537,7 +1521,19 @@ function run() {
const inputs = (0, inputs_1.getInputs)(); const inputs = (0, inputs_1.getInputs)();
core.debug(`Inputs: ${JSON.stringify(inputs, null, 2)}`); core.debug(`Inputs: ${JSON.stringify(inputs, null, 2)}`);
const workingDirectory = path_1.default.resolve(env.GITHUB_WORKSPACE || process.cwd(), inputs.path); const workingDirectory = path_1.default.resolve(env.GITHUB_WORKSPACE || process.cwd(), inputs.path);
core.debug(`Working directory: ${workingDirectory}`);
const hasGitDirectory = yield (0, utils_1.hasLocalGitDirectory)({ workingDirectory }); const hasGitDirectory = yield (0, utils_1.hasLocalGitDirectory)({ workingDirectory });
core.debug(`Has git directory: ${hasGitDirectory}`);
const filePatterns = yield (0, utils_1.getFilePatterns)({
inputs,
workingDirectory
});
core.debug(`File patterns: ${filePatterns}`);
const yamlFilePatterns = yield (0, utils_1.getYamlFilePatterns)({
inputs,
workingDirectory
});
core.debug(`Yaml file patterns: ${JSON.stringify(yamlFilePatterns)}`);
if (inputs.token && if (inputs.token &&
env.GITHUB_EVENT_PULL_REQUEST_NUMBER && env.GITHUB_EVENT_PULL_REQUEST_NUMBER &&
!hasGitDirectory) { !hasGitDirectory) {
@ -1557,7 +1553,13 @@ function run() {
core.warning(`Input "${input}" is not supported when using GitHub's REST API to get changed files`); core.warning(`Input "${input}" is not supported when using GitHub's REST API to get changed files`);
} }
} }
yield getChangedFilesFromRESTAPI({ inputs, env, workingDirectory }); yield getChangedFilesFromRESTAPI({
inputs,
env,
workingDirectory,
filePatterns,
yamlFilePatterns
});
} }
else { else {
if (!hasGitDirectory) { if (!hasGitDirectory) {
@ -1565,7 +1567,13 @@ function run() {
return; return;
} }
core.info('Using local .git directory'); core.info('Using local .git directory');
yield getChangedFilesFromLocalGit({ inputs, env, workingDirectory }); yield getChangedFilesFromLocalGit({
inputs,
env,
workingDirectory,
filePatterns,
yamlFilePatterns
});
} }
}); });
} }

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -92,7 +92,7 @@ export const getSHAForPushEvent = async (
const currentBranch = targetBranch const currentBranch = targetBranch
let initialCommit = false let initialCommit = false
if (isShallow) { if (isShallow && !inputs.skipInitialFetch) {
core.info('Repository is shallow, fetching more history...') core.info('Repository is shallow, fetching more history...')
if (isTag) { if (isTag) {
@ -271,7 +271,7 @@ export const getSHAForPullRequestEvent = async (
targetBranch = currentBranch targetBranch = currentBranch
} }
if (isShallow) { if (isShallow && !inputs.skipInitialFetch) {
core.info('Repository is shallow, fetching more history...') core.info('Repository is shallow, fetching more history...')
let prFetchExitCode = await gitFetch({ let prFetchExitCode = await gitFetch({

View File

@ -40,6 +40,7 @@ export type Inputs = {
recoverDeletedFilesToDestination: string recoverDeletedFilesToDestination: string
token: string token: string
apiUrl: string apiUrl: string
skipInitialFetch: boolean
} }
export const getInputs = (): Inputs => { export const getInputs = (): Inputs => {
@ -154,6 +155,9 @@ export const getInputs = (): Inputs => {
) )
const token = core.getInput('token', {required: false}) const token = core.getInput('token', {required: false})
const apiUrl = core.getInput('api_url', {required: false}) const apiUrl = core.getInput('api_url', {required: false})
const skipInitialFetch = core.getBooleanInput('skip_initial_fetch', {
required: false
})
const inputs: Inputs = { const inputs: Inputs = {
files, files,
@ -194,7 +198,8 @@ export const getInputs = (): Inputs => {
outputDir, outputDir,
outputRenamedFilesAsDeletedAndAdded, outputRenamedFilesAsDeletedAndAdded,
token, token,
apiUrl apiUrl,
skipInitialFetch
} }
if (fetchDepth) { if (fetchDepth) {

View File

@ -28,11 +28,15 @@ import {
const getChangedFilesFromLocalGit = async ({ const getChangedFilesFromLocalGit = async ({
inputs, inputs,
env, env,
workingDirectory workingDirectory,
filePatterns,
yamlFilePatterns
}: { }: {
inputs: Inputs inputs: Inputs
env: Env env: Env
workingDirectory: string workingDirectory: string
filePatterns: string[]
yamlFilePatterns: Record<string, string[]>
}): Promise<void> => { }): Promise<void> => {
await verifyMinimumGitVersion() await verifyMinimumGitVersion()
@ -120,12 +124,6 @@ const getChangedFilesFromLocalGit = async ({
core.info('All Done!') core.info('All Done!')
core.endGroup() core.endGroup()
const filePatterns = await getFilePatterns({
inputs,
workingDirectory
})
core.debug(`File patterns: ${filePatterns}`)
if (filePatterns.length > 0) { if (filePatterns.length > 0) {
core.startGroup('changed-files-patterns') core.startGroup('changed-files-patterns')
await setChangedFilesOutput({ await setChangedFilesOutput({
@ -139,12 +137,6 @@ const getChangedFilesFromLocalGit = async ({
core.endGroup() core.endGroup()
} }
const yamlFilePatterns = await getYamlFilePatterns({
inputs,
workingDirectory
})
core.debug(`Yaml file patterns: ${JSON.stringify(yamlFilePatterns)}`)
if (Object.keys(yamlFilePatterns).length > 0) { if (Object.keys(yamlFilePatterns).length > 0) {
for (const key of Object.keys(yamlFilePatterns)) { for (const key of Object.keys(yamlFilePatterns)) {
core.startGroup(`changed-files-yaml-${key}`) core.startGroup(`changed-files-yaml-${key}`)
@ -201,11 +193,15 @@ const getChangedFilesFromLocalGit = async ({
const getChangedFilesFromRESTAPI = async ({ const getChangedFilesFromRESTAPI = async ({
inputs, inputs,
env, env,
workingDirectory workingDirectory,
filePatterns,
yamlFilePatterns
}: { }: {
inputs: Inputs inputs: Inputs
env: Env env: Env
workingDirectory: string workingDirectory: string
filePatterns: string[]
yamlFilePatterns: Record<string, string[]>
}): Promise<void> => { }): Promise<void> => {
const allDiffFiles = await getChangedFilesFromGithubAPI({ const allDiffFiles = await getChangedFilesFromGithubAPI({
inputs, inputs,
@ -214,12 +210,6 @@ const getChangedFilesFromRESTAPI = async ({
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`) core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`)
core.info('All Done!') core.info('All Done!')
const filePatterns = await getFilePatterns({
inputs,
workingDirectory
})
core.debug(`File patterns: ${filePatterns}`)
if (filePatterns.length > 0) { if (filePatterns.length > 0) {
core.startGroup('changed-files-patterns') core.startGroup('changed-files-patterns')
await setChangedFilesOutput({ await setChangedFilesOutput({
@ -232,12 +222,6 @@ const getChangedFilesFromRESTAPI = async ({
core.endGroup() core.endGroup()
} }
const yamlFilePatterns = await getYamlFilePatterns({
inputs,
workingDirectory
})
core.debug(`Yaml file patterns: ${JSON.stringify(yamlFilePatterns)}`)
if (Object.keys(yamlFilePatterns).length > 0) { if (Object.keys(yamlFilePatterns).length > 0) {
for (const key of Object.keys(yamlFilePatterns)) { for (const key of Object.keys(yamlFilePatterns)) {
core.startGroup(`changed-files-yaml-${key}`) core.startGroup(`changed-files-yaml-${key}`)
@ -270,13 +254,30 @@ export async function run(): Promise<void> {
const env = await getEnv() const env = await getEnv()
core.debug(`Env: ${JSON.stringify(env, null, 2)}`) core.debug(`Env: ${JSON.stringify(env, null, 2)}`)
const inputs = getInputs() const inputs = getInputs()
core.debug(`Inputs: ${JSON.stringify(inputs, null, 2)}`) core.debug(`Inputs: ${JSON.stringify(inputs, null, 2)}`)
const workingDirectory = path.resolve( const workingDirectory = path.resolve(
env.GITHUB_WORKSPACE || process.cwd(), env.GITHUB_WORKSPACE || process.cwd(),
inputs.path inputs.path
) )
core.debug(`Working directory: ${workingDirectory}`)
const hasGitDirectory = await hasLocalGitDirectory({workingDirectory}) const hasGitDirectory = await hasLocalGitDirectory({workingDirectory})
core.debug(`Has git directory: ${hasGitDirectory}`)
const filePatterns = await getFilePatterns({
inputs,
workingDirectory
})
core.debug(`File patterns: ${filePatterns}`)
const yamlFilePatterns = await getYamlFilePatterns({
inputs,
workingDirectory
})
core.debug(`Yaml file patterns: ${JSON.stringify(yamlFilePatterns)}`)
if ( if (
inputs.token && inputs.token &&
@ -302,7 +303,13 @@ export async function run(): Promise<void> {
) )
} }
} }
await getChangedFilesFromRESTAPI({inputs, env, workingDirectory}) await getChangedFilesFromRESTAPI({
inputs,
env,
workingDirectory,
filePatterns,
yamlFilePatterns
})
} else { } else {
if (!hasGitDirectory) { if (!hasGitDirectory) {
core.setFailed( core.setFailed(
@ -312,7 +319,13 @@ export async function run(): Promise<void> {
} }
core.info('Using local .git directory') core.info('Using local .git directory')
await getChangedFilesFromLocalGit({inputs, env, workingDirectory}) await getChangedFilesFromLocalGit({
inputs,
env,
workingDirectory,
filePatterns,
yamlFilePatterns
})
} }
} }