Skip to content

Instantly share code, notes, and snippets.

@dsebastien
Last active October 18, 2020 09:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsebastien/aff0276b2e9e04fb801e5e109b6aa184 to your computer and use it in GitHub Desktop.
Save dsebastien/aff0276b2e9e04fb801e5e109b6aa184 to your computer and use it in GitHub Desktop.
image: app-ci-image:latest
stages:
- test
- end to end
- build
- security audit
variables:
# Docker driver: speed things up: https://gitlab.com/gitlab-org/gitlab-foss/-/issues/21374
DOCKER_DRIVER: overlay
# Avoid fetching everything
GIT_DEPTH: 0
before_script:
- date
- echo "Pipeline ID = $CI_PIPELINE_ID"
- echo "Project name = $CI_PROJECT_NAME"
- echo "Build ref = $CI_BUILD_REF_NAME"
- whoami
- pwd
- ls -ail
- echo "Default environment:"
- env
- date
# TODO track the following issue for performance improvements https://gitlab.com/gitlab-org/gitlab-runner/issues/1797
# Current approach: install everything based on cache for each job
- echo "Installing dependencies (if needed)"
# The NPM_CACHE_FOLDER env variable is defined in the App's CI dockerfile
- if [[ ! -d node_modules ]] || [[ -n `git diff --name-only origin/master HEAD | grep "\package-lock.json\b"` ]]; then npm ci --cache ${NPM_CACHE_FOLDER} --prefer-offline --no-audit --no-optional; fi
- date
after_script:
- date
Compile:
stage: test
when: always
script:
- npm run tsc:all
Lint:
stage: test
when: always
script:
- npm run affected:lint -- --base=remotes/origin/master --head=HEAD --parallel
Unit tests:
stage: test
when: always
script:
- npm run affected:test:ci -- --base=remotes/origin/master --head=HEAD --parallel
# Help Gitlab extract coverage data
coverage: /All files[^|]*\|[^|]*\s+([\d\.]+)/
artifacts:
name: "Coverage reports"
# expire_in: 3 days # default: 30 days
paths: # TODO complete
- coverage/ # keep code coverage reports
End-to-end tests:
stage: end to end
when: manual
allow_failure: true # Setting this to false would make this job mandatory
script:
- npm run affected:e2e -- --headless --base=remotes/origin/master --head=HEAD --parallel
# TODO investigate e2e job variant for production builds: https://blog.nrwl.io/nrwl-nx-7-0-better-e2e-testing-with-cypress-1b88336bef5e
Static security audit:
stage: security audit
when: always
script:
- npm audit --audit-level critical
Build affected:
stage: build
when: always
script:
- npm run affected:build -- --base=remotes/origin/master --head=HEAD # We always consider the master
artifacts:
name: "Build"
#expire_in: 1 days # default: 30 days
paths:
- dist/ # keep the built application
Build all prod:
stage: build
only:
refs:
- tags
- master
- acceptance
- production
script:
- npm run affected:build:prod:all
artifacts:
name: "Production build"
#expire_in: 15 days # default: 30 days
paths:
- dist/ # keep the built application
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment