From 2f49eb9ee1f1dc38d9f070ebecf12b59c9436e0e Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sun, 9 Jul 2023 03:19:14 -0600 Subject: [PATCH] feat: add support for skipping initial fetch (#1353) Co-authored-by: GitHub Action --- action.yml | 4 +++ dist/index.js | Bin 1683460 -> 1683768 bytes dist/index.js.map | Bin 1685707 -> 1686063 bytes src/commitSha.ts | 4 +-- src/inputs.ts | 7 ++++- src/main.ts | 69 +++++++++++++++++++++++++++------------------- 6 files changed, 53 insertions(+), 31 deletions(-) diff --git a/action.yml b/action.yml index a8b5643f..79771228 100644 --- a/action.yml +++ b/action.yml @@ -124,6 +124,10 @@ inputs: description: "Depth of additional branch history fetched. **NOTE**: This can be adjusted to resolve errors with insufficient history." required: false default: "50" + skip_initial_fetch: + description: "Skip the initial fetch to improve performance." + required: false + default: "false" 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." required: false diff --git a/dist/index.js b/dist/index.js index e5b0b63efe6e95479db693418d6d9d1438049233..2f41f1743e2a3ea708a64ae3c56a4a6dc126f698 100644 GIT binary patch delta 698 zcmZp9khbGd+J>+a1qC%V1;xy~g3^*=z2fZ50?)k6lFY;$x73p43{8bcHF>&;?4yIcg&&6>=3UQ!4o7@rBTAwCUc#bm~l;*<9uW}Q6mi16kM7j#&p zbhs3t0Nseqf3BS664g;i%gjj)NGvHyEy^p_QK(GJ&2gJ<>%r(geZ3kZ>t?P8dYqFN z|B#q|Je!e!(<^hv&C9+`XWTsDZ44`Jy}pz6KA(r{n)K@YWQA7F$#cKD12xODPTp6; zr5>JNl%1KEu8@*hl$uOs#jATko*6-eGOM z!`6C-z4Z=9>m8sJSL+?_);m0{cX(Ux@U`CIZ@nYXdPlJJj!^3z;nq7Mt#?FQ?})YD O5pTUCvGtCm#(Drl=ooGQ delta 345 zcmdn-D6Qo|+J>-_$uH*cOy=lu+kB)%MjXUh%+cezx#*$}%jO+d&vH$_AIE63`QZa& z&dHa5IZeLfEHK&9N?`JX@2r!rd5BDo`>i&4+UIYR4fy#cFL)O`)Dx>vgF1QPx7>Tq{~peZ4fR1? zUHRBCH!R(_?-PlGtl+pgEqU$w$w!H2-F}qU?7l0tc&!$<5xc0x8Go`{?&*>Da80jR z<^gkz>w_A%xKc{ytV5|5<`ma#|b*Fa`q6?f5VWyILtT!?!{+Y9kdBDL5n^ z55g(vj9t*=pQpK7xQAfb+a8luUdj(EmX$X&GbUG+aw&;dS0Rmh44h))EMz_6Qx-1T zaHTH-BC5l@4d2W#->n<~&R%DL(?p7?c#6BbCwD{v04 z)mckdS~2AUw|;LbDrSmXO+9_4+l3=pIE=SBM7Pb+_#EGrVINLeG#k&sz#mKA=b#^# zHkn_%tiXPTtDjjA7gUI_ymkriO~Br!O=(}jg|9T4x3Rduk8N+;KTdB#C%&F{dr-f_ zLO8O-93owXuEo2ATN&F;0T1k+!5s9>u O5DAkGu{art9{Udb!!C>f delta 448 zcma*hJ4ixt6b5ka{hxb%+!NS|%0F z8uc#8*P@cSSk&fpn4pR&G@auC_WB? zO3hiAH{t7uV!^`=7{= { @@ -154,6 +155,9 @@ export const getInputs = (): Inputs => { ) const token = core.getInput('token', {required: false}) const apiUrl = core.getInput('api_url', {required: false}) + const skipInitialFetch = core.getBooleanInput('skip_initial_fetch', { + required: false + }) const inputs: Inputs = { files, @@ -194,7 +198,8 @@ export const getInputs = (): Inputs => { outputDir, outputRenamedFilesAsDeletedAndAdded, token, - apiUrl + apiUrl, + skipInitialFetch } if (fetchDepth) { diff --git a/src/main.ts b/src/main.ts index 7e8a526e..a68f4a30 100644 --- a/src/main.ts +++ b/src/main.ts @@ -28,11 +28,15 @@ import { const getChangedFilesFromLocalGit = async ({ inputs, env, - workingDirectory + workingDirectory, + filePatterns, + yamlFilePatterns }: { inputs: Inputs env: Env workingDirectory: string + filePatterns: string[] + yamlFilePatterns: Record }): Promise => { await verifyMinimumGitVersion() @@ -120,12 +124,6 @@ const getChangedFilesFromLocalGit = async ({ core.info('All Done!') core.endGroup() - const filePatterns = await getFilePatterns({ - inputs, - workingDirectory - }) - core.debug(`File patterns: ${filePatterns}`) - if (filePatterns.length > 0) { core.startGroup('changed-files-patterns') await setChangedFilesOutput({ @@ -139,12 +137,6 @@ const getChangedFilesFromLocalGit = async ({ core.endGroup() } - const yamlFilePatterns = await getYamlFilePatterns({ - inputs, - workingDirectory - }) - core.debug(`Yaml file patterns: ${JSON.stringify(yamlFilePatterns)}`) - if (Object.keys(yamlFilePatterns).length > 0) { for (const key of Object.keys(yamlFilePatterns)) { core.startGroup(`changed-files-yaml-${key}`) @@ -201,11 +193,15 @@ const getChangedFilesFromLocalGit = async ({ const getChangedFilesFromRESTAPI = async ({ inputs, env, - workingDirectory + workingDirectory, + filePatterns, + yamlFilePatterns }: { inputs: Inputs env: Env workingDirectory: string + filePatterns: string[] + yamlFilePatterns: Record }): Promise => { const allDiffFiles = await getChangedFilesFromGithubAPI({ inputs, @@ -214,12 +210,6 @@ const getChangedFilesFromRESTAPI = async ({ core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`) core.info('All Done!') - const filePatterns = await getFilePatterns({ - inputs, - workingDirectory - }) - core.debug(`File patterns: ${filePatterns}`) - if (filePatterns.length > 0) { core.startGroup('changed-files-patterns') await setChangedFilesOutput({ @@ -232,12 +222,6 @@ const getChangedFilesFromRESTAPI = async ({ core.endGroup() } - const yamlFilePatterns = await getYamlFilePatterns({ - inputs, - workingDirectory - }) - core.debug(`Yaml file patterns: ${JSON.stringify(yamlFilePatterns)}`) - if (Object.keys(yamlFilePatterns).length > 0) { for (const key of Object.keys(yamlFilePatterns)) { core.startGroup(`changed-files-yaml-${key}`) @@ -270,13 +254,30 @@ export async function run(): Promise { const env = await getEnv() core.debug(`Env: ${JSON.stringify(env, null, 2)}`) + const inputs = getInputs() core.debug(`Inputs: ${JSON.stringify(inputs, null, 2)}`) + const workingDirectory = path.resolve( env.GITHUB_WORKSPACE || process.cwd(), inputs.path ) + core.debug(`Working directory: ${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 ( inputs.token && @@ -302,7 +303,13 @@ export async function run(): Promise { ) } } - await getChangedFilesFromRESTAPI({inputs, env, workingDirectory}) + await getChangedFilesFromRESTAPI({ + inputs, + env, + workingDirectory, + filePatterns, + yamlFilePatterns + }) } else { if (!hasGitDirectory) { core.setFailed( @@ -312,7 +319,13 @@ export async function run(): Promise { } core.info('Using local .git directory') - await getChangedFilesFromLocalGit({inputs, env, workingDirectory}) + await getChangedFilesFromLocalGit({ + inputs, + env, + workingDirectory, + filePatterns, + yamlFilePatterns + }) } }