Skip to content

Commit

Permalink
feat: add mysql and redis service (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Feb 28, 2023
1 parent 378e943 commit 8d2469e
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 1 deletion.
117 changes: 117 additions & 0 deletions .github/workflows/node-test-mysql.yml
@@ -0,0 +1,117 @@
name: Node.js Unit Test

on:
workflow_call:
inputs:
os:
type: string
description: 'Operator System, such as: ubuntu-latest,macos-latest'
default: 'ubuntu-latest, macos-latest, windows-latest'

version:
type: string
description: 'Node.js Version, such as 16, 18'
default: '16, 18'

install:
type: string
description: 'Install dependencies script'
default: 'npm i --no-package-lock --no-fund'

action_ref:
type: string
description: 'Branch name for artusjs/github-actions, for test purpose'
default: master

mysql_version:
type: string
description: mysql version
default: '5'

jobs:
Setup:
runs-on: ubuntu-latest
outputs:
os: ${{ steps.handler.outputs.os }}
version: ${{ steps.handler.outputs.version }}

steps:
# Checkout action repository
- name: Checkout
uses: actions/checkout@v3
with:
repository: artusjs/github-actions
path: action_repo
ref: ${{ inputs.action_ref }}

# Setup Node.js environment
- name: Setup Node.js
uses: actions/setup-node@v3

# Install dependencies
- name: Install dependencies
run: npm i --no-package-lock --no-fund
working-directory: action_repo/scripts/test

# Normalize inputs style
- name: Convert Inputs to Matrix
id: handler
run: node action_repo/scripts/test/index.js
env:
INPUT_OS: ${{ inputs.os }}
INPUT_VERSION: ${{ inputs.version }}

Test:
needs: Setup
strategy:
fail-fast: false
matrix:
os: ${{ fromJSON(needs.setup.outputs.os) }}
version: ${{ fromJSON(needs.setup.outputs.version) }}

name: Test (${{ matrix.os }}, ${{ matrix.version }})
runs-on: ${{ matrix.os }}

services:
mysql:
image: mysql:${{ inputs.mysql_version }}
env:
MYSQL_ALLOW_EMPTY_PASSWORD: true
MYSQL_DATABASE: test
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5

redis:
# https://docs.github.com/en/actions/using-containerized-services/about-service-containers#example-mapping-redis-ports
image: redis
ports:
# Opens tcp port 6379 on the host and service container
- 6379:6379

concurrency:
group: ${{ github.workflow }}-#${{ github.event.pull_request.number || github.ref }}-(${{ matrix.os }}, ${{ matrix.version }})
cancel-in-progress: true

steps:
- name: Checkout Git Source
uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.version }}

- name: Install Dependencies
run: ${{ inputs.install }}

- name: Run Lint
run: npm run lint --if-present

- name: Run Test
run: npm run ci

- name: Code Coverage
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/node-test.yml
Expand Up @@ -84,7 +84,7 @@ jobs:
run: ${{ inputs.install }}

- name: Run Lint
run: npm run lint
run: npm run lint --if-present

- name: Run Test
run: npm run ci
Expand Down

0 comments on commit 8d2469e

Please sign in to comment.