Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: If icon files change, upadte lastUpdated in package.json #51

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .github/fetch_icons/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import core from "@actions/core";
import { readFileSync, writeFileSync } from "fs";
import fetchIcons from "../../dist/scripts/fetch-icons/fetchIcons.js";
import { checkForFileChanges, stageAllFiles } from '../../dist/scripts/utils/checkGit.js';
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;
Expand All @@ -27,9 +28,13 @@ try {

if (newHash) {
writeFileSync(hashPath, newHash);
const packageJson = JSON.parse(readFileSync("./package.json").toString());
packageJson.lastUpdated = DATE;
writeFileSync("./package.json", JSON.stringify(packageJson, null, 2));
const fileChanges = checkForFileChanges();
if (fileChanges) {
const packageJson = JSON.parse(readFileSync("./package.json").toString());
packageJson.lastUpdated = DATE;
writeFileSync("./package.json", JSON.stringify(packageJson, null, 2));
stageAllFiles();
}
}
console.log("Files changed", newHash);
core.setOutput("files_changed", newHash != undefined);
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
run: npm ci
- name: Run tests
run: npm run test
- name: Run tsc
run: tsc

release-comment:
name: Release Comment
Expand Down
26 changes: 26 additions & 0 deletions scripts/utils/checkGit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { execSync } from "child_process";

/**
* Gets all files that have changed in the current branch
* @returns string[] - List of files that have changed
*/
const getAllChangedFiles = (): string[] => {
const diffOutput = execSync(`git diff HEAD --name-only`).toString();
return diffOutput.toString().split("\n").filter(Boolean);
};

/**
* Stages all files in the current branch
*/
export const stageAllFiles = (): void => {
execSync(`git add .`);
};

/**
* Checks if any files have changed in the current branch, but removes package.json from the list of changed files
* @returns boolean - Whether files have changed and the action should create a PR
*/
export const checkForFileChanges = (): boolean => {
stageAllFiles();
return getAllChangedFiles().length > 0;
};