From 254362ba7b4f87ab8e26a250a8ad27bf879183ec Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 23 Oct 2024 13:04:07 +0100 Subject: [PATCH] working? --- .github/fetch_icons/action.yml | 5 +++++ .github/fetch_icons/index.js | 7 ++++--- .github/workflows/build.yml | 1 + scripts/utils/checkGit.ts | 28 +++++++++++++++++----------- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/.github/fetch_icons/action.yml b/.github/fetch_icons/action.yml index feff5b20..2034b540 100644 --- a/.github/fetch_icons/action.yml +++ b/.github/fetch_icons/action.yml @@ -7,6 +7,11 @@ inputs: date: description: "The date and time the action was run" required: true + actions-runner-debug: + description: "The date and time the action was run" + required: false + default: false + type: boolean outputs: files_changed: description: "Boolean that gets set to true if any icons have been added or removed" diff --git a/.github/fetch_icons/index.js b/.github/fetch_icons/index.js index 0094f606..53bc7354 100644 --- a/.github/fetch_icons/index.js +++ b/.github/fetch_icons/index.js @@ -5,6 +5,7 @@ import { checkForFileChanges, stageAllFiles } from '../../dist/scripts/utils/che import { ZDS_ASSETS_FILE_ID, ZDS_ASSETS_ICON_PAGE_NAME } from "../../figmaConfig.js"; const FIGMA_ACCESS_TOKEN = core.getInput("figma-access-token") || process.env.FIGMA_ACCESS_TOKEN; +const VERBOSE_LOGS = core.getBooleanInput("ACTIONS_RUNNER_DEBUG") || false; const DATE = core.getInput("date") || 'now'; try { @@ -23,13 +24,13 @@ try { ZDS_ASSETS_ICON_PAGE_NAME, oldHash, "outputs", - false, + VERBOSE_LOGS, ); let filesChanged = false; if (newHash) { writeFileSync(hashPath, newHash); - filesChanged = checkForFileChanges(); + filesChanged = checkForFileChanges(VERBOSE_LOGS); if (filesChanged) { const packageJson = JSON.parse(readFileSync("./package.json").toString()); packageJson.lastUpdated = DATE; @@ -39,7 +40,7 @@ try { } console.log("Files changed", filesChanged); - core.setOutput("files_changed", false); //TODO: Luke change this + core.setOutput("files_changed", filesChanged); } catch (error) { core.setFailed(error.message); } diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fc3799bf..8181f6a5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,6 +48,7 @@ jobs: with: figma-access-token: ${{ secrets.FIGMA_PERSONAL_ACCESS_TOKEN }} date: ${{ steps.date.outputs.date }} + actions-runner-debug: ${{secrets.ACTIONS_RUNNER_DEBUG}} - name: Icons changed run: echo ${{ steps.fetch_icons.outputs.files_changed }} - name: Create code connect files diff --git a/scripts/utils/checkGit.ts b/scripts/utils/checkGit.ts index e137e5e4..a3f0f6e6 100644 --- a/scripts/utils/checkGit.ts +++ b/scripts/utils/checkGit.ts @@ -2,30 +2,36 @@ import { execSync } from "child_process"; /** * Gets all files that have changed in the current branch + * @param {boolean} verboseLogs - Logs more verbose outputs for testing. * @returns string[] - List of files that have changed */ -const getAllChangedFiles = (): string[] => { - console.log("git diff HEAD"); - console.log(execSync(`git diff HEAD`).toString()); +const getAllChangedFiles = (verboseLogs?: boolean): string[] => { const diffOutput = execSync(`git diff HEAD --name-only`).toString(); - if (diffOutput != "") { - // console.log("Files changed:", diffOutput); + if (diffOutput != "" && verboseLogs) { + console.log("Files changed:", execSync(`git diff HEAD`).toString()); } return diffOutput.toString().split("\n").filter(Boolean); }; /** * Stages all files in the current branch + * @param {boolean} verboseLogs - Logs more verbose outputs for testing. */ -export const stageAllFiles = (): void => { - execSync(`git add .`); +export const stageAllFiles = (verboseLogs?: boolean): void => { + if (verboseLogs) { + console.log("git add", execSync(`git add .`).toString()); + } else { + execSync(`git add .`); + } }; /** - * Checks if any files have changed in the current branch, but removes package.json from the list of changed files + * Checks if any files have changed in the current branch. + * The check is deliberately off by one to account for `outputs/code-connect.figma.ts` which is not yet regenerated, so will always be changed. + * @param {boolean} verboseLogs - Logs more verbose outputs for testing. * @returns boolean - Whether files have changed and the action should create a PR */ -export const checkForFileChanges = (): boolean => { - stageAllFiles(); - return getAllChangedFiles().length > 0; +export const checkForFileChanges = (verboseLogs?: boolean): boolean => { + stageAllFiles(verboseLogs); + return getAllChangedFiles(verboseLogs).length > 1; };