@cmflow/cli 0.65.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +106 -0
- package/bin/checkfeatures.sh +5 -0
- package/bin/cm-changelog.js +17 -0
- package/bin/cm-clean.js +10 -0
- package/bin/cm-config.js +14 -0
- package/bin/cm-deploy.js +11 -0
- package/bin/cm-fetch.js +11 -0
- package/bin/cm-finish.js +13 -0
- package/bin/cm-publish-pages.js +11 -0
- package/bin/cm-publish.js +14 -0
- package/bin/cm-push.js +14 -0
- package/bin/cm-rebase.js +14 -0
- package/bin/cm-republish.js +11 -0
- package/bin/cm-start.js +20 -0
- package/bin/cm.js +20 -0
- package/bin/cmexpedit.sh +9 -0
- package/bin/cmpull.sh +7 -0
- package/bin/cmrelease.js +3 -0
- package/package.json +88 -0
- package/release.config.js +19 -0
- package/semantic.js +1 -0
- package/src/commands/changelog.js +47 -0
- package/src/commands/clean.js +30 -0
- package/src/commands/config.js +23 -0
- package/src/commands/deploy.js +39 -0
- package/src/commands/fetch.js +21 -0
- package/src/commands/finish.js +44 -0
- package/src/commands/index.js +10 -0
- package/src/commands/prompts/branches.js +38 -0
- package/src/commands/publish-pages.js +29 -0
- package/src/commands/push.js +26 -0
- package/src/commands/rebase.js +38 -0
- package/src/commands/release.js +36 -0
- package/src/commands/republish.js +24 -0
- package/src/commands/start.js +82 -0
- package/src/commands/tasks/push-branch.js +16 -0
- package/src/commands/tasks/rebase-all-branches.js +34 -0
- package/src/commands/tasks/refresh-repository.js +33 -0
- package/src/commands/tasks/run-test.js +23 -0
- package/src/commands/tasks/update-branch.js +40 -0
- package/src/commands/tasks/update-dependencies.js +37 -0
- package/src/commands/utils/check-install.js +31 -0
- package/src/common/cli/cli.js +107 -0
- package/src/common/cli/docker.js +63 -0
- package/src/common/cli/docker.test.js +128 -0
- package/src/common/cli/git.js +130 -0
- package/src/common/cli/git.test.js +205 -0
- package/src/common/cli/heroku.js +21 -0
- package/src/common/cli/heroku.test.js +56 -0
- package/src/common/cli/lerna.js +25 -0
- package/src/common/cli/lerna.test.js +48 -0
- package/src/common/cli/npm.js +33 -0
- package/src/common/cli/npm.test.js +47 -0
- package/src/common/cli/yarn.js +33 -0
- package/src/common/cli/yarn.test.js +48 -0
- package/src/common/configure-git-workspace.js +27 -0
- package/src/common/get-config.js +135 -0
- package/src/common/get-package-json.js +7 -0
- package/src/common/get-release-config.js +7 -0
- package/src/common/index.js +10 -0
- package/src/common/run-command.js +61 -0
- package/src/common/run-command.test.js +63 -0
- package/src/index.js +1 -0
- package/src/main.js +10 -0
- package/src/semantic-release/actions/analyze-commits.js +9 -0
- package/src/semantic-release/actions/fail.js +16 -0
- package/src/semantic-release/actions/generate-notes.js +11 -0
- package/src/semantic-release/actions/index.js +8 -0
- package/src/semantic-release/actions/prepare.js +101 -0
- package/src/semantic-release/actions/publish.js +17 -0
- package/src/semantic-release/actions/success.js +30 -0
- package/src/semantic-release/actions/verify-conditions.js +30 -0
- package/src/semantic-release/actions/verify-release.js +7 -0
- package/src/semantic-release/get-semantic-config.js +115 -0
- package/src/semantic-release/utils/calculate-snapshot-version.js +9 -0
- package/src/semantic-release/utils/calculate-snapshot-version.test.js +57 -0
- package/src/semantic-release/utils/display-package-info.js +11 -0
- package/src/semantic-release/utils/display-release-info.js +12 -0
- package/src/semantic-release/utils/docker-clean-tags.js +45 -0
- package/src/semantic-release/utils/docker-clean-tags.test.js +54 -0
- package/src/semantic-release/utils/docker-publish.js +36 -0
- package/src/semantic-release/utils/docker-publish.test.js +43 -0
- package/src/semantic-release/utils/ghpages-publish.js +16 -0
- package/src/semantic-release/utils/log-section.js +5 -0
- package/src/workflow/index.js +37 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Cli } from './cli'
|
|
2
|
+
|
|
3
|
+
class YarnCli extends Cli {
|
|
4
|
+
constructor () {
|
|
5
|
+
super('yarn')
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
newVersion (version) {
|
|
9
|
+
return this.version('--no-git-tag-version', '--new-version', version)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
version (...args) {
|
|
13
|
+
return this.sync('version', ...args)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
run (...args) {
|
|
17
|
+
return super.run(...args)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
install (...args) {
|
|
21
|
+
return super.run('add', ...args)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Reinstall dependencies without yarn.lock mutation
|
|
26
|
+
* @returns {Promise<unknown>}
|
|
27
|
+
*/
|
|
28
|
+
restore () {
|
|
29
|
+
return super.run('install', '--frozen-lockfile', '--production=false')
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const yarn = new YarnCli()
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import execa from 'execa'
|
|
2
|
+
import { yarn } from './yarn'
|
|
3
|
+
import { Cli } from './cli'
|
|
4
|
+
|
|
5
|
+
jest.mock('execa')
|
|
6
|
+
|
|
7
|
+
execa.sync.mockImplementation((...args) => {
|
|
8
|
+
return {
|
|
9
|
+
stdout: `CMD: ${[].concat(...args.filter(arg => typeof arg === 'string' || Array.isArray(arg))).join(' ')}`
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
execa.mockReturnValue({})
|
|
14
|
+
|
|
15
|
+
describe('YarnCli', () => {
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
jest.spyOn(Cli, 'getRaw').mockImplementation((...args) => {
|
|
18
|
+
return `CMD: ${[].concat(...args.filter(arg => typeof arg === 'string' || Array.isArray(arg))).join(' ')}`
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
describe('newVersion', () => {
|
|
22
|
+
it('should run newVersion cmd', () => {
|
|
23
|
+
const result = yarn.newVersion('1.0.0')
|
|
24
|
+
|
|
25
|
+
expect(result.stdout).toEqual('CMD: yarn version --no-git-tag-version --new-version 1.0.0')
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
describe('run', () => {
|
|
29
|
+
it('should run "run" cmd', async () => {
|
|
30
|
+
await yarn.run('run-arg')
|
|
31
|
+
|
|
32
|
+
expect(execa).toHaveBeenCalledWith('yarn', ['run-arg'], {
|
|
33
|
+
cwd: process.cwd(),
|
|
34
|
+
stdio: 'inherit'
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
describe('install', () => {
|
|
39
|
+
it('should run "install" cmd', async () => {
|
|
40
|
+
await yarn.install('install-arg')
|
|
41
|
+
|
|
42
|
+
expect(execa).toHaveBeenCalledWith('yarn', ['add', 'install-arg'], {
|
|
43
|
+
cwd: process.cwd(),
|
|
44
|
+
stdio: 'inherit'
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
})
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { git } from './cli/git'
|
|
2
|
+
|
|
3
|
+
export function configureGitWorkspace (context) {
|
|
4
|
+
const {
|
|
5
|
+
logger,
|
|
6
|
+
config: {
|
|
7
|
+
GH_TOKEN,
|
|
8
|
+
REPOSITORY_URL,
|
|
9
|
+
ORIGIN,
|
|
10
|
+
GIT_USER_NAME,
|
|
11
|
+
GIT_USER_EMAIL
|
|
12
|
+
}
|
|
13
|
+
} = context
|
|
14
|
+
|
|
15
|
+
if (GIT_USER_NAME && GIT_USER_EMAIL) {
|
|
16
|
+
git.config('--global', 'user.name', `"${GIT_USER_NAME}"`)
|
|
17
|
+
git.config('--global', 'user.email', `"${GIT_USER_EMAIL}"`)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (GH_TOKEN) {
|
|
21
|
+
const repository = REPOSITORY_URL.replace('https://', '')
|
|
22
|
+
|
|
23
|
+
logger.info(`Configure remote repository ${repository}`)
|
|
24
|
+
git.remote('remove', ORIGIN).sync()
|
|
25
|
+
git.remote('add', ORIGIN, `https://${GH_TOKEN}@${repository}`).sync()
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import hasYarn from 'has-yarn'
|
|
2
|
+
import { get } from 'lodash'
|
|
3
|
+
import { git } from './cli/git'
|
|
4
|
+
import { getPackageJson } from './get-package-json'
|
|
5
|
+
|
|
6
|
+
const toBool = (value) => {
|
|
7
|
+
if (value === 'false') return false
|
|
8
|
+
if (value === '0') return false
|
|
9
|
+
|
|
10
|
+
return !!value
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function getCI () {
|
|
14
|
+
const { env } = process
|
|
15
|
+
const { GIT_USER_NAME, GIT_USER_EMAIL } = env
|
|
16
|
+
if (env.CI) {
|
|
17
|
+
if (env.TRAVIS) {
|
|
18
|
+
const { TRAVIS_BUILD_NUMBER, TRAVIS_COMMIT, TRAVIS_PULL_REQUEST, TRAVIS_BRANCH } = env
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
CI_NAME: 'Travis CI',
|
|
22
|
+
USER: GIT_USER_NAME || 'Travis CI',
|
|
23
|
+
EMAIL: GIT_USER_EMAIL || 'travis@travis-ci.org',
|
|
24
|
+
BUILD_NUMBER: TRAVIS_BUILD_NUMBER,
|
|
25
|
+
CI_ORIGIN: 'origin-git',
|
|
26
|
+
REF_COMMIT: TRAVIS_COMMIT,
|
|
27
|
+
IS_PULL_REQUEST: TRAVIS_PULL_REQUEST && TRAVIS_PULL_REQUEST !== 'false',
|
|
28
|
+
BRANCH_NAME: TRAVIS_BRANCH
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (env.GITLAB_CI) {
|
|
33
|
+
const { CI_BUILD_ID, CI_JOB_ID, CI_COMMIT_SHA, CI_COMMIT_BRANCH } = env
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
CI_NAME: 'GitLab CI',
|
|
37
|
+
USER: GIT_USER_NAME || 'GitLab CI',
|
|
38
|
+
EMAIL: GIT_USER_EMAIL || 'gitlab@gitlab.com',
|
|
39
|
+
BUILD_NUMBER: CI_BUILD_ID || CI_JOB_ID,
|
|
40
|
+
CI_ORIGIN: 'origin-git',
|
|
41
|
+
REF_COMMIT: CI_COMMIT_SHA,
|
|
42
|
+
IS_PULL_REQUEST: false,
|
|
43
|
+
BRANCH_NAME: CI_COMMIT_BRANCH
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (env.CIRCLECI) {
|
|
48
|
+
const { CIRCLE_BUILD_NUM, CIRCLE_SHA1, CIRCLE_PULL_REQUEST, CIRCLE_BRANCH } = env
|
|
49
|
+
return {
|
|
50
|
+
CI_NAME: 'Circle CI',
|
|
51
|
+
USER: GIT_USER_NAME || 'Circle CI',
|
|
52
|
+
EMAIL: GIT_USER_EMAIL || 'circle@circleci.com',
|
|
53
|
+
BUILD_NUMBER: CIRCLE_BUILD_NUM,
|
|
54
|
+
CI_ORIGIN: 'origin-git',
|
|
55
|
+
REF_COMMIT: CIRCLE_SHA1,
|
|
56
|
+
IS_PULL_REQUEST: CIRCLE_PULL_REQUEST && CIRCLE_PULL_REQUEST !== 'false',
|
|
57
|
+
BRANCH_NAME: CIRCLE_BRANCH
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
NAME: 'Unsupported CI',
|
|
62
|
+
BUILD_NUMBER: '',
|
|
63
|
+
CI_ORIGIN: 'origin-git',
|
|
64
|
+
IS_PULL_REQUEST: false,
|
|
65
|
+
BRANCH_NAME: git.getBranchName()
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// / local
|
|
69
|
+
return {
|
|
70
|
+
NAME: 'LOCAL',
|
|
71
|
+
BUILD_NUMBER: '1',
|
|
72
|
+
CI_ORIGIN: 'origin-git',
|
|
73
|
+
BRANCH_NAME: git.getBranchName()
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function getConfig () {
|
|
78
|
+
const pkg = getPackageJson()
|
|
79
|
+
const [owner, projectName] = pkg.name.replace(/^@/, '').split('/')
|
|
80
|
+
const {
|
|
81
|
+
PROJECT_NAME,
|
|
82
|
+
DOCKER_HUB_ID,
|
|
83
|
+
DOCKER_HUB_PWD,
|
|
84
|
+
REF_COMMIT,
|
|
85
|
+
GH_TOKEN,
|
|
86
|
+
HEROKU_APP,
|
|
87
|
+
SKIP_DEPLOY,
|
|
88
|
+
SKIP_GITHUB_PUBLISH,
|
|
89
|
+
GITHUB_PAGES_PATH,
|
|
90
|
+
REPOSITORY_URL,
|
|
91
|
+
GIT_USER_NAME,
|
|
92
|
+
GIT_USER_EMAIL
|
|
93
|
+
} = process.env
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
PROJECT_NAME: PROJECT_NAME || projectName,
|
|
97
|
+
HAS_YARN: hasYarn(),
|
|
98
|
+
HAS_LERNA: pkg.dependencies.lerna || pkg.devDependencies.lerna,
|
|
99
|
+
HAS_BUILD: pkg.scripts.build,
|
|
100
|
+
HAS_E2E: pkg.scripts.test_e2e,
|
|
101
|
+
HAS_BUILD_CHANGELOG: pkg.scripts.build_changelog,
|
|
102
|
+
get DEPLOY_ON_DOCKER () {
|
|
103
|
+
return toBool(process.env.DEPLOY_ON_DOCKER) && DOCKER_HUB_ID && DOCKER_HUB_PWD
|
|
104
|
+
},
|
|
105
|
+
DEPLOY_ON_HEROKU: !!HEROKU_APP,
|
|
106
|
+
CI_SKIP: '[ci skip]',
|
|
107
|
+
RELEASE_CANDIDATE_TAG: '[MEP]',
|
|
108
|
+
ORIGIN: 'origin',
|
|
109
|
+
get PRODUCTION_BRANCH () {
|
|
110
|
+
return process.env.PRODUCTION_BRANCH || 'production'
|
|
111
|
+
},
|
|
112
|
+
get DEVELOP_BRANCH () {
|
|
113
|
+
return process.env.DEVELOP_BRANCH || 'master'
|
|
114
|
+
},
|
|
115
|
+
get OWNER () {
|
|
116
|
+
return process.env.OWNER || owner
|
|
117
|
+
},
|
|
118
|
+
get DOCKER_REPOSITORY () {
|
|
119
|
+
const { DOCKER_REPOSITORY, OWNER, PROJECT_NAME } = process.env
|
|
120
|
+
return DOCKER_REPOSITORY || `${OWNER || owner}/${PROJECT_NAME || projectName}`
|
|
121
|
+
},
|
|
122
|
+
DOCKER_HUB_ID,
|
|
123
|
+
DOCKER_HUB_PWD,
|
|
124
|
+
HEROKU_APP,
|
|
125
|
+
REF_COMMIT,
|
|
126
|
+
GH_TOKEN,
|
|
127
|
+
REPOSITORY_URL: get(pkg, 'repository.url', get(pkg, 'repository', REPOSITORY_URL)),
|
|
128
|
+
SKIP_DEPLOY,
|
|
129
|
+
SKIP_GITHUB_PUBLISH,
|
|
130
|
+
GITHUB_PAGES_PATH,
|
|
131
|
+
GIT_USER_NAME,
|
|
132
|
+
GIT_USER_EMAIL,
|
|
133
|
+
...getCI()
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './cli/cli'
|
|
2
|
+
export * from './cli/docker'
|
|
3
|
+
export * from './cli/git'
|
|
4
|
+
export * from './cli/lerna'
|
|
5
|
+
export * from './cli/npm'
|
|
6
|
+
export * from './cli/yarn'
|
|
7
|
+
export * from './get-config'
|
|
8
|
+
export * from './configure-git-workspace'
|
|
9
|
+
export * from './get-package-json'
|
|
10
|
+
export * from './run-command'
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
import figures from 'figures'
|
|
3
|
+
import inquirer from 'inquirer'
|
|
4
|
+
import Listr from 'listr'
|
|
5
|
+
import { getReleaseConfig } from './get-release-config'
|
|
6
|
+
import { getConfig } from './get-config'
|
|
7
|
+
|
|
8
|
+
function createTasksRunner (tasks, ctx) {
|
|
9
|
+
return new Listr(tasks, {
|
|
10
|
+
concurrent: false,
|
|
11
|
+
renderer: !ctx.verbose ? 'default' : 'verbose'
|
|
12
|
+
}).run(ctx)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function runCommand (klass, commander) {
|
|
16
|
+
try {
|
|
17
|
+
let context = {
|
|
18
|
+
...getReleaseConfig(),
|
|
19
|
+
...getConfig(),
|
|
20
|
+
verbose: commander.verbose
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// eslint-disable-next-line new-cap
|
|
24
|
+
const command = new klass()
|
|
25
|
+
|
|
26
|
+
// Map context from commander and current context
|
|
27
|
+
if (command.mapContext) {
|
|
28
|
+
context = command.mapContext(commander, context)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// show prompts
|
|
32
|
+
if (command.prompt) {
|
|
33
|
+
context = {
|
|
34
|
+
...context,
|
|
35
|
+
...await inquirer.prompt(command.prompt(context))
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Verify conditions
|
|
40
|
+
command.verifyConditions && command.verifyConditions(context)
|
|
41
|
+
|
|
42
|
+
// Get tasks
|
|
43
|
+
const tasks = command.getTasks(context)
|
|
44
|
+
|
|
45
|
+
// Run tasks
|
|
46
|
+
await createTasksRunner(tasks, context)
|
|
47
|
+
|
|
48
|
+
command.success && command.success(context)
|
|
49
|
+
} catch (er) {
|
|
50
|
+
// eslint-disable-next-line no-console
|
|
51
|
+
console.error(chalk.red(figures.cross + ' ' + String(er)))
|
|
52
|
+
if (commander.verbose) {
|
|
53
|
+
// eslint-disable-next-line no-console
|
|
54
|
+
console.error(String(er.stack).replace(String(er), ''))
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
process.on('unhandledRejection', (reason, p) => {
|
|
60
|
+
// avoid extra promise rejection when using toObservable
|
|
61
|
+
})
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import Listr from 'listr'
|
|
2
|
+
import { runCommand } from './run-command'
|
|
3
|
+
|
|
4
|
+
jest.mock('listr')
|
|
5
|
+
|
|
6
|
+
describe('runCommand', () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
Listr.mockReturnValue({
|
|
9
|
+
run () {
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
})
|
|
13
|
+
it('should call runCommand', async () => {
|
|
14
|
+
class Cmd {
|
|
15
|
+
mapContext (ctx) {
|
|
16
|
+
return {
|
|
17
|
+
...ctx,
|
|
18
|
+
test: true
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getTasks () {
|
|
23
|
+
return []
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
jest.spyOn(Cmd.prototype, 'mapContext')
|
|
28
|
+
jest.spyOn(Cmd.prototype, 'getTasks')
|
|
29
|
+
|
|
30
|
+
await runCommand(Cmd, {
|
|
31
|
+
prop: '1'
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
expect(Cmd.prototype.mapContext).toHaveBeenCalledWith({ prop: '1' }, expect.any(Object))
|
|
35
|
+
expect(Cmd.prototype.getTasks).toHaveBeenCalledWith({
|
|
36
|
+
prop: '1',
|
|
37
|
+
test: true
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
it('should call runCommand and catch error', async () => {
|
|
41
|
+
class Cmd {
|
|
42
|
+
mapContext (ctx) {
|
|
43
|
+
return {
|
|
44
|
+
...ctx,
|
|
45
|
+
test: true
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
getTasks () {
|
|
50
|
+
throw new Error('Error')
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
jest.spyOn(console, 'error').mockReturnValue(undefined)
|
|
55
|
+
|
|
56
|
+
await runCommand(Cmd, {
|
|
57
|
+
prop: '1'
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
// eslint-disable-next-line no-console
|
|
61
|
+
expect(console.error).toHaveBeenCalled()
|
|
62
|
+
})
|
|
63
|
+
})
|
package/src/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('esm')(module)('./main.js')
|
package/src/main.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import commitAnalyzerPlugins from '@semantic-release/commit-analyzer'
|
|
2
|
+
|
|
3
|
+
export function analyzeCommits (pluginConfig, context) {
|
|
4
|
+
if (context.branch && context.branch.type !== 'prerelease') {
|
|
5
|
+
return commitAnalyzerPlugins.analyzeCommits(pluginConfig, context)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return 'patch' // always trigger patch for prerelease
|
|
9
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import githubPlugins from '@semantic-release/github'
|
|
2
|
+
import { git } from '../../common'
|
|
3
|
+
|
|
4
|
+
export async function fail (pluginConfig, context) {
|
|
5
|
+
if (context.branch && context.branch.type !== 'prerelease') {
|
|
6
|
+
const { tagFormat, config: { ORIGIN } } = context
|
|
7
|
+
|
|
8
|
+
try {
|
|
9
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
10
|
+
await git.push('--delete', ORIGIN, tagFormat.replace('${version}', context.nextRelease.version))
|
|
11
|
+
} catch (er) {
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
await githubPlugins.fail(pluginConfig, context)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import releaseNotesPlugins from '@semantic-release/release-notes-generator'
|
|
2
|
+
import { npm, yarn } from '../../common'
|
|
3
|
+
|
|
4
|
+
export async function generateNotes (pluginConfig, context) {
|
|
5
|
+
if (context.branch.type === 'release' && !context.config.SKIP_GITHUB_PUBLISH) {
|
|
6
|
+
if (context.config.HAS_BUILD_CHANGELOG) {
|
|
7
|
+
await (context.config.HAS_YARN ? yarn : npm).run('build_changelog')
|
|
8
|
+
}
|
|
9
|
+
return releaseNotesPlugins.generateNotes(pluginConfig, context)
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { dockerPublish } from '../utils/docker-publish'
|
|
2
|
+
import { git, lerna, npm, yarn, configureGitWorkspace } from '../../common'
|
|
3
|
+
|
|
4
|
+
async function gitMep (context) {
|
|
5
|
+
const { logger, branch, config: { PRODUCTION_BRANCH, ORIGIN } } = context
|
|
6
|
+
|
|
7
|
+
logger.info(`Branch ${branch.name} is candidate to MEP`)
|
|
8
|
+
|
|
9
|
+
git.reset('--hard')
|
|
10
|
+
git.clean('-f', '-d').sync()
|
|
11
|
+
|
|
12
|
+
logger.start('Checkout production branch')
|
|
13
|
+
|
|
14
|
+
git.config('--replace-all', 'remote.origin.fetch', '+refs/heads/*:refs/remotes/origin/*')
|
|
15
|
+
git.fetch().sync()
|
|
16
|
+
git.fetch('--tags').sync()
|
|
17
|
+
git.checkout('-qf', PRODUCTION_BRANCH).sync()
|
|
18
|
+
|
|
19
|
+
logger.success(`Current branch: ${PRODUCTION_BRANCH}`)
|
|
20
|
+
|
|
21
|
+
const building = git.getLastCommitMsg()
|
|
22
|
+
logger.info('Last commit message on production', building)
|
|
23
|
+
|
|
24
|
+
logger.start(`Merge ${branch.name} into ${PRODUCTION_BRANCH} branch`)
|
|
25
|
+
git.merge('--no-ff', '-m', `${branch.name}`, branch.name)
|
|
26
|
+
logger.success(`${branch.name} merged into ${PRODUCTION_BRANCH} branch`)
|
|
27
|
+
|
|
28
|
+
configureGitWorkspace(context)
|
|
29
|
+
|
|
30
|
+
logger.start(`Push ${PRODUCTION_BRANCH} branch`)
|
|
31
|
+
await git.push(ORIGIN, PRODUCTION_BRANCH)
|
|
32
|
+
logger.success(`${PRODUCTION_BRANCH} branch pushed`)
|
|
33
|
+
|
|
34
|
+
logger.start(`Remove ${ORIGIN}/${branch.name} branch`)
|
|
35
|
+
await git.push(ORIGIN, ':' + branch.name)
|
|
36
|
+
logger.success(`${ORIGIN}/${branch.name} branch correctly removed`)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function gitPrepareRelease (pluginConfig, context) {
|
|
40
|
+
const { logger, config: { CI_NAME, BUILD_NUMBER } } = context
|
|
41
|
+
|
|
42
|
+
logger.info('Adding files to commit')
|
|
43
|
+
git.add('-A').sync()
|
|
44
|
+
|
|
45
|
+
logger.info('Get commit stage status')
|
|
46
|
+
git.status()
|
|
47
|
+
|
|
48
|
+
const revisionMessage = `${CI_NAME} build: ${context.branch.name} ${BUILD_NUMBER} ${context.nextRelease.gitTag} [ci skip]`
|
|
49
|
+
|
|
50
|
+
logger.info('Commit changes with revision message: ')
|
|
51
|
+
logger.info(revisionMessage)
|
|
52
|
+
|
|
53
|
+
git.commit('-m', revisionMessage).sync()
|
|
54
|
+
|
|
55
|
+
logger.success('Change committed')
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function prepare (pluginConfig, context) {
|
|
59
|
+
const { branch, config: { RELEASE_CANDIDATE_TAG, HAS_BUILD, HAS_E2E, SKIP_DEPLOY, SKIP_GITHUB_PUBLISH }, logger } = context
|
|
60
|
+
const pkgManager = context.config.HAS_YARN ? yarn : npm
|
|
61
|
+
|
|
62
|
+
pkgManager.newVersion(context.nextRelease.version)
|
|
63
|
+
|
|
64
|
+
if (context.config.HAS_LERNA) { // support project based on lerna
|
|
65
|
+
await lerna.newVersion(context.nextRelease.version)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (HAS_BUILD && !SKIP_DEPLOY) {
|
|
69
|
+
logger.info('Start build task')
|
|
70
|
+
await pkgManager.run('build')
|
|
71
|
+
logger.info('Build task finished with success...')
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (HAS_E2E && !SKIP_DEPLOY) {
|
|
75
|
+
logger.info('Start test_e2e task')
|
|
76
|
+
await pkgManager.run('test_e2e')
|
|
77
|
+
logger.info('test_e2e task finished with success...')
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!SKIP_GITHUB_PUBLISH) {
|
|
81
|
+
if (branch.type === 'release') {
|
|
82
|
+
logger.info('Prepare release')
|
|
83
|
+
configureGitWorkspace(context)
|
|
84
|
+
return gitPrepareRelease(pluginConfig, context)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const lastCommitMessage = git.getLastCommitMsg()
|
|
88
|
+
|
|
89
|
+
logger.info('Last commit message:', lastCommitMessage)
|
|
90
|
+
if (lastCommitMessage.includes(RELEASE_CANDIDATE_TAG)) {
|
|
91
|
+
await gitMep(context)
|
|
92
|
+
process.exit(0)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!SKIP_DEPLOY) {
|
|
97
|
+
await dockerPublish(context)
|
|
98
|
+
}
|
|
99
|
+
// avoid next semantic-release steps when is a prerelease or release branch with SKIP_GITHUB_PUBLISH
|
|
100
|
+
process.exit(0)
|
|
101
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import githubPlugins from '@semantic-release/github'
|
|
2
|
+
import { dockerPublish } from '../utils/docker-publish'
|
|
3
|
+
import { ghPagesPublish } from '../utils/ghpages-publish'
|
|
4
|
+
|
|
5
|
+
export async function publish (pluginConfig, context) {
|
|
6
|
+
const { branch, env: { SKIP_GITHUB_PUBLISH, GITHUB_PAGES_PATH } } = context
|
|
7
|
+
|
|
8
|
+
if (!SKIP_GITHUB_PUBLISH && branch.type === 'release') {
|
|
9
|
+
await githubPlugins.publish(pluginConfig, context)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (GITHUB_PAGES_PATH && branch.type === 'release') {
|
|
13
|
+
await ghPagesPublish(context)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
await dockerPublish(context)
|
|
17
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import githubPlugins from '@semantic-release/github'
|
|
2
|
+
import { dockerCleanTags } from '../utils/docker-clean-tags'
|
|
3
|
+
import { git } from '../../common'
|
|
4
|
+
|
|
5
|
+
async function githubSuccess (pluginConfig, context) {
|
|
6
|
+
const { logger, config: { PRODUCTION_BRANCH, ORIGIN, DEVELOP_BRANCH } } = context
|
|
7
|
+
await git.push('--quiet', '--set-upstream', ORIGIN, PRODUCTION_BRANCH)
|
|
8
|
+
|
|
9
|
+
if (PRODUCTION_BRANCH !== DEVELOP_BRANCH) {
|
|
10
|
+
logger.start(`Reset HEAD of ${ORIGIN}/${DEVELOP_BRANCH} branch to HEAD of ${ORIGIN}/${PRODUCTION_BRANCH} `)
|
|
11
|
+
await git.push('-f', ORIGIN, `refs/remotes/${ORIGIN}/${PRODUCTION_BRANCH}:refs/heads/${DEVELOP_BRANCH}`)
|
|
12
|
+
logger.success(`${ORIGIN}/${DEVELOP_BRANCH} branch correctly updated`)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
await githubPlugins.success(pluginConfig, context)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function success (pluginConfig, context) {
|
|
19
|
+
const { branch, config: { SKIP_GITHUB_PUBLISH } } = context
|
|
20
|
+
|
|
21
|
+
if (branch.type !== 'prerelease' && !SKIP_GITHUB_PUBLISH) {
|
|
22
|
+
await githubSuccess(pluginConfig, context)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
await dockerCleanTags(context)
|
|
27
|
+
} catch (er) {
|
|
28
|
+
context.logger.warn(er)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
import githubPlugins from '@semantic-release/github'
|
|
3
|
+
import { git } from '../../common'
|
|
4
|
+
|
|
5
|
+
export function verifyConditions (pluginConfig, context) {
|
|
6
|
+
if (pluginConfig.dryRun) {
|
|
7
|
+
return
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const { branch, config: { USER, EMAIL, ORIGIN } } = context
|
|
11
|
+
|
|
12
|
+
if (USER && EMAIL) {
|
|
13
|
+
context.logger.info('Configure git with username')
|
|
14
|
+
|
|
15
|
+
git.config('--global', 'user.name', USER)
|
|
16
|
+
git.config('--global', 'user.email', EMAIL)
|
|
17
|
+
|
|
18
|
+
context.logger.info('Configure git branch')
|
|
19
|
+
context.logger.success('Workspace is correctly configured')
|
|
20
|
+
} else {
|
|
21
|
+
context.logger.error(chalk.red('Ignore git configuration (Empty GIT_USER_EMAIL or/and GIT_USER_NAME variables)'))
|
|
22
|
+
process.exit(1)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
git.fetch().sync()
|
|
26
|
+
git.checkout(branch.name).sync()
|
|
27
|
+
git.branch(`--set-upstream-to=${ORIGIN}/${branch.name}`, branch.name).sync()
|
|
28
|
+
|
|
29
|
+
return githubPlugins.verifyConditions(pluginConfig, context)
|
|
30
|
+
}
|