diff --git a/.github/actions/testing/action.yml b/.github/actions/testing/action.yml new file mode 100644 index 0000000..2d4e225 --- /dev/null +++ b/.github/actions/testing/action.yml @@ -0,0 +1,41 @@ +name: 'Testing' + +inputs: + npm_token: + description: 'npm_token' + required: true + node_v: + type: string + required: false + default: "12.14.1" + redis_url: + type: string + required: false + db_url: + type: string + required: false + +runs: + using: "composite" + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v3 + with: + persist-credentials: false + - name: setup node + uses: actions/setup-node@master + with: + node-version: ${{ inputs.node_v }} + + # install application dependencies + - uses: c-hive/gha-npm-cache@v1 + - name: Install Dependencies + shell: bash + run: npm install + - name: Run tests + shell: bash + env: + REDIS_URL: ${{ inputs.redis_url }} + DB_URL: ${{ inputs.db_url }} + run: | + env IS_LOCAL_LOG=true npm run test \ No newline at end of file diff --git a/.github/workflows/node-testing-with-dbs-workflow.yaml b/.github/workflows/node-testing-with-dbs-workflow.yaml new file mode 100644 index 0000000..e4dd428 --- /dev/null +++ b/.github/workflows/node-testing-with-dbs-workflow.yaml @@ -0,0 +1,52 @@ +name: Node testing with DB and Redis workflow + +on: + workflow_call: + secrets: + NPM_TOKEN: + required: true + inputs: + node_v: + type: string + required: false + default: "12.14.1" +env: + ## Sets environment variable + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + NODE_OPTIONS: "--max-old-space-size=4096" + +jobs: + testing: + # The type of runner that the job will run on + # Containers must run in Linux based operating systems + runs-on: app_backend + + container: node:${{ inputs.node_v }} + + # Service containers to add` + services: + # Label used to access the service container + redis: + image: redis + # Set health checks to wait until redis has started + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + mysql: + image: mysql:5.7 + ports: + - 3306:3306 + env: + MYSQL_ROOT_PASSWORD: '1234' + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + - name: Testing + uses: totango/shared-github-actions/.github/actions/testing@main + id: image + with: + node_v: ${{ inputs.node_v }} + npm_token: ${{ secrets.NPM_TOKEN }} + db_url: mysql + redis_url: redis \ No newline at end of file diff --git a/.github/workflows/node-testing-workflow.yaml b/.github/workflows/node-testing-workflow.yaml index 3d2ca4f..b4b783b 100644 --- a/.github/workflows/node-testing-workflow.yaml +++ b/.github/workflows/node-testing-workflow.yaml @@ -23,34 +23,11 @@ jobs: container: node:${{ inputs.node_v }} - # Service containers to add` - services: - # Label used to access the service container - redis: - image: redis - # Set health checks to wait until redis has started - options: >- - --health-cmd "redis-cli ping" - --health-interval 10s - --health-timeout 5s - --health-retries 5 # Steps represent a sequence of tasks that will be executed as part of the job steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v3 + - name: Testing + uses: totango/shared-github-actions/.github/actions/testing@main + id: image with: - persist-credentials: false - - name: setup node - uses: actions/setup-node@master - with: - node-version: ${{ inputs.node_v }} - - # install application dependencies - - uses: c-hive/gha-npm-cache@v1 - - name: Install Dependencies - run: npm install - - name: Run tests - env: - REDIS_URL: 'redis' - run: | - env IS_LOCAL_LOG=true npm run test \ No newline at end of file + node_v: ${{ inputs.node_v }} + npm_token: ${{ secrets.NPM_TOKEN }} \ No newline at end of file