mirror of
https://github.com/elyby/accounts-frontend.git
synced 2026-10-20 20:58:07 +05:30
237 lines
5.1 KiB
YAML
237 lines
5.1 KiB
YAML
variables:
|
|
NODE_IMAGE: node:22-alpine
|
|
DEPLOY_IMAGE: docksal/ssh-agent:1.3
|
|
# To cache npm modules we use an environment variable
|
|
# to point at the folder we list as a path in "cache" job settings
|
|
YARN_CACHE_FOLDER: "$CI_PROJECT_DIR/cache/yarn"
|
|
|
|
GIT_DEPTH: 10
|
|
|
|
stages:
|
|
- prepare
|
|
- test
|
|
- build
|
|
- deploy
|
|
|
|
# GitLab don't support bash syntax in the "variables" definitions,
|
|
# so we use a custom step to define all necessary environment variables
|
|
.defineVars: &defineVars |-
|
|
export VERSION="${CI_COMMIT_TAG:-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}}"
|
|
|
|
.installSentry: &installSentry |-
|
|
apk add curl
|
|
export SENTRY_CLI_VERSION="3.4.3"
|
|
curl -sL https://sentry.io/get-cli/ | bash
|
|
|
|
.setupSSH: &setupSSH |-
|
|
mkdir ~/.ssh
|
|
echo -e "Host *\n StrictHostKeyChecking no\n" > ~/.ssh/config
|
|
eval $(ssh-agent -s)
|
|
echo "$SSH_DEPLOY_KEY" | tr -d '\r' | ssh-add -
|
|
|
|
###################
|
|
# Steps to extend #
|
|
###################
|
|
|
|
.yarnCache:
|
|
cache:
|
|
key: yarn-cache
|
|
paths:
|
|
- node_modules
|
|
- packages/*/node_modules
|
|
- tests-e2e/node_modules # Keep this node_modules because it's one of workspaces
|
|
policy: pull
|
|
|
|
#################
|
|
# Prepare stage #
|
|
#################
|
|
|
|
Yarn:
|
|
stage: prepare
|
|
image: $NODE_IMAGE
|
|
extends:
|
|
- .yarnCache
|
|
cache:
|
|
policy: pull-push
|
|
variables:
|
|
CYPRESS_INSTALL_BINARY: 0 # Don't install binary to increase caching performance between jobs
|
|
before_script:
|
|
- apk add git
|
|
script:
|
|
- yarn install --frozen-lockfile
|
|
|
|
#################
|
|
# Testing stage #
|
|
#################
|
|
|
|
Lint:
|
|
stage: test
|
|
image: $NODE_IMAGE
|
|
needs:
|
|
- Yarn
|
|
extends:
|
|
- .yarnCache
|
|
script:
|
|
- yarn lint:check
|
|
|
|
TypeScript:
|
|
stage: test
|
|
image: $NODE_IMAGE
|
|
needs:
|
|
- Yarn
|
|
extends:
|
|
- .yarnCache
|
|
script:
|
|
- yarn ts:check
|
|
|
|
Jest:
|
|
stage: test
|
|
image: $NODE_IMAGE
|
|
needs:
|
|
- Yarn
|
|
extends:
|
|
- .yarnCache
|
|
script:
|
|
- yarn test
|
|
|
|
Crowdin:
|
|
stage: test
|
|
image: $NODE_IMAGE
|
|
needs:
|
|
- Yarn
|
|
extends:
|
|
- .yarnCache
|
|
script:
|
|
- yarn i18n:extract
|
|
- yarn i18n:push
|
|
- yarn i18n:pull
|
|
artifacts:
|
|
name: "i18n for $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA"
|
|
paths:
|
|
- packages/app/i18n/*.json
|
|
- packages/app/i18n/index.js
|
|
expire_in: 1 week
|
|
|
|
###############
|
|
# Build stage #
|
|
###############
|
|
|
|
Build:
|
|
stage: build
|
|
image: $NODE_IMAGE
|
|
needs:
|
|
- Lint
|
|
- TypeScript
|
|
- Jest
|
|
- Crowdin
|
|
extends:
|
|
- .yarnCache
|
|
before_script:
|
|
- *defineVars
|
|
script:
|
|
- yarn build
|
|
# Remove unneeded files
|
|
- rm -rf build/*.css.map
|
|
# Move all source maps to its own directory
|
|
- mkdir -p source-maps
|
|
- cd build
|
|
- find . -name '*.js.map' | cpio -pdm ../source-maps/
|
|
- rm -rf *.js.map
|
|
- find . -name '*.js' | cpio -pdm ../source-maps/
|
|
- cd ..
|
|
# Cleanup source maps for unimportant bundles
|
|
- rm -f source-maps/runtime.js
|
|
- rm -f source-maps/intl-polyfills.js
|
|
- rm -rf source-maps/locale-*
|
|
artifacts:
|
|
name: "Production build for $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA"
|
|
paths:
|
|
- build
|
|
- source-maps
|
|
expire_in: 1 week
|
|
|
|
Storybook:
|
|
stage: build
|
|
image: $NODE_IMAGE
|
|
needs:
|
|
- Yarn
|
|
- Crowdin
|
|
extends:
|
|
- .yarnCache
|
|
script:
|
|
- yarn sb:build --quiet
|
|
artifacts:
|
|
name: "Storybook for $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA"
|
|
paths:
|
|
- storybook-static
|
|
expire_in: 1 day
|
|
|
|
################
|
|
# Deploy stage #
|
|
################
|
|
|
|
.deployJob:
|
|
stage: deploy
|
|
image: $DEPLOY_IMAGE
|
|
needs:
|
|
- Build
|
|
dependencies:
|
|
- Build
|
|
variables:
|
|
GIT_STRATEGY: none
|
|
DEPLOY_HOST: 167.235.12.151
|
|
DEPLOY_PORT: 4534
|
|
before_script:
|
|
- *defineVars
|
|
- *installSentry
|
|
- *setupSSH
|
|
- apk add rsync
|
|
script:
|
|
# Send release to the Sentry
|
|
- sentry-cli releases new "$VERSION"
|
|
- sentry-cli releases set-commits --commit "elyby/accounts-frontend@${CI_COMMIT_SHA}" "$VERSION"
|
|
- sentry-cli sourcemaps upload --release="$VERSION" source-maps
|
|
# Deploy
|
|
- rsync -v -a -r --delete-after -e "ssh -p ${DEPLOY_PORT:-22}" build/ "${DEPLOY_USER:-root}@${DEPLOY_HOST}:${DEPLOY_PATH}/"
|
|
# Finalize Sentry's release
|
|
- sentry-cli releases deploys "$VERSION" new -e "$CI_ENVIRONMENT_NAME"
|
|
- sentry-cli releases finalize "$VERSION"
|
|
|
|
Dev:
|
|
extends:
|
|
- .deployJob
|
|
environment:
|
|
name: Development
|
|
variables:
|
|
DEPLOY_PATH: /srv/account.dev.ely.by/frontend
|
|
rules:
|
|
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
|
when: never
|
|
- if: '$CI_COMMIT_MESSAGE =~ /\[skip deploy\]/'
|
|
when: never
|
|
- if: '$CI_COMMIT_BRANCH == "master"'
|
|
when: on_success
|
|
- if: '$CI_COMMIT_MESSAGE =~ /\[deploy dev\]/'
|
|
when: on_success
|
|
# Default:
|
|
- when: never
|
|
|
|
Prod:
|
|
extends:
|
|
- .deployJob
|
|
environment:
|
|
name: Production
|
|
variables:
|
|
DEPLOY_PATH: /srv/account.ely.by/frontend
|
|
rules:
|
|
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
|
when: never
|
|
- if: '$CI_COMMIT_MESSAGE =~ /\[skip deploy\]/'
|
|
when: never
|
|
- if: '$CI_COMMIT_BRANCH != "master"'
|
|
when: never
|
|
- if: '$CI_COMMIT_MESSAGE =~ /\[deploy\]/'
|
|
when: on_success
|
|
# Default:
|
|
- when: manual
|