Skip to content

Commit

Permalink
Add test to check for missing assignments of fake passwords
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlul committed Jul 16, 2023
1 parent 5ae7c9e commit fa3650f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/validate-data.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-FileCopyrightText: © 2023 Kevin Lu
# SPDX-Licence-Identifier: AGPL-3.0-or-later
name: Validate data does not contain wikitext templates
name: Validate data

on:
push:
Expand All @@ -19,5 +19,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: |
- uses: actions/setup-node@v3
with:
node-version: 18
cache: yarn
- name: Does not contain wikitext templates
run: |
! grep {{ -R data --include='*.yaml'
- name: Cards are not missing placeholder fake passwords
if: success() || failure()
run: yarn check-for-missing-fake-password data/cards
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"download-tcg": "cd data/limit-regulation/tcg && ts-node ../../../src/limit-regulation/tcg-extract-transform.ts",
"download-ocg": "cd data/limit-regulation/ocg && ts-node ../../../src/limit-regulation/ocg-extract-transform.ts",
"download-rush": "cd data/limit-regulation/rush && ts-node ../../../src/limit-regulation/rush-extract-transform.ts",
"load": "ts-node src/load.ts"
"load": "ts-node src/load.ts",
"check-for-missing-fake-password": "ts-node src/assignments/check-for-missing.ts"
},
"engines": {
"node": ">=18",
Expand Down
28 changes: 28 additions & 0 deletions src/assignments/check-for-missing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-FileCopyrightText: © 2023 Kevin Lu
// SPDX-Licence-Identifier: AGPL-3.0-or-later
import fs from "fs";
import path from "path";

if (process.argv.length < 3) {
console.error(`Usage: ${process.argv[1]} <data/cards>`);
process.exit(1);
}

(async () => {
const files = await fs.promises.readdir(process.argv[2]);
const missingFakePasswords = [];
for (const file of files) {
if (file.endsWith(".json")) {
const card = JSON.parse(await fs.promises.readFile(path.join(process.argv[2], file), "utf8"));
if (!card.password && !card.fake_password) {
missingFakePasswords.push(card);
}
}
}
if (missingFakePasswords.length) {
for (const card of missingFakePasswords) {
console.log(`${card.yugipedia_page_id}\t[${card.name.en}]`);
}
process.exit(2);
}
})();

0 comments on commit fa3650f

Please sign in to comment.