forked from fengmk2/github-actions
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add mysql and redis service (#1)
- Loading branch information
Showing
2 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }} |
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