Skip to content

Commit 1f98dd7

Browse files
alexander-fenstercallmehiphop
authored andcommitted
chore: setup nighty build in CircleCI (#158)
* chore: setup nighty build in CircleCI * chore: setup nighty build in CircleCI
1 parent 12f91b6 commit 1f98dd7

File tree

2 files changed

+108
-21
lines changed

2 files changed

+108
-21
lines changed

.circleci/config.yml

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,8 @@
1-
unit_tests:
2-
steps: &unit_tests
3-
- checkout
4-
- run:
5-
name: Install modules and dependencies.
6-
command: npm install
7-
- run:
8-
name: Install codecov.
9-
command: npm install codecov
10-
- run:
11-
name: Run unit tests.
12-
command: npm test
13-
- run:
14-
name: Submit coverage data to codecov.
15-
command: node_modules/.bin/codecov
16-
when: always
171
version: 2
182
workflows:
193
version: 2
204
tests:
21-
jobs:
5+
jobs: &workflow_jobs
226
- node4:
237
filters:
248
tags:
@@ -70,33 +54,67 @@ workflows:
7054
ignore: /.*/
7155
tags:
7256
only: '/^v[\d.]+$/'
57+
nightly:
58+
triggers:
59+
- schedule:
60+
cron: 0 7 * * *
61+
filters:
62+
branches:
63+
only: master
64+
jobs: *workflow_jobs
7365
jobs:
7466
node4:
7567
docker:
7668
- image: 'node:4'
7769
user: node
78-
steps: *unit_tests
70+
steps: &unit_tests_steps
71+
- checkout
72+
- run: &remove_package_lock
73+
name: Remove package-lock.json if needed.
74+
command: |
75+
WORKFLOW_NAME=`python .circleci/get_workflow_name.py`
76+
echo "Workflow name: $WORKFLOW_NAME"
77+
if [ "$WORKFLOW_NAME" = "nightly" ]; then
78+
echo "Nightly build detected, removing package-lock.json."
79+
rm -f package-lock.json samples/package-lock.json
80+
else
81+
echo "Not a nightly build, skipping this step."
82+
fi
83+
- run:
84+
name: Install modules and dependencies.
85+
command: npm install
86+
- run:
87+
name: Install codecov.
88+
command: npm install codecov
89+
- run:
90+
name: Run unit tests.
91+
command: npm test
92+
- run:
93+
name: Submit coverage data to codecov.
94+
command: node_modules/.bin/codecov
95+
when: always
7996
node6:
8097
docker:
8198
- image: 'node:6'
8299
user: node
83-
steps: *unit_tests
100+
steps: *unit_tests_steps
84101
node8:
85102
docker:
86103
- image: 'node:8'
87104
user: node
88-
steps: *unit_tests
105+
steps: *unit_tests_steps
89106
node9:
90107
docker:
91108
- image: 'node:9'
92109
user: node
93-
steps: *unit_tests
110+
steps: *unit_tests_steps
94111
lint:
95112
docker:
96113
- image: 'node:8'
97114
user: node
98115
steps:
99116
- checkout
117+
- run: *remove_package_lock
100118
- run:
101119
name: Install modules and dependencies.
102120
command: npm install
@@ -109,6 +127,7 @@ jobs:
109127
user: node
110128
steps:
111129
- checkout
130+
- run: *remove_package_lock
112131
- run:
113132
name: Install modules and dependencies.
114133
command: npm install
@@ -121,6 +140,7 @@ jobs:
121140
user: node
122141
steps:
123142
- checkout
143+
- run: *remove_package_lock
124144
- run:
125145
name: Decrypt credentials.
126146
command: |

.circleci/get_workflow_name.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""
16+
Get workflow name for the current build using CircleCI API.
17+
Would be great if this information is available in one of
18+
CircleCI environment variables, but it's not there.
19+
https://circleci.ideas.aha.io/ideas/CCI-I-295
20+
"""
21+
22+
import json
23+
import os
24+
import sys
25+
import urllib2
26+
27+
28+
def main():
29+
try:
30+
username = os.environ['CIRCLE_PROJECT_USERNAME']
31+
reponame = os.environ['CIRCLE_PROJECT_REPONAME']
32+
build_num = os.environ['CIRCLE_BUILD_NUM']
33+
except:
34+
sys.stderr.write(
35+
'Looks like we are not inside CircleCI container. Exiting...\n')
36+
return 1
37+
38+
try:
39+
request = urllib2.Request(
40+
"https://circleci.com/api/v1.1/project/github/%s/%s/%s" %
41+
(username, reponame, build_num),
42+
headers={"Accept": "application/json"})
43+
contents = urllib2.urlopen(request).read()
44+
except:
45+
sys.stderr.write('Cannot query CircleCI API. Exiting...\n')
46+
return 1
47+
48+
try:
49+
build_info = json.loads(contents)
50+
except:
51+
sys.stderr.write(
52+
'Cannot parse JSON received from CircleCI API. Exiting...\n')
53+
return 1
54+
55+
try:
56+
workflow_name = build_info['workflows']['workflow_name']
57+
except:
58+
sys.stderr.write(
59+
'Cannot get workflow name from CircleCI build info. Exiting...\n')
60+
return 1
61+
62+
print workflow_name
63+
return 0
64+
65+
66+
retval = main()
67+
exit(retval)

0 commit comments

Comments
 (0)