Skip to content

Commit

Permalink
working?
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Oct 23, 2024
1 parent d27f63f commit 468f178
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .github/fetch_icons/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions .github/fetch_icons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -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);
}
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 17 additions & 11 deletions scripts/utils/checkGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit 468f178

Please sign in to comment.