Skip to content

Commit f956e14

Browse files
committed
patch(travis-on-success): use Travis build stages instead of run once hack
1 parent 9de3b4d commit f956e14

File tree

4 files changed

+56
-85
lines changed

4 files changed

+56
-85
lines changed

.travis.yml

+19-17
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
sudo: false
21
language: node_js
3-
cache:
4-
directories:
5-
- node_modules
6-
notifications:
7-
email: false
2+
83
node_js:
94
- '8'
105
- '10'
116
- '12'
7+
8+
sudo: false
9+
notifications:
10+
email: false
11+
cache:
12+
directories:
13+
- node_modules
14+
1215
script: npm run validate
13-
before_install:
14-
# See: https://github.com/semantic-release/semantic-release/blob/master/docs/03-recipes/git-auth-ssh-keys.md
15-
- openssl aes-256-cbc -K $encrypted_c1ac1ba52366_key -iv $encrypted_c1ac1ba52366_iv -in github-deploy-key.enc -out /tmp/github-deploy-key -d
16-
- chmod 600 /tmp/github-deploy-key
17-
- echo 'echo ${SSH_PASSPHRASE}' > /tmp/askpass && chmod +x /tmp/askpass
18-
- eval "$(ssh-agent -s)"
19-
- DISPLAY=":0.0" SSH_ASKPASS="/tmp/askpass" setsid ssh-add /tmp/github-deploy-key < /dev/null
20-
after_success: node src travis-after-success
21-
branches:
22-
only:
23-
- master
16+
17+
jobs:
18+
include:
19+
- stage: release
20+
node_js: lts/*
21+
deploy:
22+
provider: script
23+
skip_cleanup: true
24+
script:
25+
- 'node src travis-after-success'

src/scripts/__tests__/__snapshots__/travis-after-success.js.snap

+5-18
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,17 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`travis-after-success calls concurrently with both scripts when on travis 1`] = `npx travis-deploy-once@5`;
3+
exports[`travis-after-success calls concurrently with both scripts when on travis 1`] = `concurrently --prefix [{name}] --names codecov,release --prefix-colors bgBlue.bold.reset,bgGreen.bold.reset "echo installing codecov && npx -p codecov@3 -c 'echo running codecov && codecov'" "echo installing semantic-release && npx -p semantic-release@15 -c 'echo running semantic-release && semantic-release'"`;
44

5-
exports[`travis-after-success calls concurrently with both scripts when on travis 2`] = `concurrently --prefix [{name}] --names codecov,release --prefix-colors bgBlue.bold.reset,bgGreen.bold.reset "echo installing codecov && npx -p codecov@3 -c 'echo running codecov && codecov'" "echo installing semantic-release && npx -p semantic-release@15 -c 'echo running semantic-release && semantic-release'"`;
5+
exports[`travis-after-success does not do autorelease script when running on travis but in a pull request 1`] = `concurrently --prefix [{name}] --names codecov --prefix-colors bgBlue.bold.reset "echo installing codecov && npx -p codecov@3 -c 'echo running codecov && codecov'"`;
66

7-
exports[`travis-after-success does not do autorelease script when running on travis but in a pull request 1`] = `npx travis-deploy-once@5`;
7+
exports[`travis-after-success does not do the autorelease script when the version is different 1`] = `concurrently --prefix [{name}] --names codecov --prefix-colors bgBlue.bold.reset "echo installing codecov && npx -p codecov@3 -c 'echo running codecov && codecov'"`;
88

9-
exports[`travis-after-success does not do autorelease script when running on travis but in a pull request 2`] = `concurrently --prefix [{name}] --names codecov --prefix-colors bgBlue.bold.reset "echo installing codecov && npx -p codecov@3 -c 'echo running codecov && codecov'"`;
9+
exports[`travis-after-success does not do the codecov script when opted out 1`] = `concurrently --prefix [{name}] --names release --prefix-colors bgBlue.bold.reset "echo installing semantic-release && npx -p semantic-release@15 -c 'echo running semantic-release && semantic-release'"`;
1010

11-
exports[`travis-after-success does not do the autorelease script when the version is different 1`] = `npx travis-deploy-once@5`;
12-
13-
exports[`travis-after-success does not do the autorelease script when the version is different 2`] = `concurrently --prefix [{name}] --names codecov --prefix-colors bgBlue.bold.reset "echo installing codecov && npx -p codecov@3 -c 'echo running codecov && codecov'"`;
14-
15-
exports[`travis-after-success does not do the codecov script when opted out 1`] = `npx travis-deploy-once@5`;
16-
17-
exports[`travis-after-success does not do the codecov script when opted out 2`] = `concurrently --prefix [{name}] --names release --prefix-colors bgBlue.bold.reset "echo installing semantic-release && npx -p semantic-release@15 -c 'echo running semantic-release && semantic-release'"`;
18-
19-
exports[`travis-after-success does not do the codecov script when there is no coverage directory 1`] = `npx travis-deploy-once@5`;
20-
21-
exports[`travis-after-success does not do the codecov script when there is no coverage directory 2`] = `concurrently --prefix [{name}] --names release --prefix-colors bgBlue.bold.reset "echo installing semantic-release && npx -p semantic-release@15 -c 'echo running semantic-release && semantic-release'"`;
11+
exports[`travis-after-success does not do the codecov script when there is no coverage directory 1`] = `concurrently --prefix [{name}] --names release --prefix-colors bgBlue.bold.reset "echo installing semantic-release && npx -p semantic-release@15 -c 'echo running semantic-release && semantic-release'"`;
2212

2313
exports[`travis-after-success does not run either script when no coverage dir and not the right version 1`] = `
2414
Array [
25-
Array [
26-
installing and running travis-deploy-once,
27-
],
2815
Array [
2916
No need to autorelease or report coverage. Skipping travis-after-success script...,
3017
],

src/scripts/__tests__/travis-after-success.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@ cases(
4040
if (runsNothing) {
4141
expect(console.log.mock.calls).toMatchSnapshot()
4242
} else {
43-
expect(crossSpawnSyncMock).toHaveBeenCalledTimes(2)
44-
const [firstCall, secondCall] = crossSpawnSyncMock.mock.calls
45-
const [scriptOne, calledArgsOne] = firstCall
46-
expect([scriptOne, ...calledArgsOne].join(' ')).toMatchSnapshot()
47-
const [scriptTwo, calledArgsTwo] = secondCall
48-
expect([scriptTwo, ...calledArgsTwo].join(' ')).toMatchSnapshot()
43+
expect(crossSpawnSyncMock).toHaveBeenCalledTimes(1)
44+
const [call] = crossSpawnSyncMock.mock.calls
45+
const [script, calledArgs] = call
46+
expect([script, ...calledArgs].join(' ')).toMatchSnapshot()
4947
}
5048

5149
// afterEach

src/scripts/travis-after-success.js

+28-44
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const spawn = require('cross-spawn')
2+
23
const {
34
resolveBin,
45
getConcurrentlyArgs,
@@ -7,51 +8,34 @@ const {
78
parseEnv,
89
} = require('../utils')
910

10-
console.log('installing and running travis-deploy-once')
11-
const deployOnceResults = spawn.sync('npx', ['travis-deploy-once@5'], {
12-
stdio: 'inherit',
13-
})
14-
if (deployOnceResults.status === 0) {
15-
runAfterSuccessScripts()
16-
} else {
17-
console.log(
18-
'travis-deploy-once exited with a non-zero exit code',
19-
deployOnceResults.status,
20-
)
21-
process.exit(deployOnceResults.status)
22-
}
23-
24-
// eslint-disable-next-line complexity
25-
function runAfterSuccessScripts() {
26-
const autorelease =
27-
pkg.version === '0.0.0-semantically-released' &&
28-
parseEnv('TRAVIS', false) &&
29-
process.env.TRAVIS_BRANCH === 'master' &&
30-
!parseEnv('TRAVIS_PULL_REQUEST', false)
11+
const autorelease =
12+
pkg.version === '0.0.0-semantically-released' &&
13+
parseEnv('TRAVIS', false) &&
14+
process.env.TRAVIS_BRANCH === 'master' &&
15+
!parseEnv('TRAVIS_PULL_REQUEST', false)
3116

32-
const reportCoverage = hasFile('coverage') && !parseEnv('SKIP_CODECOV', false)
17+
const reportCoverage = hasFile('coverage') && !parseEnv('SKIP_CODECOV', false)
3318

34-
if (!autorelease && !reportCoverage) {
35-
console.log(
36-
'No need to autorelease or report coverage. Skipping travis-after-success script...',
37-
)
38-
} else {
39-
const result = spawn.sync(
40-
resolveBin('concurrently'),
41-
getConcurrentlyArgs(
42-
{
43-
codecov: reportCoverage
44-
? `echo installing codecov && npx -p codecov@3 -c 'echo running codecov && codecov'`
45-
: null,
46-
release: autorelease
47-
? `echo installing semantic-release && npx -p semantic-release@15 -c 'echo running semantic-release && semantic-release'`
48-
: null,
49-
},
50-
{killOthers: false},
51-
),
52-
{stdio: 'inherit'},
53-
)
19+
if (!autorelease && !reportCoverage) {
20+
console.log(
21+
'No need to autorelease or report coverage. Skipping travis-after-success script...',
22+
)
23+
} else {
24+
const result = spawn.sync(
25+
resolveBin('concurrently'),
26+
getConcurrentlyArgs(
27+
{
28+
codecov: reportCoverage
29+
? `echo installing codecov && npx -p codecov@3 -c 'echo running codecov && codecov'`
30+
: null,
31+
release: autorelease
32+
? `echo installing semantic-release && npx -p semantic-release@15 -c 'echo running semantic-release && semantic-release'`
33+
: null,
34+
},
35+
{killOthers: false},
36+
),
37+
{stdio: 'inherit'},
38+
)
5439

55-
process.exit(result.status)
56-
}
40+
process.exit(result.status)
5741
}

0 commit comments

Comments
 (0)