generated from serverless/template-package
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.travis.yml
126 lines (113 loc) · 4.36 KB
/
.travis.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
115
116
117
118
119
120
121
122
123
124
125
126
language: node_js
git:
# Minimize git history, but ensure to not break things:
# - Merging multiple PR's around same time may introduce a case where it's not
# the last merge commit that is to be tested
# - Aside of merge commit we need a previous commit to be able to detect a version switch
depth: 30
cache:
# Not relying on 'npm' shortcut, as per Travis docs it's the only 'node_modules' that it'll cache
directories:
- $HOME/.npm
- node_modules
branches:
only:
- master # Do not build PR branches
- /^v\d+\.\d+\.\d+$/ # Ensure to build release tags
stages:
- name: Test
if: tag IS NOT present
- name: Deploy
if: tag =~ ^v\d+\.\d+\.\d+$
env:
global:
- FORCE_COLOR=1 # Ensure colored output (color support is not detected in some cases)
# Ensure to install dependencies at their latest versions
install:
# Note: `npm update` has issues which we need to workaround:
# - There seems no way to update all project dependency groups in one run
# Hence different calls for prod and dev dependencies
# - We were relying on "--depth 3", but depth setting makes optional dependencies not optional
# and adding "--no-optional" proven to not be a reliable workaround (worked just in some cases)
# - npm documents --dev option for dev dependencies update, but it's only --save-dev that works
- npm update --no-save # Updates just dependencies
- npm update --save-dev --no-save # Updates just devDependencies
before_script:
# Fail build right after first script fails. Travis doesn't ensure that: https://github.com/travis-ci/travis-ci/issues/1066
# More info on below line: https://www.davidpashley.com/articles/writing-robust-shell-scripts/#idm5413512
- set -e
- git config --global user.email "platform@serverless.com"
- git config --global user.name "Serverless CI"
# Ensure to fail build if deploy fails, Travis doesn't ensure that: https://github.com/travis-ci/travis-ci/issues/921
before_deploy:
- set -e
# Remove eventual old npm logs
- rm -rf ~/.npm/_logs
after_deploy:
- |
# npm creates log only on failure
if [ -d ~/.npm/_logs ]; then
# Undocumented way to force Travis build to fail
travis_terminate 1
fi
- npx github-release-from-cc-changelog $TRAVIS_TAG
jobs:
include:
# In most cases it's best to configure one job per platform & Node.js version combination
# (job boot & setup takes ca 1 minute, one task run lasts ca few seconds)
# PR's from branches
# Ensure commit messages follow CC, and confirm on changelog in case of release PR's
- name: 'Prettier check updated, Lint updated, Commitlint, Changelog confirm (on release) - Node.js v12'
if: type = pull_request AND fork = false
node_js: 12
script:
- npm run prettier-check:updated
- npm run lint:updated
- npm run commitlint:pull-request
# If release PR, confirm we have a changelog
- |
tagName=`git diff -U0 master package.json | grep '"version": "' | tail -n 1 | grep -oE "[0-9]+\.[0-9]+\.[0-9]+"` || :
if [ -n "$tagName" ];
then
npx dump-release-notes-from-cc-changelog $tagName
fi
# PR's from forks
# Do not validate commit messages,
# (if user didn't ensure CC, PR should be squash merged with a valid CC commit message)
- name: 'Prettier check updated, Lint updated - Node.js v12'
if: type = pull_request AND fork = true
node_js: 12
script:
- npm run prettier-check:updated
- npm run lint:updated
# master branch
- name: 'Tag on version bump - Node.js v12'
if: branch = master AND type = push
env:
# GITHUB_TOKEN
- secure: CHANGEME
node_js: 12
script:
# If package version was changed with last merged PR, push tag
- |
tagName=`git diff -U0 HEAD^ package.json | grep '"version": "' | tail -n 1 | grep -oE "[0-9]+\.[0-9]+\.[0-9]+"` || :
if [ -n "$tagName" ];
then
git tag v$tagName
git push -q https://$GITHUB_TOKEN@github.com/serverlessCHANGEME --tags
fi
# version tag
- stage: Deploy
env:
# GITHUB_TOKEN
- secure: CHANGEME
node_js: 12
script: skip
deploy:
edge: true
provider: npm
email: services@serverless.com
on:
tags: true
api_key:
secure: CHANGEME