Skip to content

Commit b297e5c

Browse files
committed
feat: adding circleci config
Adding the circleci config file to the repo
1 parent 3a91ebd commit b297e5c

File tree

1 file changed

+227
-0
lines changed

1 file changed

+227
-0
lines changed

.circleci/config.yml

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
version: 2.1
2+
orbs:
3+
slack: circleci/slack@3.4.2
4+
5+
commands:
6+
7+
install_deps:
8+
description: Install dependencies
9+
steps:
10+
- run:
11+
name: Setup NPM Token
12+
command: |
13+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
14+
- restore_cache:
15+
key: npm-v1-{{ checksum "package-lock.json" }}-{{ arch }}
16+
- run:
17+
name: Install dependencies
18+
command: npm ci
19+
- save_cache:
20+
key: npm-v1-{{ checksum "package-lock.json" }}-{{ arch }}
21+
paths:
22+
- node_modules
23+
24+
notify_approval:
25+
description: Send approval notification
26+
steps:
27+
- run:
28+
name: Send slack webhook
29+
command: |
30+
COMMIT_MESSAGE=$(git log --format=%B -n 1)
31+
curl -0 -v -X POST ${WEBHOOK_URL} \
32+
-H 'Content-Type: text/json; charset=utf-8' \
33+
-d @- \<<EOF
34+
{
35+
"blocks": [
36+
{
37+
"type": "header",
38+
"text": {
39+
"type": "plain_text",
40+
"text": "Deploy waiting for approval",
41+
"emoji": true
42+
}
43+
},
44+
{
45+
"type": "section",
46+
"fields": [
47+
{
48+
"type": "mrkdwn",
49+
"text": "*Project:*\n<https://github.com/spytecgps/${CIRCLE_PROJECT_REPONAME}|${CIRCLE_PROJECT_REPONAME}>"
50+
},
51+
{
52+
"type": "mrkdwn",
53+
"text": "*Committer:*\n${CIRCLE_USERNAME}"
54+
},
55+
{
56+
"type": "mrkdwn",
57+
"text": "*Branch:*\n<https://github.com/spytecgps/${CIRCLE_PROJECT_REPONAME}/tree/${CIRCLE_BRANCH}|${CIRCLE_BRANCH}>"
58+
},
59+
{
60+
"type": "mrkdwn",
61+
"text": "*Commit:*\n${CIRCLE_SHA1:0:7}"
62+
},
63+
{
64+
"type": "mrkdwn",
65+
"text": "*Message*\n${COMMIT_MESSAGE}"
66+
}
67+
]
68+
},
69+
{
70+
"type": "actions",
71+
"elements": [
72+
{
73+
"type": "button",
74+
"text": {
75+
"type": "plain_text",
76+
"emoji": true,
77+
"text": "Visit Job"
78+
},
79+
"style": "primary",
80+
"url": "${CIRCLE_BUILD_URL}",
81+
"value": "click_me_123"
82+
}
83+
]
84+
}
85+
]
86+
}
87+
EOF
88+
89+
90+
notify_deploy:
91+
description: Send npm publish notification
92+
steps:
93+
- run:
94+
name: Send slack webhook
95+
command: |
96+
TAG=$(git describe --tags)
97+
curl -0 -v -X POST ${WEBHOOK_URL} \
98+
-H 'Content-Type: text/json; charset=utf-8' \
99+
-d @- \<<EOF
100+
{
101+
"blocks": [
102+
{
103+
"type": "section",
104+
"text": {
105+
"type": "mrkdwn",
106+
"text": "*Published @spytecgps/${CIRCLE_PROJECT_REPONAME} to npm successfully!* :party:"
107+
}
108+
},
109+
{
110+
"type": "divider"
111+
},
112+
{
113+
"type": "section",
114+
"fields": [
115+
{
116+
"type": "mrkdwn",
117+
"text": "*Project:*\n<https://github.com/spytecgps/${CIRCLE_PROJECT_REPONAME}|${CIRCLE_PROJECT_REPONAME}>"
118+
},
119+
{
120+
"type": "mrkdwn",
121+
"text": "*Committer:*\n${CIRCLE_USERNAME}"
122+
},
123+
{
124+
"type": "mrkdwn",
125+
"text": "*Branch:*\n<https://github.com/spytecgps/${CIRCLE_PROJECT_REPONAME}/tree/${CIRCLE_BRANCH}|${CIRCLE_BRANCH}>"
126+
},
127+
{
128+
"type": "mrkdwn",
129+
"text": "*Commit:*\n${CIRCLE_SHA1:0:7}"
130+
},
131+
{
132+
"type": "mrkdwn",
133+
"text": "*Version*\n${TAG}"
134+
}
135+
]
136+
}
137+
]
138+
}
139+
EOF
140+
141+
run_unit_tests:
142+
description: Unit tests
143+
steps:
144+
- run:
145+
name: Unit tests
146+
command: npm run test
147+
- store_test_results:
148+
path: ./reports/junit/
149+
- store_artifacts:
150+
path: coverage
151+
152+
jobs:
153+
154+
build:
155+
docker:
156+
- image: cimg/node:12.22.3-browsers
157+
steps:
158+
- checkout
159+
- install_deps
160+
- run_unit_tests
161+
- persist_to_workspace:
162+
root: .
163+
paths: .
164+
165+
notify-approval:
166+
description: Wait for approval to publish
167+
docker:
168+
- image: cimg/node:12.20
169+
working_directory: ~/app
170+
steps:
171+
- attach_workspace:
172+
at: ~/app
173+
- notify_approval
174+
175+
publish:
176+
description: Bump version and publish package to npm
177+
working_directory: ~/app
178+
docker:
179+
- image: cimg/node:12.20
180+
steps:
181+
- attach_workspace:
182+
at: ~/app
183+
- install_deps
184+
- run:
185+
name: Bump version and tag
186+
command: |
187+
mkdir ~/.ssh
188+
ssh-keyscan github.com >> ~/.ssh/known_hosts
189+
git config --global user.email "circle-ci@$GITHUB_ORG.io"
190+
git config --global user.name "circle-ci"
191+
npm version patch -m "Bumped version to %s [ci skip]"
192+
git push -u origin ${CIRCLE_BRANCH} && git push --tags
193+
- run:
194+
name: Publish to npm
195+
command: npm publish
196+
- notify_deploy
197+
198+
workflows:
199+
version: 2
200+
build_and_publish_package:
201+
jobs:
202+
- build:
203+
context:
204+
- npm-global
205+
- notify-approval:
206+
name: notify-approval
207+
requires:
208+
- build
209+
context:
210+
- slack
211+
filters:
212+
branches:
213+
only: master
214+
- approval:
215+
type: approval
216+
requires:
217+
- build
218+
filters:
219+
branches:
220+
only: master
221+
- publish:
222+
name: publish
223+
requires:
224+
- approval
225+
context:
226+
- slack
227+
- npm-global

0 commit comments

Comments
 (0)