Skip to content

Commit 77aa7f0

Browse files
committed
ci: New Travis configuration with automated releases
1 parent 584bf9d commit 77aa7f0

File tree

3 files changed

+194
-16
lines changed

3 files changed

+194
-16
lines changed

Diff for: .travis.yml

+149-16
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,156 @@
11
language: node_js
22

3-
matrix:
4-
include:
5-
- node_js: '4'
6-
- node_js: '6'
7-
- node_js: '8'
8-
- node_js: '10'
9-
- node_js: '10'
10-
env:
11-
- DISABLE_TESTS=true
12-
- LINTING=true
3+
git:
4+
# Minimize git history, but ensure to not break things:
5+
# - Merging multiple PR's around same time may introduce a case where it's not
6+
# the last merge commit that is to be tested
7+
# - Aside of merge commit we need a previous commit to be able to detect a version switch
8+
depth: 30
9+
10+
cache:
11+
# Not relying on 'npm' shortcut, as per Travis docs it's the only 'node_modules' that it'll cache
12+
directories:
13+
- $HOME/.npm
14+
- node_modules
15+
16+
branches:
17+
only: # Do not build PR branches
18+
# Release branches
19+
- master
20+
# Release tags
21+
- /^v\d+\.\d+\.\d+$/ # Ensure to build release tags
22+
23+
stages:
24+
- name: Test
25+
if: tag IS NOT present
26+
- name: Tag on Release
27+
if: branch = master AND type = push
28+
- name: Deploy
29+
if: tag =~ ^v\d+\.\d+\.\d+$
1330

14-
sudo: false
31+
env:
32+
global:
33+
- FORCE_COLOR=1 # Ensure colored output (color support is not detected in some cases)
1534

35+
# Ensure to install dependencies at their latest versions
1636
install:
17-
- travis_retry npm install
37+
# Note: `npm update` has issues which we need to workaround:
38+
# - There seems no way to update all project dependency groups in one run
39+
# Hence different calls for prod and dev dependencies
40+
# - The bigger depth, the longer update takes (-9999 as proposed in npm docs hangs the process).
41+
# Therefore we keep at 3 which should ensure most of dependencies are at latest versions
42+
# - Depth setting makes optional dependencies not optional (install error crashes process)
43+
# Hence we skip install of optional dependencies completely, with --no-optional
44+
# Note: this patch works only for npm@5+
45+
# - npm documents --dev option for dev dependencies update, but it's only --save-dev that works
46+
- npm update --depth 3 --no-optional --no-save
47+
- npm update --depth 3 --save-dev --no-save
48+
49+
before_script:
50+
# Fail build right after first script fails. Travis doesn't ensure that: https://github.com/travis-ci/travis-ci/issues/1066
51+
# More info on below line: https://www.davidpashley.com/articles/writing-robust-shell-scripts/#idm5413512
52+
- set -e
53+
- git config --global user.email "platform@serverless.com"
54+
- git config --global user.name "Serverless CI"
55+
56+
jobs:
57+
include:
58+
# In most cases it's best to configure one job per platform & Node.js version combination
59+
# (job boot & setup takes ca 1 minute, one task run lasts ca few seconds)
60+
61+
# PR's from branches
62+
# Ensure commit messages follow CC, and confirm on changelog in case of release PR's
63+
- name: 'Prettier check updated, Lint updated, Commitlint, Changelog confirm (on release), Unit Tests - Node.js v12'
64+
if: type = pull_request AND fork = false
65+
node_js: 12
66+
script:
67+
- npm run prettier-check:updated
68+
- npm run lint:updated
69+
- npm run commitlint:pull-request
70+
# If release PR, confirm we have a changelog
71+
- |
72+
tagName=`git diff master package.json | grep '"version": "' | tail -n 1 | grep -oE "[0-9]+\.[0-9]+\.[0-9]+"` || :
73+
if [ -n "$tagName" ];
74+
then
75+
npx dump-release-notes-from-cc-changelog $tagName
76+
fi
77+
- npm test
1878

19-
script:
20-
- if [[ ! -z "$DISABLE_TESTS" && ! -z "$LINTING" ]]; then npm run lint; fi
79+
# PR's from forks
80+
# Do not validate commit messages,
81+
# (if user didn't ensure CC, PR should be squash merged with a valid CC commit message)
82+
- name: 'Prettier check updated, Lint updated, Unit Tests - Node.js v12'
83+
if: type = pull_request AND fork = true
84+
node_js: 12
85+
script:
86+
- npm run prettier-check:updated
87+
- npm run lint:updated
88+
- npm test
2189

22-
after_success:
23-
- ./node_modules/jest/bin/jest.js --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
90+
# master branch
91+
- name: 'Unit Tests - Node.js v12'
92+
if: type != pull_request
93+
node_js: 12
94+
95+
- name: 'Unit Tests, Coverage - Node.js v13'
96+
node_js: 13
97+
script:
98+
- npm run coverage
99+
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
100+
101+
- name: 'Unit Tests - Node.js v10'
102+
node_js: 10
103+
104+
- name: 'Unit Tests - Node.js v8'
105+
node_js: 8
106+
107+
- name: 'Unit Tests - Node.js v6'
108+
node_js: 6
109+
110+
- name: 'Unit Tests - Node.js v4'
111+
node_js: 4
112+
113+
- stage: Tag on Release
114+
name: 'Tag on Release'
115+
node_js: 12
116+
env:
117+
# GITHUB_TOKEN
118+
- secure: Eu4uYULeMcBVkj3AJxKTGTytCkGBDZAl5z/26Jnv1sH3hK02UQeJdE2L8gTk/TfMS/MMLInSb0YqD4S8qEz6C3zg4Q9z9/N653JaKSbpQPjjc8BsOaZlgo0rrUJWu/BwdYLou1zAhAGd4cUtyAAnIkvJW30XAnH6A73EyGY3GgRRIUGb/PxUB2cHrqalq/V/u6kuNw5Sf26SmVVdJMhj5/es+kQdI2EeykEQMO2FRXKV2GRXs5TFikW/doTENHQAK6QPWJbVX1PHF4Via9vJuLhaOo4QjH3XCpDYX5UYsR7gvOChSsY3VMjHgLkjgTyabiv0mnrhjsLkkvlVsSzmmYmMShyGbJSjnqAa+C69oGFJo9Tim5qQOEJIZ5R7A1ctS8wZSmb2YUc7YU/1/kTjQ8ccU1MgAPp4w9drdwCZXLTQ8fc1MYPo4+sDoAdJVSpS9YQ5qsenZH1lgyJ3iV+RwLjzltdRTs4FjeAOxCaEjpdhXkVZpH58wiDYm4F4OfzfvvSYPSxa2eoZVSI+YV4YEtHQrFgxWwNHgIt8rH8zETKjhlva6PCirZdWfmQg1LU/3Jly1lNw9fkTy9UzAfsLaSQM8hEbjOR6nh7AQCUqp9Fq7jH7lV/t/yGEIH5Ie/qW/uFcZpV1RLicgeGAnI+7RM55vSB9tyO8tiJcWBQZgLw=
119+
script:
120+
- |
121+
tagName=`git diff HEAD^ package.json | grep '"version": "' | tail -n 1 | grep -oE "[0-9]+\.[0-9]+\.[0-9]+"` || :
122+
if [ -n "$tagName" ];
123+
then
124+
git tag v$tagName
125+
git push -q https://$GITHUB_TOKEN@github.com/serverless/test --tags
126+
fi
127+
128+
# version tag
129+
- stage: Deploy
130+
env:
131+
# GITHUB_TOKEN
132+
- secure: Eu4uYULeMcBVkj3AJxKTGTytCkGBDZAl5z/26Jnv1sH3hK02UQeJdE2L8gTk/TfMS/MMLInSb0YqD4S8qEz6C3zg4Q9z9/N653JaKSbpQPjjc8BsOaZlgo0rrUJWu/BwdYLou1zAhAGd4cUtyAAnIkvJW30XAnH6A73EyGY3GgRRIUGb/PxUB2cHrqalq/V/u6kuNw5Sf26SmVVdJMhj5/es+kQdI2EeykEQMO2FRXKV2GRXs5TFikW/doTENHQAK6QPWJbVX1PHF4Via9vJuLhaOo4QjH3XCpDYX5UYsR7gvOChSsY3VMjHgLkjgTyabiv0mnrhjsLkkvlVsSzmmYmMShyGbJSjnqAa+C69oGFJo9Tim5qQOEJIZ5R7A1ctS8wZSmb2YUc7YU/1/kTjQ8ccU1MgAPp4w9drdwCZXLTQ8fc1MYPo4+sDoAdJVSpS9YQ5qsenZH1lgyJ3iV+RwLjzltdRTs4FjeAOxCaEjpdhXkVZpH58wiDYm4F4OfzfvvSYPSxa2eoZVSI+YV4YEtHQrFgxWwNHgIt8rH8zETKjhlva6PCirZdWfmQg1LU/3Jly1lNw9fkTy9UzAfsLaSQM8hEbjOR6nh7AQCUqp9Fq7jH7lV/t/yGEIH5Ie/qW/uFcZpV1RLicgeGAnI+7RM55vSB9tyO8tiJcWBQZgLw=
133+
node_js: 12
134+
script: skip
135+
# Ensure to fail build if deploy fails, Travis doesn't ensure that: https://github.com/travis-ci/travis-ci/issues/921
136+
before_deploy:
137+
- set -e
138+
# Remove eventual old npm logs
139+
- rm -rf ~/.npm/_logs
140+
after_deploy:
141+
- |
142+
# npm creates log only on failure
143+
if [ -d ~/.npm/_logs ]
144+
then
145+
# Undocumented way to force Travis build to fail
146+
travis_terminate 1
147+
fi
148+
- npx github-release-from-cc-changelog $TRAVIS_TAG
149+
deploy:
150+
edge: true # Workaorund Travis regression: https://travis-ci.community/t/missing-api-key-when-deploying-to-github-releases/5761
151+
provider: npm
152+
email: services@serverless.com
153+
on:
154+
tags: true
155+
api_key:
156+
secure: GxHxrCEjTIwzcHW6EEJm6/6Lwm3H+aTmOSrDHgwMwiwg98fTqQ2pD1L06CppSiaq9T33RPEim4kuBHIpTtmiJwVVQMIdEQheUfE05OwWBWcOEta2h3ahbGPX8iA48aVdRuXD4/Vpiho2a7zPuVBIsgDH1OzLO/WiYx10afzqlOOvwBITOkRy6eKD/I/Omxid6KjvMwfrHYScWvL9JTo7aV0MhFL4MV+9fN3nutF5+wSSIjfkzTmhxKmHEi/nlcuFCVS8yfutX7sMLugxNilqbv815SbjHMrkgZwkzrnalTbF3B2ohV8zYcuCrUEwDPRlrWbmoFMGJdcuXE90HPiHagn2Olv5e28f5ToQGFzwzYWrAO2Rc4l6gyUn8uwonN/xrK6N8ucEti9b/vzQz2/bH3rB+S++ZPiYAUcgZ8eLUp6TXkFoxanRuH/k2I8kfBj3bQrfvJofbaQKcrsGPFmR+AEsxDiZ2fCQfZHuZS4t8JD5VtDXacTSbbZzqwiKHF0sdJIIzE8EXQ7OejK8UQ2nSUZMlVUzvwuAnhPgjOC9QCNpQwprSX2Hn5d8lvcxI+TDj7XWYxqbhIlRHxPLghKTMicIH/luwy3OpCP4769Hjmy4e2M6kjyUKjhrV7BvrBVZSVPSP0vuh3oZCPGZSRXl3JfelQGXrUNufxomZu/gLZM=

Diff for: RELEASE_PROCESS.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Release process
2+
3+
## Semi-automation
4+
5+
This project relies on [semantic commit messages](https://www.conventionalcommits.org/en/v1.0.0-beta.4/#summary) which allows to streamline the release process (versioning and changelog generation is automated)
6+
7+
See proposed [Commit Message Guidelines](https://docs.google.com/document/d/1hKUs3qt_aVp_PBI1UqvfaIqKma3jAJimEoGCRGGbOqs/edit#)
8+
9+
In PR's as coming from forks (community contributions) while its welcome, we do not require to follow semantic commit messages. Yet, such PR is expected to be squash merged by project member with single semantic commit message.
10+
11+
PR's comming from branches have commit messages validated with [commmitlint](https://commitlint.js.org/#/)
12+
13+
## Release flow
14+
15+
Releases are triggered manually by preparing a release PR's as follows
16+
17+
1. Create a `release` branch (should derive from current `master` state)
18+
2. Bump version ranges of _all_ dependencies to latest supported versions (e.g. if latest version of a dependency is `2.3.5` and range in a `package.json` is `^2.2.4` then it should be updated to `^2.3.5`)
19+
_Note: Unfortunately there seems no reliable utility to automate that (there's a [request at `npm-check-updates`](https://github.com/tjunnone/npm-check-updates/issues/581))
20+
If you handle installation of dependencies through [npm-cross-link](https://github.com/medikoo/npm-cross-link#npm-cross-link) then [`--bump-deps`](https://github.com/medikoo/npm-cross-link#general-options) option will bump version ranges as expected_
21+
3. Commit eventual dependency version updates with following commit message:
22+
`chore: Bump dependencies`
23+
4. Run `npm run prepare-release` command.
24+
_It'll automatically bump version in `package.json` to expected one (by inspecting changes since previous release) and will generate new changelog entry._
25+
5. If needed improve generated changelog entry in `CHANGELOG.md`
26+
6. Commit `package.json` and `CHANGELOG.md` changes with following commit message:
27+
`chore: Release`
28+
**Note: For automation purpose it is important that it's the last commit in the PR**
29+
7. Push branch upstream and create a PR.
30+
_Release PR's are automatically detected in CI by fact of `version` in `package.json` file being changed in last commit. In context of that build, existence of new version changelog entry (in `CHANGELOG.md`) is validated._
31+
8. After PR is accepted by CI and one of the reviewers, merge it via _"Rebase and merge"_ option
32+
33+
Further actions are automated in CI context:
34+
35+
8. `master` CI build detects that release PR was merged (by fact that it covers change of `version` field in `package.json` file). Having that (after successufl tests pass) version tag is created and pushed to the repository.
36+
9. _tag_ CI build, publishes new version to npm, also it retrieves release notes from CHANGELOG.md and publishes them to GitHub.
37+
38+
### Updating release notes for already published versions
39+
40+
Improvements to release notes can be done at anytime to any already published version:
41+
42+
1. Update `CHANGELOG.md` with desired changes (ensure they'd also end in `master`)
43+
2. Push updated release notes to GitHub by running:
44+
`npx github-release-from-cc-changelog <version>`

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"eslint": "^6.8.0",
4848
"eslint-plugin-import": "^2.20.1",
4949
"git-list-updated": "^1.2.1",
50+
"github-release-from-cc-changelog": "^2.2.0",
5051
"husky": "^4.2.3",
5152
"jest": "^24.9.0",
5253
"lint-staged": "^10.0.8",

0 commit comments

Comments
 (0)