Skip to content

Commit 6a5bafe

Browse files
alexander-fenstercallmehiphop
authored andcommitted
chore: setup nighty build in CircleCI (#17)
* chore: setup nighty build in CircleCI * chore: setup nighty build in CircleCI
1 parent 7832fe2 commit 6a5bafe

File tree

2 files changed

+94
-19
lines changed

2 files changed

+94
-19
lines changed

packages/google-cloud-oslogin/.circleci/config.yml

+27-19
Original file line numberDiff line numberDiff line change
@@ -1,21 +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: Run unit tests.
9-
command: npm test
10-
- run:
11-
name: Submit coverage data to codecov.
12-
command: node_modules/.bin/codecov
13-
when: always
141
version: 2
152
workflows:
163
version: 2
174
tests:
18-
jobs:
5+
jobs: &workflow_jobs
196
- node4:
207
filters:
218
tags:
@@ -59,16 +46,35 @@ workflows:
5946
ignore: /.*/
6047
tags:
6148
only: '/^v[\d.]+$/'
49+
nightly:
50+
triggers:
51+
- schedule:
52+
cron: 0 7 * * *
53+
filters:
54+
branches:
55+
only: master
56+
jobs: *workflow_jobs
6257
jobs:
6358
node4:
6459
docker:
6560
- image: 'node:4'
6661
user: node
67-
steps:
62+
steps: &unit_tests_steps
6863
- checkout
64+
- run: &remove_package_lock
65+
name: Remove package-lock.json if needed.
66+
command: |
67+
WORKFLOW_NAME=`python .circleci/get_workflow_name.py`
68+
echo "Workflow name: $WORKFLOW_NAME"
69+
if [ "$WORKFLOW_NAME" = "nightly" ]; then
70+
echo "Nightly build detected, removing package-lock.json."
71+
rm -f package-lock.json samples/package-lock.json
72+
else
73+
echo "Not a nightly build, skipping this step."
74+
fi
6975
- run:
7076
name: Install modules and dependencies.
71-
command: npm install --unsafe-perm
77+
command: npm install
7278
- run:
7379
name: Run unit tests.
7480
command: npm test
@@ -80,23 +86,24 @@ jobs:
8086
docker:
8187
- image: 'node:6'
8288
user: node
83-
steps: *unit_tests
89+
steps: *unit_tests_steps
8490
node8:
8591
docker:
8692
- image: 'node:8'
8793
user: node
88-
steps: *unit_tests
94+
steps: *unit_tests_steps
8995
node9:
9096
docker:
9197
- image: 'node:9'
9298
user: node
93-
steps: *unit_tests
99+
steps: *unit_tests_steps
94100
lint:
95101
docker:
96102
- image: 'node:8'
97103
user: node
98104
steps:
99105
- checkout
106+
- run: *remove_package_lock
100107
- run:
101108
name: Install modules and dependencies.
102109
command: |
@@ -125,6 +132,7 @@ jobs:
125132
user: node
126133
steps:
127134
- checkout
135+
- run: *remove_package_lock
128136
- run:
129137
name: Install modules and dependencies.
130138
command: npm install
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)