diff --git a/.github/check.js b/.github/check.mjs similarity index 64% rename from .github/check.js rename to .github/check.mjs index 4e36bb7..343b033 100644 --- a/.github/check.js +++ b/.github/check.mjs @@ -1,16 +1,16 @@ -const { readdirSync, readFileSync, existsSync } = require("fs"); -const { execSync } = require("child_process"); +import { readdirSync, readFileSync, existsSync } from "fs"; +import { ExifTool } from "exiftool-vendored"; -// strip all metadata to ensure consistency -exec("exiftool -All= -r -overwrite_original ./images"); -exec("exiftool -All= -r -overwrite_original ./print"); +const exiftool = new ExifTool(); -checkDimensions("./images", 600, 600); -checkDimensions("./print", 1200, 1200); +await checkDimensions("./images", 600, 600); +await checkDimensions("./print", 1200, 1200); checkList("software.json"); checkList("groups.json"); +await exiftool.end(); + // check list of entries in json file function checkList(filename) { console.info(`Checking list "${filename}"`); @@ -41,29 +41,27 @@ function checkList(filename) { } } -// check dimensions of images in directory -function checkDimensions( - directory, +// check dimensions of images in folder +async function checkDimensions( + folder, expectedWidth, expectedHeight, extension = "png" ) { - // get all images matching extension in directory - const paths = readdirSync(directory) + // get all images matching extension in folder + const paths = readdirSync(folder) .filter((filename) => filename.endsWith(`.${extension}`)) - .map((filename) => `${directory}/${filename}`); + .map((filename) => `${folder}/${filename}`); for (const [index, path] of Object.entries(paths)) { console.info(`Checking "${path}" (${+index + 1} of ${paths.length})`); - // extract dimensions - const [width, height] = exec( - `exiftool -s3 -ImageWidth -ImageHeight ${path}`, - false - ) - .split(/\s/) - .filter(Boolean) - .map(Number); + // extract metadata + const { + ImageWidth: width, + ImageHeight: height, + ColorType: colorspace, + } = await exiftool.read(path); // check dimensions if (width !== expectedWidth || height !== expectedHeight) @@ -72,14 +70,7 @@ function checkDimensions( ); // check color space - const colorspace = exec(`exiftool -s3 -ColorType ${path}`, false); if (!colorspace.toLowerCase().includes("rgb")) throw Error(`Colorspace "${colorspace}", expected RGB`); } } - -function exec(command, print = true) { - const result = execSync(command).toString().trim(); - if (print) console.log(result); - return result; -} diff --git a/.github/clean.mjs b/.github/clean.mjs new file mode 100644 index 0000000..fdc3863 --- /dev/null +++ b/.github/clean.mjs @@ -0,0 +1,17 @@ +import { ExifTool } from "exiftool-vendored"; + +const exiftool = new ExifTool(); + +await stripMeta("./images"); +await stripMeta("./print"); + +await exiftool.end(); + +// strip all metadata from all images in folder to ensure consistency +async function stripMeta(folder) { + await exiftool.write(folder, {}, [ + "-All=", + "-recurse", + "-overwrite_original", + ]); +} diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 51daba7..ce993f3 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -1,6 +1,9 @@ -name: Check and clean files +name: Check files -on: pull_request +on: + pull_request: + branches: + - main jobs: check: @@ -11,13 +14,11 @@ jobs: with: ref: ${{ github.head_ref }} - - name: Install exiftool - run: sudo apt install exiftool + - name: Install packages + run: npm install exiftool-vendored@26 - - name: Run script - run: node ./.github/check.js + - if: runner.debug == '1' + uses: mxschmitt/action-tmate@v3 - - name: Commit changed files - uses: stefanzweifel/git-auto-commit-action@v5 - with: - commit_message: "Update files" + - name: Run script + run: node ./.github/check.mjs diff --git a/.github/workflows/clean.yaml b/.github/workflows/clean.yaml new file mode 100644 index 0000000..3c22e95 --- /dev/null +++ b/.github/workflows/clean.yaml @@ -0,0 +1,27 @@ +name: Clean files + +on: + push: + branches: + - main + +jobs: + clean: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install packages + run: npm install exiftool-vendored@26 + + - if: runner.debug == '1' + uses: mxschmitt/action-tmate@v3 + + - name: Run script + run: node ./.github/clean.mjs + + - name: Commit changed files + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "Clean files" diff --git a/.gitignore b/.gitignore index fd5106f..2023a37 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ +node_modules +package.json +package-lock.json .DS_STORE diff --git a/README.md b/README.md index 6fcb760..cf73071 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,6 @@ The order of entries on the website is shuffled randomly on each page visit to n 1. [Fork this repo](https://github.dev/CU-DBMI/wall-of-software) and make one or more changes. 1. Open a pull request (PR). - Check "Allow edits by maintainers". Name the PR the canonical name(s) of the software/group(s) you're changing, using commas for multiple, e.g. "Word Lapse, Preprint Similarity Search". 1. Shortly after opening the PR, a link will appear that shows a preview of the website with your changes (if any). Add `?print` at the end of the url to view the print versions of images instead. @@ -59,7 +58,7 @@ To remove/change entries, edit the above files as needed. ## Images -Images should meet the following standards: +Images must meet the following standards: - Unique, visually appealing logo or other graphical representation of your software/group. - Not up-scaled, stretched, or otherwise blurry/noisy/distorted/etc.