diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..fa495d2 --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,68 @@ +name: Node.js CI + +on: + push: + branches: + - main + pull_request: + branches: + - main + +env: + PORT: "3000" + NODE_ENV: "development" + DB_USERNAME: "user" + DB_PASSWORD: "password123" + DB_NAME: "api" + DB_HOST: "localhost" + DB_PORT: "3306" + DATABASE_URL: "mysql://user:password123@localhost:3306/api" + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Use PNPM as package manager + uses: pnpm/action-setup@v2 + with: + version: 8 + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: "20" + cache: pnpm + + - name: Install dependencies + run: pnpm install + + - name: Run ESLint + run: pnpm exec eslint src/**/*.ts + + - name: Build + run: pnpm build + + - name: Run tests + run: | + pnpm infra:up + sleep 5 + pnpm test + + - name: Build container and test health + run: | + docker build -t poll-api . + pnpm infra:up + docker container run -d -p 3000:3000 \ + --rm --name poll \ + -e DB_USERNAME='user' -e DB_PASSWORD='password123' \ + -e DB_NAME='api' -e DB_HOST='mysql' \ + -e DB_PORT='3306' -e NODE_ENV='development' \ + -e PORT='3000' \ + --network pollNetwork \ + poll-api + sleep 5 + curl localhost:3000/healthy diff --git a/docker-compose.yaml b/docker-compose.yaml index 7262f5b..dfd1b9c 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -4,6 +4,8 @@ services: mysql: image: mysql:8.0 container_name: mysql + networks: + - pollNetwork environment: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: ${DB_NAME} @@ -13,3 +15,8 @@ services: - "${DB_PORT}:${DB_PORT}" restart: always command: --default-authentication-plugin=mysql_native_password + + +networks: + pollNetwork: + name: pollNetwork \ No newline at end of file