-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
114 lines (105 loc) · 3.35 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
---
.configure-registry:
&configure-registry
# - apk --quiet --no-progress --update --no-cache add git openssh
- sed -i "s/\$NPM_TOKEN/$NPM_TOKEN/g" .yarnrc.yml
- cat .yarnrc.yml
- NODE_ENV=cicd yarn install
default:
image: node:16-alpine
before_script:
- *configure-registry
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- "**/dist/"
policy: pull-push
workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "push"'
variables:
NPM_TOKEN: ${NPM_TOKEN}
GITLAB_TOKEN: ${GITLAB_TOKEN}
stages:
- test
- release
- publish
- notify
lint:
# image: node:16-alpine
image: node:16
stage: test
rules:
- if: $CI_COMMIT_MESSAGE =~ /^chore\(publish\)/
when: never
- if: $CI_COMMIT_BRANCH
when: always
script:
- yarn workspaces foreach run lint
test:
# image: node:16-alpine
image: node:16
stage: test
rules:
- if: $CI_COMMIT_MESSAGE =~ /^chore\(publish\)/
when: never
- when: always
script:
- yarn workspaces foreach run test
release:
# image: node:16-alpine
image: node:16
stage: release
rules:
- if: $CI_COMMIT_MESSAGE =~ /^chore\(publish\)/
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: always
- if: $CI_COMMIT_BRANCH == "alpha"
when: always
- if: $CI_COMMIT_BRANCH == "beta"
when: always
variables:
# Set git commit identity
GIT_AUTHOR_NAME: "AutoCloud Deploy Bot"
GIT_AUTHOR_EMAIL: "no-reply@loudcloud.dev"
GIT_COMMITTER_NAME: "AutoCloud Deploy Bot"
GIT_COMMITTER_EMAIL: "no-reply@loudcloud.dev"
# Disable Husky for the git step of semantic release (handles all versions, env var name changed in v6)
HUSKY_SKIP_HOOKS: 1
HUSKY: 0
before_script:
- *configure-registry
script:
- yarn release
publish:
# image: node:16-alpine
image: node:16
stage: publish
rules:
- if: $CI_COMMIT_TAG
when: always
- if: $CI_COMMIT_BRANCH
when: never
script:
- export NPM_TAG=`./.cicd/release_tag.js $CI_COMMIT_TAG`
- export WORKSPACE_NAME=`./.cicd/workspace_name.js $CI_COMMIT_TAG`
- yarn workspace $WORKSPACE_NAME publish --tag $NPM_TAG
.curlcmd: &curlcmd >
curl
-sS
-X POST
--data-urlencode "payload={\"attachments\":[{\"fallback\":\"$GITLAB_USER_NAME released new $CI_PROJECT_TITLE version $CI_COMMIT_TAG\",\"color\":\"good\",\"author_name\":\"$GITLAB_USER_NAME ($GITLAB_USER_LOGIN)\",\"author_icon\":\"$GITLAB_USER_AVATAR\",\"author_link\":\"https://gitlab.com/$GITLAB_USER_LOGIN\",\"title\":\"Version $CI_COMMIT_TAG of $CI_PROJECT_NAME released\",\"title_link\":\"$CI_PROJECT_URL/-/tags/$CI_COMMIT_TAG\",\"fields\":[{\"title\":\"Tag\",\"value\":\"<$CI_PROJECT_URL/commits/$CI_COMMIT_TAG|$CI_COMMIT_TAG>\",\"short\":true},{\"title\":\"Commit\",\"value\":\"<$CI_PROJECT_URL/tree/$CI_COMMIT_SHA|$CI_COMMIT_TITLE>\",\"short\":true}],\"footer\":\"$CI_PROJECT_NAME\",\"ts\":$( date +%s )}]}"
$SLACK_API_ENDPOINT
notify:
image: alpine:latest
stage: notify
rules:
- if: $CI_COMMIT_TAG
# Overwrite the default before script with a no-op action to disable the node specific actions
before_script:
- echo "noop"
script:
- apk add --no-cache curl
- GITLAB_USER_AVATAR=$( echo $GITLAB_USER_EMAIL | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]' | md5sum | awk -F' ' '{print $1}' | xargs -I{} echo 'https://www.gravatar.com/avatar/{}?s=80&d=identicon' )
- *curlcmd