From d27f63f45d78a8b776937eefb7698ef5a7796507 Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 23 Oct 2024 12:40:41 +0100 Subject: [PATCH 1/3] test --- .github/fetch_icons/index.js | 2 +- scripts/fetch-icons/fetchIcons.ts | 2 +- scripts/fetch-icons/generators/generatePNGs.ts | 4 ++-- scripts/utils/checkGit.ts | 4 +++- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/fetch_icons/index.js b/.github/fetch_icons/index.js index 61164312..0094f606 100644 --- a/.github/fetch_icons/index.js +++ b/.github/fetch_icons/index.js @@ -39,7 +39,7 @@ try { } console.log("Files changed", filesChanged); - core.setOutput("files_changed", filesChanged); + core.setOutput("files_changed", false); //TODO: Luke change this } catch (error) { core.setFailed(error.message); } diff --git a/scripts/fetch-icons/fetchIcons.ts b/scripts/fetch-icons/fetchIcons.ts index 9b4b23b5..2c048a5c 100644 --- a/scripts/fetch-icons/fetchIcons.ts +++ b/scripts/fetch-icons/fetchIcons.ts @@ -92,7 +92,7 @@ export default async function main( generateDefinitionFiles(outputDir, generateFontResult, manifest); console.log("✅ - Generated definition files."); - generatePNGs(iconsOutputDir, pngOutputDir, categoryNames); + await generatePNGs(iconsOutputDir, pngOutputDir, categoryNames); console.log("✅ - Generated PNGs."); console.log("✅ - Done - Icons updated!"); diff --git a/scripts/fetch-icons/generators/generatePNGs.ts b/scripts/fetch-icons/generators/generatePNGs.ts index 4fed9103..53bb11bf 100644 --- a/scripts/fetch-icons/generators/generatePNGs.ts +++ b/scripts/fetch-icons/generators/generatePNGs.ts @@ -8,7 +8,7 @@ import { createFolder } from "../../utils/fileUtils.js"; * @param {string} outputDir - Location to save PNG files * @param {string[]} categories - List of all icon categories. */ -export const generatePNGs = (inputDir: string, outputDir: string, categories: string[]) => { +export const generatePNGs = async (inputDir: string, outputDir: string, categories: string[]) => { createFolder(outputDir); for (const cat of categories) { @@ -17,7 +17,7 @@ export const generatePNGs = (inputDir: string, outputDir: string, categories: st for (const svg of svgDirs) { const split = svg.split("/"); const name = split.pop()?.slice(0, -3); - sharp(inputDir + "/" + cat + "/" + svg) + await sharp(inputDir + "/" + cat + "/" + svg) .resize(512) .modulate({ lightness: 44 }) .png() diff --git a/scripts/utils/checkGit.ts b/scripts/utils/checkGit.ts index 3545354e..e137e5e4 100644 --- a/scripts/utils/checkGit.ts +++ b/scripts/utils/checkGit.ts @@ -5,9 +5,11 @@ import { execSync } from "child_process"; * @returns string[] - List of files that have changed */ const getAllChangedFiles = (): string[] => { + console.log("git diff HEAD"); + console.log(execSync(`git diff HEAD`).toString()); const diffOutput = execSync(`git diff HEAD --name-only`).toString(); if (diffOutput != "") { - console.log("Files changed:", diffOutput); + // console.log("Files changed:", diffOutput); } return diffOutput.toString().split("\n").filter(Boolean); }; From 468f1781f210aecdc438e3e905af3db0561701a3 Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 23 Oct 2024 13:04:07 +0100 Subject: [PATCH 2/3] 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..9258b79f 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; }; From 756c8b480cb29977e835832bb253f8ff52dbfa24 Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 23 Oct 2024 13:27:22 +0100 Subject: [PATCH 3/3] ci: Only run build steps if there are changes --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8181f6a5..ab6b4a64 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -55,6 +55,7 @@ jobs: if: ${{ steps.fetch_icons.outputs.files_changed == 'true'}} uses: ./.github/create_code_connect - name: Create PR title + if: ${{ steps.fetch_icons.outputs.files_changed == 'true'}} id: title run: | if [ ${{github.ref_name=='main'}} ]; then @@ -73,6 +74,7 @@ jobs: git commit -m "${{steps.title.outputs.TITLE}}" git push --set-upstream origin ${{steps.branch_name.outputs.BRANCH_NAME}} -f - name: Check if PR exists + if: ${{ steps.fetch_icons.outputs.files_changed == 'true'}} run: echo "pr_exists=$(gh pr list -H ${{steps.branch_name.outputs.BRANCH_NAME}} --json number -q length)" >> $GITHUB_ENV env: GITHUB_TOKEN: ${{ github.token }}