Skip to content

Commit

Permalink
feat(ci): add unified test/lint command
Browse files Browse the repository at this point in the history
  • Loading branch information
rpidanny committed Dec 22, 2023
1 parent 47ab873 commit d30e1a4
Show file tree
Hide file tree
Showing 84 changed files with 3,993 additions and 542 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/2019-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ jobs:
working-directory: ./${{ env.YEAR }}

- name: Lint
run: |
isort --check-only .
black --check .
run: make lint
working-directory: ./${{ env.YEAR }}

- name: Test
run: ./run-tests.sh
run: make test
working-directory: ./${{ env.YEAR }}
5 changes: 4 additions & 1 deletion .github/workflows/2022-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ jobs:
- run: npm ci
working-directory: ./${{ env.YEAR }}

- run: npm test
- run: make lint
working-directory: ./${{ env.YEAR }}

- run: make test
working-directory: ./${{ env.YEAR }}
4 changes: 2 additions & 2 deletions .github/workflows/2023-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ jobs:
- run: npm ci
working-directory: ./${{ env.YEAR }}

- run: npm run lint
- run: make lint
working-directory: ./${{ env.YEAR }}

- run: npm test
- run: make test
working-directory: ./${{ env.YEAR }}
42 changes: 42 additions & 0 deletions 2019/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
GREEN:=\033[0;32m
NC:=\033[0m
RED:=\033[0;31m

DAYS:=$(shell ls -d */ | sed 's:/$$::' | grep -E '^Day[0-9]{2}' | sort -u)


init: # Init folder for a given [day]
ifndef day
@echo "[day] must be defined"
else ifneq ("$(wildcard Day$(day))", "")
@echo "directory already exists"
else
@mkdir -p Day$(day)
@cp Day00/* Day$(day)
@grep -rl "Day 0" Day$(day)/solutions.spec.ts | xargs sed -i "" "s/Day 0/Day $(day)/g"
@echo "Day$(day) created! happy coding!"
endif

test: # Run tests
ifndef day
@echo "Running all tests for 2019"
@for day in $(DAYS); do \
echo "----------------------------------------------------------------------"; \
echo "$(GREEN)Running tests for $$day...$(NC)"; \
pytest -v $$day || exit 1; \
done;
else
@echo "$(GREEN)Running tests for Day$(day)...$(NC)"
@pytest -v Day$(day) || exit 1
endif

lint: # Run linter
ifndef day
@echo "Running linter for 2019"
@black --check .
@isort --check-only .
else
@echo "$(GREEN)Running linter for Day$(day)...$(NC)"
@black --check ./Day$(day)
@isort --check-only ./Day$(day)
endif
7 changes: 0 additions & 7 deletions 2019/run-tests.sh

This file was deleted.

25 changes: 25 additions & 0 deletions 2022/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
env: {
browser: true,
commonjs: true,
es2021: true,
},
extends: ['google', 'prettier'],
overrides: [
{
env: {
node: true,
},
files: ['.eslintrc.{js,cjs}'],
parserOptions: {
sourceType: 'script',
},
},
],
parserOptions: {
ecmaVersion: 'latest',
},
rules: {
'require-jsdoc': 'off',
},
};
7 changes: 7 additions & 0 deletions 2022/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": true,
"arrowParens": "always",
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": true
}
10 changes: 5 additions & 5 deletions 2022/Day00/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { getInputLines } = require("../utils/input");
const { day } = require("./config");
const { step1, step2 } = require("./solutions");
const {getInputLines} = require('../utils/input');
const {day} = require('./config');
const {step1, step2} = require('./solutions');

const TEST_MODE = false;

let rawInputs = getInputLines(
TEST_MODE ? `./Day${day}/test.input.txt` : `./Day${day}/input.txt`
const rawInputs = getInputLines(
TEST_MODE ? `./Day${day}/test.input.txt` : `./Day${day}/input.txt`,
);

console.log(`Step1: ${step1(rawInputs)}`);
Expand Down
2 changes: 1 addition & 1 deletion 2022/Day00/solutions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {} = require("./helpers");
const {} = require('./helpers');

// Part 1;
function step1(inputs) {
Expand Down
14 changes: 7 additions & 7 deletions 2022/Day00/solutions.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const { getInputLines } = require("../utils/input");
const { step1, step2 } = require("./solutions");
const { day} = require('./config');
const {getInputLines} = require('../utils/input');
const {step1, step2} = require('./solutions');
const {day} = require('./config');

describe("Solutions", () => {
let input = getInputLines(`./Day${day}/test.input.txt`);
test("step 1", () => {
describe('Solutions', () => {
const input = getInputLines(`./Day${day}/test.input.txt`);
test('step 1', () => {
expect(step1(input)).toEqual(123);
});

test("step 2", () => {
test('step 2', () => {
expect(step2(input)).toEqual(456);
});
});
2 changes: 1 addition & 1 deletion 2022/Day01/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const getTotalCaloriesPerElf = (foodItems) => {

let calories = 0;
for (const food of foodItems) {
if (food === "") {
if (food === '') {
totalCalories.push(calories);
calories = 0;
} else {
Expand Down
10 changes: 5 additions & 5 deletions 2022/Day01/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { getInputLines } = require("../utils/input");
const { day } = require("./config");
const { step1, step2 } = require("./solutions");
const {getInputLines} = require('../utils/input');
const {day} = require('./config');
const {step1, step2} = require('./solutions');

const TEST_MODE = false;

let rawInputs = getInputLines(
TEST_MODE ? `./Day${day}/test.input.txt` : `./Day${day}/input.txt`
const rawInputs = getInputLines(
TEST_MODE ? `./Day${day}/test.input.txt` : `./Day${day}/input.txt`,
);

console.log(`Step1: ${step1(rawInputs)}`);
Expand Down
10 changes: 4 additions & 6 deletions 2022/Day01/solutions.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
const {
getTotalCaloriesPerElf,
getCaloriesSumOfTopKElves,
} = require("./helpers");
} = require('./helpers');

const step1 = (inputs) => {
return getTotalCaloriesPerElf(inputs)[0];
};
const step1 = (inputs) => getTotalCaloriesPerElf(inputs)[0];

const step2 = (inputs) => {
const totalCaloriesPerElves = getTotalCaloriesPerElf(inputs);
Expand All @@ -15,5 +13,5 @@ const step2 = (inputs) => {

module.exports = {
step1,
step2
}
step2,
};
14 changes: 7 additions & 7 deletions 2022/Day01/solutions.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const { getInputLines } = require("../utils/input");
const { step1, step2 } = require("./solutions");
const { day} = require('./config');
const {getInputLines} = require('../utils/input');
const {step1, step2} = require('./solutions');
const {day} = require('./config');

describe("Solutions", () => {
let input = getInputLines(`./Day${day}/test.input.txt`);
test("step 1", () => {
describe('Solutions', () => {
const input = getInputLines(`./Day${day}/test.input.txt`);
test('step 1', () => {
expect(step1(input)).toEqual(24000);
});

test("step 2", () => {
test('step 2', () => {
expect(step2(input)).toEqual(45000);
});
});
22 changes: 9 additions & 13 deletions 2022/Day02/helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const getGames = (rawGames) => {
return rawGames.map((game) => game.split(" "));
};
const getGames = (rawGames) => rawGames.map((game) => game.split(' '));

// Game Mappings
const p1ScoreMappings = {
Expand All @@ -16,9 +14,9 @@ const p2ScoreMappings = {
};

const GameStateMapping = {
DRAW: "Y",
WIN: "Z",
LOOSE: "X",
DRAW: 'Y',
WIN: 'Z',
LOOSE: 'X',
};

// Step 1
Expand All @@ -33,9 +31,9 @@ const getTotalScoreFromGamePlay = (games) => {
// Draw
score += 3 + p2Score;
} else if (
(p1 === "A" && p2 === "Y") ||
(p1 === "B" && p2 === "Z") ||
(p1 === "C" && p2 === "X")
(p1 === 'A' && p2 === 'Y') ||
(p1 === 'B' && p2 === 'Z') ||
(p1 === 'C' && p2 === 'X')
) {
// Win
score += 6 + p2Score;
Expand All @@ -53,17 +51,15 @@ const getTotalScoreFromGamePlay = (games) => {
const getLoosingScore = (p1Score) => {
if (p1Score === 1) {
return 3;
} else {
return p1Score - 1;
}
return p1Score - 1;
};

const getWinningScore = (p1Score) => {
if (p1Score === 3) {
return 1;
} else {
return p1Score + 1;
}
return p1Score + 1;
};

const getTotalScoreFromGameConditions = (games) => {
Expand Down
10 changes: 5 additions & 5 deletions 2022/Day02/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { getInputLines } = require("../utils/input");
const { day } = require("./config");
const { step1, step2 } = require("./solutions");
const {getInputLines} = require('../utils/input');
const {day} = require('./config');
const {step1, step2} = require('./solutions');

const TEST_MODE = false;

let rawInputs = getInputLines(
TEST_MODE ? `./Day${day}/test.input.txt` : `./Day${day}/input.txt`
const rawInputs = getInputLines(
TEST_MODE ? `./Day${day}/test.input.txt` : `./Day${day}/input.txt`,
);

console.log(`Step1: ${step1(rawInputs)}`);
Expand Down
2 changes: 1 addition & 1 deletion 2022/Day02/solutions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const {
getGames,
getTotalScoreFromGamePlay,
getTotalScoreFromGameConditions,
} = require("./helpers");
} = require('./helpers');

const step1 = (inputs) => {
const games = getGames(inputs);
Expand Down
14 changes: 7 additions & 7 deletions 2022/Day02/solutions.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const { getInputLines } = require("../utils/input");
const { step1, step2 } = require("./solutions");
const { day} = require('./config');
const {getInputLines} = require('../utils/input');
const {step1, step2} = require('./solutions');
const {day} = require('./config');

describe("Solutions", () => {
let input = getInputLines(`./Day${day}/test.input.txt`);
test("step 1", () => {
describe('Solutions', () => {
const input = getInputLines(`./Day${day}/test.input.txt`);
test('step 1', () => {
expect(step1(input)).toEqual(15);
});

test("step 2", () => {
test('step 2', () => {
expect(step2(input)).toEqual(12);
});
});
8 changes: 4 additions & 4 deletions 2022/Day03/helpers.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const getPriority = (char) => {
let power = 0;

if (char.charCodeAt() < "a".charCodeAt()) {
power = char.charCodeAt() - "A".charCodeAt() + 27;
if (char.charCodeAt() < 'a'.charCodeAt()) {
power = char.charCodeAt() - 'A'.charCodeAt() + 27;
} else {
power = char.charCodeAt() - "a".charCodeAt() + 1;
power = char.charCodeAt() - 'a'.charCodeAt() + 1;
}
return power;
};

const getCommonItemInRucksackCompartments = (rucksack) => {
const length = rucksack.length;
const {length} = rucksack;
const m = length >> 1;

const compartment1 = rucksack.substr(0, m);
Expand Down
10 changes: 5 additions & 5 deletions 2022/Day03/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { getInputLines } = require("../utils/input");
const { step1, step2 } = require("./solutions");
const { day } = require("./config");
const {getInputLines} = require('../utils/input');
const {step1, step2} = require('./solutions');
const {day} = require('./config');

const TEST_MODE = false;

let rucksacks = getInputLines(
TEST_MODE ? `./Day${day}/test.input.txt` : `./Day${day}/input.txt`
const rucksacks = getInputLines(
TEST_MODE ? `./Day${day}/test.input.txt` : `./Day${day}/input.txt`,
);

console.log(`Step1: ${step1(rucksacks)}`);
Expand Down
2 changes: 1 addition & 1 deletion 2022/Day03/solutions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const {
getPriority,
getCommonItemInRucksackCompartments,
getCommonItemsInRucksacks,
} = require("./helpers");
} = require('./helpers');

// Part 1;
function step1(rucksacks) {
Expand Down
Loading

0 comments on commit d30e1a4

Please sign in to comment.