Skip to content

Commit

Permalink
Merge branch 'release/0.5.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
prisca-c committed Sep 6, 2024
2 parents 4d5a0e0 + 43b0867 commit 2293882
Show file tree
Hide file tree
Showing 155 changed files with 9,628 additions and 5,112 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ DB_DATABASE=
REDIS_PASSWORD=
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_DB=0

TWITCH_CLIENT_ID=
TWITCH_CLIENT_SECRET=
TWITCH_CALLBACK_URL=

# Game length in seconds
GAME_LENGTH=90
5 changes: 5 additions & 0 deletions .env.test.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
NODE_ENV=test
SESSION_DRIVER=memory
DB_CONNECTION=postgres
DB_DATABASE=
REDIS_DB=1
130 changes: 130 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: CI

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 21

- name: Install pnpm
run: |
corepack enable
corepack prepare pnpm@latest --activate
- name: Install dependencies
run: pnpm install

- name: Lint
run: pnpm lint

typecheck:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 21

- name: Install pnpm
run: |
corepack enable
corepack prepare pnpm@latest --activate
- name: Install dependencies
run: |
pnpm install
pnpm -r build
- name: Typecheck
run: pnpm typecheck

build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 21

- name: Install pnpm
run: |
corepack enable
corepack prepare pnpm@latest --activate
- name: Install dependencies
run: pnpm install

- name: Build
run: pnpm build

tests:
runs-on: ubuntu-latest
timeout-minutes: 10

services:
redis:
image: redis:6.2-alpine
ports:
- 6379:6379
postgres:
image: postgres:15-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 21

- name: Install pnpm
run: |
corepack enable
corepack prepare pnpm@latest --activate
- name: Install dependencies
run: |
pnpm install
- name: Run tests
env:
APP_KEY: 1234567890123456
NODE_ENV: test
PORT: 3030
HOST: localhost
LOG_LEVEL: info
SESSION_DRIVER: memory
REDIS_HOST: localhost
REDIS_PORT: 6379
REDIS_DB: 1
DB_CONNECTION: postgres
DB_HOST: localhost
DB_PORT: 5432
DB_USER: postgres
DB_PASSWORD: postgres
DB_DATABASE: postgres
TWITCH_CLIENT_ID: client_id
TWITCH_CLIENT_SECRET: client_secret
TWITCH_CALLBACK_URL: http://localhost:3333/auth/twitch/callback
GAME_LENGTH: 90
run: FORCE_COLOR=1 pnpm test -r
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ yarn-error.log
# Platform specific
.DS_Store
/data/
/.env.test
38 changes: 38 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,44 @@

## [UNRELEASED]

## [0.5.0] - 2024-09-06

### Added
- When guesser reached 5 words, game ends
- When game end, session is saved in database and deleted from cache (redis)
- Add `GameRules` class to handle game logic from `GameUseCase` class
- Add tests for :
- `GameRules` class (unit tests)
- `Matchmaking - Search` Controller (functional tests)
- `Matchmaking - Accept` Controller (functional tests)
- `MatchPlayerJob` class job (unit tests)
- Add CI Pipeline `.github/workflows/checks.yml` to check code quality and run tests
- Add an elo system to handle player ranking.
- Word stats are updated in database when game ends
- Word's form is now a single component `word_form.tsx` which handle error correctly using i18n, hooks, and WordValidationStateEnum
- Game takes 1min30s to end if no one found the word , added many things to handle this :
- `GameSession` now have a status which takes a `SessionState` to handle the game state {MATCHMAKING, READY, PLAYING}
- Create `PlayerSession` which handle `Player` & `{accepted: boolean, ready: boolean}` , ready is used to know if the player is ready to play
- Create `GameReadyController` + route to handle player ready state, start the game and use a setTimeout to end the game if no one found the word
- In frontend, added a useTimer hook to handle the timer and display it
- Add in game Infos :
- Show opponent's infos at the end of the game
- Show word at the end of the game
- Show current turn info
- Add a Profile page to show game's history
- Add a player card to show player's infos

### Changed
- Add `Cache` service and update all Redis calls to use it
- Add `EventStream` service and update all Transmit calls to use it
- Change project architecture
- Update `GameRules.validWord` method by adding `ValidWordState` to have more precise return value
- Switch from `Tailwind` to `UnoCSS`

### Fixed
- Fix issue from transmit listener not closing properly when unmounting a component
- Guesser now got the word when he found it or not

## [0.4.0] - 2024-05-18

### Added
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The game is simple, one user have a word given and the other person have to gues
## Technologies
- AdonisJS
- SSR with AdonisJS (InertiaJS - React)
- TailwindCSS
- UnoCSS
- Redis
- PostgreSQL
- Docker
Expand All @@ -19,6 +19,7 @@ The game is simple, one user have a word given and the other person have to gues
3. Copy `.env.example` to `.env` and fill the variables
4. Run `docker-compose up -d`
5. Run `pnpm dev`
6. Access `http://localhost:3333`
6. Run `pnpm jobs:run`
7. Access `http://localhost:3333`


36 changes: 29 additions & 7 deletions adonisrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ export default defineConfig({
| will be scanned automatically from the "./commands" directory.
|
*/
commands: [() => import('@adonisjs/core/commands'), () => import('@adonisjs/lucid/commands'), () => import('adonisjs-scheduler/commands')],
commands: [
() => import('@adonisjs/core/commands'),
() => import('@adonisjs/lucid/commands'),
() => import('adonisjs-scheduler/commands'),
],

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -45,9 +49,23 @@ export default defineConfig({
{
file: () => import('adonisjs-scheduler/scheduler_provider'),
environment: ['console'],
}
},
() => import('#core/providers/port_provider'),
],

/*
|--------------------------------------------------------------------------
| Directories
|--------------------------------------------------------------------------
|
| Register custom directories paths.
|
*/
directories: {
migrations: '#core/database/migrations',
seeders: '#core/database/seeders',
},

/*
|--------------------------------------------------------------------------
| Preloads
Expand All @@ -56,10 +74,14 @@ export default defineConfig({
| List of modules to import before starting the application.
|
*/
preloads: [() => import('#start/routes'), () => import('#start/kernel'), {
file: () => import('#start/scheduler'),
environment: ['console'],
}],
preloads: [
() => import('#start/routes'),
() => import('#start/kernel'),
{
file: () => import('#start/scheduler'),
environment: ['console'],
},
],

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -111,7 +133,7 @@ export default defineConfig({
],

assetsBundler: false,
unstable_assembler: {
hooks: {
onBuildStarting: [() => import('@adonisjs/vite/build_hook')],
},
})
7 changes: 5 additions & 2 deletions config/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import env from '#start/env'
import { defineConfig } from '@adonisjs/lucid'

const dbConfig = defineConfig({
connection: 'postgres',
connection: env.get('DB_CONNECTION'),
connections: {
postgres: {
client: 'pg',
Expand All @@ -15,7 +15,10 @@ const dbConfig = defineConfig({
},
migrations: {
naturalSort: true,
paths: ['database/migrations'],
paths: ['src/core/database/migrations'],
},
seeders: {
paths: ['src/core/database/seeders'],
},
},
},
Expand Down
1 change: 1 addition & 0 deletions config/inertia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ export default defineConfig({
ssr: {
enabled: true,
entrypoint: 'inertia/app/ssr.tsx',
pages: (_ctx, page) => !page.includes('game/session'),
},
})
14 changes: 12 additions & 2 deletions config/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { defineConfig } from '@adonisjs/redis'
import { InferConnections } from '@adonisjs/redis/types'

const redisConfig = defineConfig({
connection: 'main',
connection: env.get('NODE_ENV') === 'test' ? 'test' : 'main',

connections: {
/*
Expand All @@ -26,11 +26,21 @@ const redisConfig = defineConfig({
return times > 10 ? null : times * 50
},
},
test: {
host: env.get('REDIS_HOST'),
port: env.get('REDIS_PORT'),
password: env.get('REDIS_PASSWORD', ''),
db: 1,
keyPrefix: '',
retryStrategy(times) {
return times > 10 ? null : times * 50
},
},
},
})

export default redisConfig

declare module '@adonisjs/redis/types' {
export interface RedisConnections extends InferConnections<typeof redisConfig> {}
}
}
5 changes: 3 additions & 2 deletions inertia/app/app.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'virtual:uno.css'
import '../css/app.css'
import { hydrateRoot } from 'react-dom/client'
import { createInertiaApp } from '@inertiajs/react'
import '~/services/i18n'
import { Layout } from '~/components/layout'
import '~/features/i18n/i18n'
import { Layout } from '~/features/layout/layout'

const appName = import.meta.env.VITE_APP_NAME || 'AdonisJS'

Expand Down
4 changes: 2 additions & 2 deletions inertia/app/ssr.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ReactDOMServer from 'react-dom/server'
import { createInertiaApp } from '@inertiajs/react'
import '~/services/i18n'
import { Layout } from '~/components/layout'
import '~/features/i18n/i18n'
import { Layout } from '~/features/layout/layout'

export default function render(page: any) {
return createInertiaApp({
Expand Down
Loading

0 comments on commit 2293882

Please sign in to comment.