Skip to content

Commit 5d6bc3c

Browse files
Henrikof
authored andcommitted
[internal] Improve release script further (#999)
* Update create github release * Use write sync * v10.0.0 * Add github release script * Revert changelog and lerna.json * Revert "v10.0.0" This reverts commit 80882af. # Conflicts: # changelog.md * Added some logging to update-changelog * Update changelog * Fix some things * Add force publish option * Remove force publish from lerna.json * Move allow-branches option to package.json * Move creating github release into postrelease script * Fix package.json
1 parent 92013e2 commit 5d6bc3c

File tree

7 files changed

+106
-67
lines changed

7 files changed

+106
-67
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Next
22

3+
### Improvements
4+
5+
- [internal] Improve publish script for creating github release ([#999](https://github.com/cssinjs/jss/pull/999))
6+
37
### Bug fixes
48

59
- [jss-starter-kit] Fix react-jss exports and add missing jss exports ([#1001](https://github.com/cssinjs/jss/pull/1001))

lerna.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
{
22
"npmClient": "yarn",
33
"useWorkspaces": true,
4-
"version": "10.0.0-alpha.9",
5-
"command": {
6-
"publish": {
7-
"allowBranch": ["master"],
8-
"forcePublish": "*"
9-
}
10-
}
4+
"version": "10.0.0-alpha.9"
115
}

package.json

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,22 @@
66
],
77
"scripts": {
88
"build": "lerna run build",
9-
109
"check:all": "yarn check:flow && yarn check:ts && yarn check:snapshots && yarn check:lint",
1110
"check:flow": "flow check --max-warnings=0",
1211
"check:ts": "tsc",
1312
"check:snapshots": "lerna run check-snapshot",
1413
"check:lint": "eslint scripts/ packages/ docs/ --ext js,md",
15-
1614
"format": "prettier \"*.{js,md,json}\" \"{docs,packages,scripts}/**/*.{js,md,json}\" --write",
17-
"format:ci": "yarn format -- --list-different",
18-
15+
"format:ci": "yarn format --list-different",
1916
"test": "karma start --single-run",
2017
"test:watch": "karma start",
21-
"posttest": "[ -z \"$TRAVIS\" ] || codecov",
22-
"codecov": "codecov",
23-
"bench": "cross-env BENCHMARK=true karma start --single-run",
24-
18+
"test:bench": "cross-env BENCHMARK=true karma start --single-run",
2519
"pre-commit": "lint-staged && yarn check:all",
26-
2720
"---Release Scripts---": "",
2821
"version": "yarn build && yarn test && node ./scripts/update-changelog && node ./scripts/add-git-files",
2922
"prerelease": "yarn check:all && yarn format:ci",
30-
"release": "lerna publish --no-push --exact",
31-
"postrelease": "node ./scripts/create-git-tag && git push --tags",
23+
"release": "lerna publish --exact --force-publish * --allow-branch master",
24+
"postrelease": "node ./scripts/create-github-release",
3225
"release:patch": "yarn release patch --dist-tag latest",
3326
"release:minor": "yarn release minor --dist-tag latest",
3427
"release:major": "yarn release major --dist-tag latest",
@@ -60,6 +53,8 @@
6053
"@babel/preset-env": "^7.0.0",
6154
"@babel/preset-flow": "^7.0.0",
6255
"@babel/preset-react": "^7.0.0",
56+
"@lerna/prompt": "^3.6.0",
57+
"axios": "^0.18.0",
6358
"babel-loader": "^8.0.4",
6459
"babel-plugin-dev-expression": "^0.2.1",
6560
"camelcase": "^5.0.0",
@@ -89,6 +84,7 @@
8984
"lerna": "^3.8.0",
9085
"lint-staged": "^3.2.2",
9186
"mocha": "^3.2.0",
87+
"npmlog": "^4.1.2",
9288
"pre-commit": "^1.1.3",
9389
"prettier": "^1.13.5",
9490
"raf": "^3.4.0",

scripts/create-git-tag.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

scripts/create-github-release.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
const axios = require('axios')
4+
const log = require('npmlog/log')
5+
const {input} = require('@lerna/prompt')
6+
7+
const lerna = require('../lerna')
8+
const {CHANGELOG_FILENAME} = require('./constants')
9+
10+
function getChangelog() {
11+
const content = fs.readFileSync(path.join(process.cwd(), CHANGELOG_FILENAME), 'utf-8')
12+
const lines = content.split('\n')
13+
let hasStarted = false
14+
let hasFinished = false
15+
16+
return lines
17+
.filter(line => {
18+
if (hasFinished) {
19+
return false
20+
}
21+
22+
if (hasStarted) {
23+
hasFinished = line.startsWith('## ')
24+
25+
return !hasFinished
26+
}
27+
28+
hasStarted = line.startsWith(`## ${lerna.version}`)
29+
30+
return false
31+
})
32+
.join('\n')
33+
}
34+
35+
input('Github Username:')
36+
.then(username =>
37+
input('Github password:').then(password => ({
38+
username,
39+
password
40+
}))
41+
)
42+
.then(auth =>
43+
axios.request({
44+
method: 'POST',
45+
url: `/repos/cssinjs/jss/releases`,
46+
baseURL: `https://api.github.com`,
47+
data: {
48+
tag_name: `v${lerna.version}`,
49+
name: `v${lerna.version}`,
50+
body: getChangelog(),
51+
prerelease: lerna.version.includes('alpha')
52+
},
53+
auth
54+
})
55+
)
56+
.then(() => {
57+
log.info('jss', 'Successfully created github release')
58+
})
59+
.catch(err => {
60+
log.error('jss', `Error while creating github release: ${err.message}`)
61+
})

scripts/update-changelog.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
11
const fs = require('fs')
2-
const Path = require('path')
2+
const path = require('path')
3+
const log = require('npmlog/log')
4+
35
const lerna = require('../lerna')
46
const {CHANGELOG_FILENAME} = require('./constants')
57

6-
const changelogPath = Path.join(process.cwd(), CHANGELOG_FILENAME)
8+
const changelogPath = path.join(process.cwd(), CHANGELOG_FILENAME)
79
const content = fs.readFileSync(changelogPath, 'utf-8')
810

911
const lines = content
1012
.split('\n')
1113
.map(line => {
12-
if (line.startsWith(`## ${lerna.version} (unreleased)`)) {
14+
if (line === '## Next') {
1315
const today = new Date()
14-
return line.replace(
15-
'unreleased',
16-
`${today.getUTCFullYear()}-${today.getUTCMonth() + 1}-${today.getUTCDate()}`
17-
)
16+
const date = `${today.getUTCFullYear()}-${today.getUTCMonth() + 1}-${today.getUTCDate()}`
17+
18+
return `## ${lerna.version} (${date})`
1819
}
1920

2021
return line
2122
})
2223
.join('\n')
2324

24-
fs.writeFile(changelogPath, lines, 'utf-8')
25+
fs.writeFile(changelogPath, lines, 'utf-8', err => {
26+
if (err) {
27+
log.error('jss', 'Error while updating changelog')
28+
process.exit(1)
29+
} else {
30+
log.info('jss', 'Successfully updated changelog')
31+
}
32+
})

yarn.lock

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,7 @@
11771177
resolve-from "^4.0.0"
11781178
write-json-file "^2.3.0"
11791179

1180-
"@lerna/prompt@3.6.0":
1180+
"@lerna/prompt@3.6.0", "@lerna/prompt@^3.6.0":
11811181
version "3.6.0"
11821182
resolved "https://registry.yarnpkg.com/@lerna/prompt/-/prompt-3.6.0.tgz#b17cc464dec9d830619723e879dc747367378217"
11831183
integrity sha512-nyAjPMolJ/ZRAAVcXrUH89C4n1SiWvLh4xWNvWYKLcf3PI5yges35sDFP/HYrM4+cEbkNFuJCRq6CxaET4PRsg==
@@ -2089,6 +2089,14 @@ aws4@^1.8.0:
20892089
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f"
20902090
integrity sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==
20912091

2092+
axios@^0.18.0:
2093+
version "0.18.0"
2094+
resolved "https://registry.yarnpkg.com/axios/-/axios-0.18.0.tgz#32d53e4851efdc0a11993b6cd000789d70c05102"
2095+
integrity sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=
2096+
dependencies:
2097+
follow-redirects "^1.3.0"
2098+
is-buffer "^1.1.5"
2099+
20922100
axobject-query@^2.0.1:
20932101
version "2.0.1"
20942102
resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.0.1.tgz#05dfa705ada8ad9db993fa6896f22d395b0b0a07"
@@ -3356,7 +3364,7 @@ debug@2.6.8:
33563364
dependencies:
33573365
ms "2.0.0"
33583366

3359-
debug@3.1.0:
3367+
debug@3.1.0, debug@=3.1.0:
33603368
version "3.1.0"
33613369
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
33623370
integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==
@@ -4380,6 +4388,13 @@ follow-redirects@^1.0.0:
43804388
dependencies:
43814389
debug "^3.1.0"
43824390

4391+
follow-redirects@^1.3.0:
4392+
version "1.6.1"
4393+
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.6.1.tgz#514973c44b5757368bad8bddfe52f81f015c94cb"
4394+
integrity sha512-t2JCjbzxQpWvbhts3l6SH1DKzSrx8a+SsaVf4h6bG4kOXUuPYS/kg2Lr4gQSb7eemaHqJkOThF1BGyjlUkO1GQ==
4395+
dependencies:
4396+
debug "=3.1.0"
4397+
43834398
for-in@^1.0.1, for-in@^1.0.2:
43844399
version "1.0.2"
43854400
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"

0 commit comments

Comments
 (0)