.github/workflows/test.yml
name: test
on:
workflow_call:
inputs:
deployment_environment:
description: 'The targeted `DEPLOYMENT_ENVIRONMENT`'
required: false
default: dev
type: string
secrets:
AWS_ACCESS_KEY_ID:
required: true
AWS_SECRET_ACCESS_KEY:
required: true
CC_TEST_REPORTER_ID:
required: true
CHECK_RUN_REPORTER_TOKEN:
required: true
CODACY_PROJECT_TOKEN:
required: true
CODECOV_TOKEN:
required: true
COVERALLS_REPO_TOKEN:
required: true
REPORT_CI_TOKEN:
required: true
workflow_dispatch:
inputs:
deployment_environment:
description: 'The targeted `DEPLOYMENT_ENVIRONMENT`'
required: true
default: dev
type: choice
options:
- dev
- prd
secrets:
AWS_ACCESS_KEY_ID:
required: true
AWS_SECRET_ACCESS_KEY:
required: true
CC_TEST_REPORTER_ID:
required: true
CHECK_RUN_REPORTER_TOKEN:
required: true
CODACY_PROJECT_TOKEN:
required: true
CODECOV_TOKEN:
required: true
COVERALLS_REPO_TOKEN:
required: true
REPORT_CI_TOKEN:
required: true
jobs:
test:
name: Run `yarn test`
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: us-east-1
DEPLOY: false
DEPLOYMENT_ENVIRONMENT: ${{ github.event.inputs.deployment_environment || inputs.deployment_environment }}
runs-on:
- ubuntu-latest
concurrency: test-${{ github.ref }}
steps:
- name: Set variables
id: variables
run: |
echo "::set-output name=deployment_environment::$DEPLOYMENT_ENVIRONMENT"
echo "NODE_ENV=$DEPLOYMENT_ENVIRONMENT" >> $GITHUB_ENV
echo "PRINTABLE_PUPPETEER_NO_SANDBOX=$CI" >> $GITHUB_ENV
echo "CPU_ARCH=$RUNNER_ARCH" >> $GITHUB_ENV
echo "OS_NAME=$RUNNER_OS" >> $GITHUB_ENV
echo "BRANCH=$GITHUB_REF_NAME" >> $GITHUB_ENV
echo "GIT_BRANCH=$GITHUB_REF_NAME" >> $GITHUB_ENV
echo "COMMIT_SHA=$GITHUB_SHA" >> $GITHUB_ENV
echo "GIT_COMMIT_SHA=$GITHUB_SHA" >> $GITHUB_ENV
echo "BUILD_NUMBER=$GITHUB_RUN_ID" >> $GITHUB_ENV
echo "JOB_NUMBER=$GITHUB_RUN_ATTEMPT" >> $GITHUB_ENV
if [[ $GITHUB_EVENT_NAME == 'pull_request' || $GITHUB_EVENT_NAME == 'pull_request_target' ]]; then
echo "PULL_REQUEST=true" >> $GITHUB_ENV
fi;
- name: Run `git checkout`
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup node@12
uses: actions/setup-node@v2
with:
node-version: "12"
- name: Setup dependencies on build runner
run: |
sudo apt-get update
sudo apt-get install language-pack-ja japan* fonts-wqy-microhei ttf-wqy-microhei
# @NOTE-RT: Rerun `install` to make sure we've got our dependencies
- name: Install `yarn`
run: |
npm install -g yarn@1
yarn config set script-shell $(which bash)
- name: Get Date
id: get-date
run: |
echo "::set-output name=date::$(/bin/date -u "+%Y%m%d")"
shell: bash
- name: Restore `node_modules` cache
uses: actions/cache@v2
id: yarn-cache
with:
path: |
node_modules
*/*/node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}-${{ steps.get-date.outputs.date }}
restore-keys: |
${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}-
${{ runner.os }}-yarn-
- name: Actually run `yarn install --frozen-lockfile`
run: yarn install --frozen-lockfile
- name: Setup CodeClimate for tests
run: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > $PWD/cc-test-reporter
chmod +x $PWD/cc-test-reporter
$PWD/cc-test-reporter before-build
shell: bash
- name: Setup DynamoDB Local
uses: rrainn/dynamodb-action@v2.0.1
- name: Actually run `yarn test`
id: test-actual
env:
NODE_ENV: test
run: |
yarn run pretest
yarn cover:actual
timeout-minutes: 10
- name: Cleanup after tests
if: always()
env:
NODE_ENV: test
run: |
yarn run kill --scope @randy.tarampi/service
- name: Collect results
if: always()
env:
NODE_ENV: test
run: |
yarn run pretest:collect
yarn run cover:collect
- name: Report results to CodeClimate
if: always()
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
run: |
$PWD/cc-test-reporter after-build --exit-code=$(if [[ "${{ steps.test-actual.outcome.success }}" == 'success' ]]; then echo '0'; else echo '1'; fi;) || true
shell: bash
- name: Report results to Check Run Reporter (pretest)
if: always()
uses: check-run-reporter/action@v2.11.1
with:
token: ${{ secrets.CHECK_RUN_REPORTER_TOKEN }}
report: pretest-results.xml
label: pretest
- name: Report results to Check Run Reporter (test)
if: always()
uses: check-run-reporter/action@v2.11.1
with:
token: ${{ secrets.CHECK_RUN_REPORTER_TOKEN }}
report: test-results.xml
label: test
- name: Report coverage to Coveralls
if: always()
uses: coverallsapp/github-action@1.1.3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Report coverage to CodeClimate
if: always()
uses: paambaati/codeclimate-action@v3.0.0
with:
coverageLocations: coverage/lcov.info:lcov
- name: Report coverage to CodeCov
if: always()
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: coverage
- name: Report coverage to Codacy
if: always()
uses: codacy/codacy-coverage-reporter-action@v1
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: coverage/lcov.info
- name: Report coverage to report.ci
if: always()
env:
REPORT_CI_TOKEN: ${{ secrets.REPORT_CI_TOKEN }}
run: |
python <(curl https://report.ci/upload.py) || true
shell: bash