misc/github ci test 워크플로우 추가 #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs | |
name: CI | |
on: | |
pull_request: | |
branches: ['main'] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [20.x] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Cache node modules | |
id: node-cache | |
uses: actions/cache@v4 | |
env: | |
cache-name: cache-node-modules | |
with: | |
path: | | |
**/node_modules | |
~/.cache | |
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json')}} | |
restore-keys: | | |
${{ runner.os }}-node-modules- | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Clean install | |
if: steps.node-cache.outputs.cache-hit != 'true' | |
run: npm ci | |
ci-test: | |
runs-on: ubuntu-latest | |
needs: [build] | |
timeout-minutes: 10 | |
strategy: | |
fail-fast: false | |
matrix: | |
workspace: ['test:e2e', 'test:unit'] | |
services: | |
redis: | |
image: redis | |
ports: | |
- 6379:6379 | |
mysql: | |
image: mysql:8.0.23 | |
env: | |
DB_USERNAME: anniemon | |
DB_PASSWORD: anniemon | |
DB_NAME: e-commerce_test | |
MYSQL_ROOT_PASSWORD: root | |
ports: | |
- 3306 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 1 | |
- name: Cache node modules | |
id: cache | |
uses: actions/cache@v4 | |
with: | |
path: | | |
**/node_modules | |
~/.cache | |
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json')}} | |
- name: Clean Install | |
if: steps.cache.outputs.cache-hit != 'true' | |
run: npm ci --include dev | |
- name: Start MySQL | |
run: sudo service mysql start | |
- name: Create DB | |
run: mysql -h 127.0.0.1 -uroot -proot -e "CREATE DATABASE IF NOT EXISTS e-commerce_test CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; CREATE USER 'root'@'%' IDENTIFIED BY 'root'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; CREATE USER 'anniemon'@'%' IDENTIFIED BY 'anniemon'; GRANT ALL PRIVILEGES ON *.* TO 'anniemon'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES; " | |
- name: CI test ${{ matrix.workspace }} | |
run: | | |
npm run ${{ matrix.workspace}} | |
env: | |
NODE_ENV: test | |
CI: true |