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

Split workflows #16

Merged
merged 9 commits into from
Jun 11, 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
47 changes: 19 additions & 28 deletions .github/check.js → .github/check.mjs
Original file line number Diff line number Diff line change
@@ -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}"`);
Expand Down Expand Up @@ -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)
Expand All @@ -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;
}
17 changes: 17 additions & 0 deletions .github/clean.mjs
Original file line number Diff line number Diff line change
@@ -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",
]);
}
21 changes: 11 additions & 10 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Check and clean files
name: Check files

on: pull_request
on:
pull_request:
branches:
- main

jobs:
check:
Expand All @@ -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
27 changes: 27 additions & 0 deletions .github/workflows/clean.yaml
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
node_modules
package.json
package-lock.json
.DS_STORE
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down