forked from klaro-org/klaro-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
62 lines (57 loc) · 2.83 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
image: node:14.5.0
# Cache modules in between jobs
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- node_modules/
before_script:
- npm ci
stages:
- test
- deploy
lint:
stage: test
script:
- npm run-script lint
- npm run-script lint-scss
deploy:
artifacts:
paths:
- dist
only:
- staging
- tags
stage: deploy
before_script:
- apt-get update -qy
- apt-get install -y rsync
- echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
script:
# if the commit tag does not match a semantic version number we bail out
- if [ -n "$CI_COMMIT_TAG" ] && [[ ! "$CI_COMMIT_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then exit 1; fi;
# we deploy tagged commits to the production version and commits in the "staging" branch to the staging environment
- if [ -n "$CI_COMMIT_TAG" ]; then export DIRECTORY=klaro-master; else if [ "$CI_COMMIT_REF_NAME" = "staging" ]; then export DIRECTORY=klaro-staging; else exit 0; fi; fi;
- if [ ! -n "$SERVER_SSH_KEY" ]; then exit 0; fi
- mkdir ~/.ssh
- chmod 700 ~/.ssh
- echo "$SERVER_SSH_KEY" | tr -d '\r' > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
# - npm ci
- export CI_APP_VERSION=$CI_COMMIT_TAG APP_VERSION=$CI_COMMIT_SHA
- export APP_COMMIT=$(git rev-parse HEAD)
- export APP_VERSION=$(git tag --points-at HEAD)
- if [ -n "$CI_COMMIT_TAG" ] && [ "$CI_COMMIT_TAG" != "$APP_VERSION" ]; then echo "versions do not match"; exit 1; fi;
# Currently we do not rebuild the files in CI, as we have reproducibility issues... :/
# - make build
# - sha256sum dist/*.js
# We make sure the distribution files are identical to the ones in the repository. If not, something might be afoul, we abort the deployment then....
# - git status
# - git diff-index --quiet HEAD dist || (echo "Cannot reproduce build files, aborting!" && exit 1)
# if this is a tagged commit we publish the package to NPM
- if [ -n "$CI_COMMIT_TAG" ]; then make publish; fi
# if a directory is specified we push the distribution files to it
- echo "Deploying to $DIRECTORY..."
- if [ -n "$DIRECTORY" ]; then rsync --progress -r -e "ssh -o StrictHostKeyChecking=no -o identityFile=~/.ssh/id_rsa" releases.yml releases.json dist/* $SERVER_USERNAME@$SERVER_IP:/dpkit/$DIRECTORY; fi;
# we copy the JS and CSS files to our CDN
- export MINOR_VERSION_LINE=`echo "$CI_COMMIT_TAG" | grep -o 'v[0-9]\+\.[0-9]\+'`
- if [ -n "$CI_COMMIT_TAG" ]; then ssh -o StrictHostKeyChecking=no -o identityFile=~/.ssh/id_rsa $SERVER_USERNAME@$SERVER_IP "bash -c 'mkdir -p /kiprotect_cdn/master/klaro/$CI_COMMIT_TAG && cp /dpkit/$DIRECTORY/klaro*.{css,js} /kiprotect_cdn/master/klaro/$CI_COMMIT_TAG && rm -rf /kiprotect_cdn/master/klaro/$MINOR_VERSION_LINE && ln -s /kiprotect_cdn/master/klaro/$CI_COMMIT_TAG /kiprotect_cdn/master/klaro/$MINOR_VERSION_LINE'"; fi;