ci: create cache node in workflow pipelines #53
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
name: CI | ||
on: | ||
push: | ||
branches: | ||
- '*' | ||
- '*/*' | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
env: | ||
CI_DEPENDENCIES: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Cache Node.js dependencies | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-node- | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 16.20.2 | ||
- name: Install dependencies | ||
run: npm install --force | ||
- name: Build of code | ||
run: npm run build | ||
- name: Set build status | ||
run: echo "build_status=${{ job.status }}" >> $GITHUB_ENV | ||
- name: Check build status | ||
run: exit 1 | ||
if: ${{ success() == false }} | ||
- name: Run unit tests | ||
id: unit-tests | ||
run: | | ||
if npm run test:ci; then | ||
echo "AWESOME UNIT TEST IS PASSED !" | ||
echo "unit_test_status=success" >> $GITHUB_ENV | ||
else | ||
echo "PLEASE BE AWARE TEST HAS BEEN FAILED !" | ||
echo "unit_test_status=failure" >> $GITHUB_ENV | ||
fi | ||
- name: Check test status | ||
run: exit 1 | ||
if: ${{ steps.unit-tests.outputs.unit_test_status == 'failure' }} |