Skip to content

Commit 8d91b47

Browse files
committed
build: add github actions to check pushes
It includes a fix to handle timezone in the tests.
1 parent a092c5c commit 8d91b47

7 files changed

Lines changed: 98 additions & 16 deletions

File tree

.github/actions/build/action.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Build the project
2+
description: Run tests and build the project
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Run check (format, lint, types)
8+
shell: bash
9+
run: npm run check
10+
11+
- name: Run tests
12+
shell: bash
13+
run: npm run test
14+
15+
- name: Build
16+
shell: bash
17+
run: npm run build

.github/actions/prepare/action.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Prepare the project
2+
description: Install all the necessary dependencies
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Setup pnpm
8+
uses: pnpm/action-setup@v4
9+
with:
10+
cache: true
11+
12+
- name: Setup node
13+
uses: actions/setup-node@v5
14+
with:
15+
node-version: 24
16+
17+
- name: Install npm dependencies
18+
shell: bash
19+
run: pnpm install
20+
21+
- name: Install playwright system dependencies
22+
shell: bash
23+
run: ./node_modules/.bin/playwright install --with-deps

.github/workflows/check.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Check
2+
run-name: Check - ${{ github.ref_name }}
3+
4+
on:
5+
push:
6+
7+
workflow_dispatch: # Allow to manually trigger the pipeline
8+
9+
# If several pushes are made on a single branch, only build the last one.
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
check:
16+
runs-on: ubuntu-24.04
17+
steps:
18+
- uses: actions/checkout@v5
19+
20+
- uses: ./.github/actions/prepare
21+
22+
- uses: ./.github/actions/build

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"fix": "pnpm run --stream /^fix:/",
1414
"fix:format": "prettier . --cache --write --experimental-cli",
1515
"fix:lint": "oxlint --type-aware --fix",
16-
"prepare": "husky && playwright install",
16+
"prepare": "husky && playwright install chromium",
1717
"serve": "vite preview",
1818
"test": "vitest run"
1919
},
@@ -49,5 +49,6 @@
4949
"vite-plugin-singlefile": "2.3.0",
5050
"vite-plugin-solid": "2.11.10",
5151
"vitest": "4.0.17"
52-
}
52+
},
53+
"packageManager": "pnpm@10.28.0+sha512.05df71d1421f21399e053fde567cea34d446fa02c76571441bfc1c7956e98e363088982d940465fd34480d4d90a0668bc12362f8aa88000a64e83d0b0e47be48"
5354
}

src/domains/attempt/schemas/attempt.test.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ import * as v from "valibot";
22
import { type Attempt, AttemptSchema } from "./attempt";
33
import { describe, expect, test } from "vitest";
44
import type { AttemptEntity } from "../../database/schemas/attempt-entity";
5+
import { DateTime } from "../utils/date-time";
56
import type { SplitEntity } from "../../database/schemas/split-entity";
67

78
const parse = (attemptEntity: AttemptEntity): Attempt => {
89
return v.parse(AttemptSchema, attemptEntity);
910
};
1011

12+
const date = new Date();
13+
const timestamp = date.getTime();
14+
const timezoneOffsetMs = date.getTimezoneOffset() * 60 * 1000;
15+
1116
describe("attemptSchema", () => {
1217
const attemptEntity: AttemptEntity = {
13-
timestamp: 1_767_455_414_145,
18+
timestamp: timestamp,
1419
player: "Noname",
1520
track: "A track",
1621
laps: 3,
@@ -39,8 +44,8 @@ describe("attemptSchema", () => {
3944
const attempt = parse(attemptEntity);
4045
expect(attempt.time).toBeUndefined();
4146
expect(attempt.coins).toBeUndefined();
42-
expect(attempt.date).toBe("2026.01.03");
43-
expect(attempt.datetime).toBe("16:50:14");
47+
expect(attempt.date).toBe(DateTime.formatDate(timestamp));
48+
expect(attempt.datetime).toBe(DateTime.formatTime(timestamp));
4449
expect(attempt.laps).toStrictEqual([1, 2, 3]);
4550
expect(attempt.splits).toHaveLength(0);
4651
expect(attempt.raw).toStrictEqual(attemptEntity);
@@ -58,8 +63,8 @@ describe("attemptSchema", () => {
5863
accumulatedCoins: 3,
5964
time: "1:00.000",
6065
accumulatedTime: "1:00.000",
61-
parsedTime: -3_540_000,
62-
parsedAccumulatedTime: -3_540_000,
66+
parsedTime: 60_000 + timezoneOffsetMs,
67+
parsedAccumulatedTime: 60_000 + timezoneOffsetMs,
6368
raw: split_1,
6469
});
6570
});
@@ -76,26 +81,26 @@ describe("attemptSchema", () => {
7681
accumulatedCoins: 3,
7782
time: "1:00.000",
7883
accumulatedTime: "1:00.000",
79-
parsedTime: -3_540_000,
80-
parsedAccumulatedTime: -3_540_000,
84+
parsedTime: 60_000 + timezoneOffsetMs,
85+
parsedAccumulatedTime: 60_000 + timezoneOffsetMs,
8186
raw: split_1,
8287
});
8388
expect(attempt.splits.at(1)).toStrictEqual({
8489
coins: -2,
8590
accumulatedCoins: 1,
8691
time: "1:00.000",
8792
accumulatedTime: "2:00.000",
88-
parsedTime: -3_540_000,
89-
parsedAccumulatedTime: -7_080_000,
93+
parsedTime: 60_000 + timezoneOffsetMs,
94+
parsedAccumulatedTime: 2 * (60_000 + timezoneOffsetMs),
9095
raw: split_2,
9196
});
9297
expect(attempt.splits.at(2)).toStrictEqual({
9398
coins: 1,
9499
accumulatedCoins: 2,
95100
time: "1:00.000",
96101
accumulatedTime: "3:00.000",
97-
parsedTime: -3_540_000,
98-
parsedAccumulatedTime: -10_620_000,
102+
parsedTime: 60_000 + timezoneOffsetMs,
103+
parsedAccumulatedTime: 3 * (60_000 + timezoneOffsetMs),
99104
raw: split_3,
100105
});
101106
});

src/domains/attempt/schemas/attempt.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import * as v from "valibot";
22
import { AttemptEntitySchema } from "../../database/schemas/attempt-entity";
3+
import { DateTime } from "../utils/date-time";
34
import { Time } from "../utils/time";
4-
import { format } from "date-and-time";
55
import { generateArray } from "../../_core/utils/generate-array";
66

77
export const AttemptSchema = v.pipe(
88
AttemptEntitySchema,
99
v.transform((attemptEntity) => {
10-
const date = format(new Date(attemptEntity.timestamp), "YYYY.MM.DD");
11-
const datetime = format(new Date(attemptEntity.timestamp), "HH:mm:ss");
10+
const date = DateTime.formatDate(attemptEntity.timestamp);
11+
const datetime = DateTime.formatTime(attemptEntity.timestamp);
1212
const laps = generateArray(attemptEntity.laps);
1313
const rowSplits = attemptEntity.laps * 2 - 1;
1414

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { compile, format } from "date-and-time";
2+
3+
const compiledDay = compile("YYYY.MM.DD");
4+
const compiledTime = compile("HH:mm:ss");
5+
6+
// It would be better to handle it internally without rely on an external library.
7+
export const DateTime = {
8+
formatDate(timestamp: number): string {
9+
return format(new Date(timestamp), compiledDay);
10+
},
11+
formatTime(timestamp: number): string {
12+
return format(new Date(timestamp), compiledTime);
13+
},
14+
};

0 commit comments

Comments
 (0)