zx-bulk-release 1.0.0
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/.github/workflows/ci.yml +120 -0
- package/.github/workflows/codeql-analysis.yml +70 -0
- package/CHANGELOG.md +17 -0
- package/LICENSE +21 -0
- package/README.md +38 -0
- package/package.json +30 -0
- package/src/main/js/analyzer.js +65 -0
- package/src/main/js/cli.js +3 -0
- package/src/main/js/deps.js +46 -0
- package/src/main/js/index.js +35 -0
- package/src/main/js/publish.js +89 -0
- package/src/main/js/tag.js +89 -0
- package/src/test/fixtures/regular-monorepo/.editorconfig +10 -0
- package/src/test/fixtures/regular-monorepo/.pnp.cjs +9597 -0
- package/src/test/fixtures/regular-monorepo/.yarn/install-state.gz +0 -0
- package/src/test/fixtures/regular-monorepo/.yarn/releases/yarn-4.0.0-rc.9.cjs +781 -0
- package/src/test/fixtures/regular-monorepo/.yarnrc.yml +1 -0
- package/src/test/fixtures/regular-monorepo/package.json +8 -0
- package/src/test/fixtures/regular-monorepo/packages/a/package.json +3 -0
- package/src/test/fixtures/regular-monorepo/packages/b/package.json +6 -0
- package/src/test/fixtures/regular-monorepo/packages/c/package.json +7 -0
- package/src/test/fixtures/regular-monorepo/packages/d/package.json +6 -0
- package/src/test/fixtures/regular-monorepo/packages/package.json +3 -0
- package/src/test/fixtures/regular-monorepo/yarn.lock +42 -0
- package/src/test/js/deps.test.js +33 -0
- package/src/test/js/index.test.js +115 -0
- package/src/test/js/integration.test.js +125 -0
- package/src/test/js/tag.test.js +160 -0
- package/src/test/js/test-utils.js +53 -0
- package/src/test/js/topo.test.js +18 -0
- package/verdaccio.config.yaml +193 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# This is a Github Workflow that runs tests on any push or pull request.
|
|
2
|
+
# If the tests pass and this is a push to the master branch it also runs Semantic Release.
|
|
3
|
+
name: CI
|
|
4
|
+
on: [push, pull_request]
|
|
5
|
+
jobs:
|
|
6
|
+
init:
|
|
7
|
+
name: init
|
|
8
|
+
runs-on: ubuntu-20.04
|
|
9
|
+
outputs:
|
|
10
|
+
skip: ${{ steps.ci-skip-step.outputs.ci-skip }}
|
|
11
|
+
skip-not: ${{ steps.ci-skip-step.outputs.ci-skip-not }}
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v3
|
|
14
|
+
- id: ci-skip-step
|
|
15
|
+
uses: mstachniuk/ci-skip@v1
|
|
16
|
+
|
|
17
|
+
test_push:
|
|
18
|
+
name: Test on push
|
|
19
|
+
needs: init
|
|
20
|
+
if: ${{ needs.init.outputs.skip == 'false' && github.event_name == 'push' }}
|
|
21
|
+
runs-on: ubuntu-20.04
|
|
22
|
+
steps:
|
|
23
|
+
- name: Checkout
|
|
24
|
+
uses: actions/checkout@v3
|
|
25
|
+
|
|
26
|
+
- name: Setup Node.js
|
|
27
|
+
uses: actions/setup-node@v3
|
|
28
|
+
with:
|
|
29
|
+
node-version: 18
|
|
30
|
+
|
|
31
|
+
- name: Install deps
|
|
32
|
+
run: yarn install
|
|
33
|
+
|
|
34
|
+
- name: Run tests
|
|
35
|
+
timeout-minutes: 2
|
|
36
|
+
run: yarn test
|
|
37
|
+
|
|
38
|
+
test_pr:
|
|
39
|
+
if: ${{ needs.init.outputs.skip == 'false' && github.event_name == 'pull_request' }}
|
|
40
|
+
needs: init
|
|
41
|
+
name: Test PR (Node v${{ matrix.node-version }}, OS ${{ matrix.os }})
|
|
42
|
+
strategy:
|
|
43
|
+
matrix:
|
|
44
|
+
os: [ ubuntu-20.04 ]
|
|
45
|
+
node-version: [ 16, 18 ]
|
|
46
|
+
|
|
47
|
+
runs-on: ${{ matrix.os }}
|
|
48
|
+
steps:
|
|
49
|
+
- name: Checkout
|
|
50
|
+
uses: actions/checkout@v3
|
|
51
|
+
|
|
52
|
+
- name: Setup Node.js
|
|
53
|
+
uses: actions/setup-node@v3
|
|
54
|
+
with:
|
|
55
|
+
node-version: ${{ matrix.node-version }}
|
|
56
|
+
|
|
57
|
+
- name: Install deps
|
|
58
|
+
run: yarn install
|
|
59
|
+
|
|
60
|
+
- name: Run tests
|
|
61
|
+
timeout-minutes: 2
|
|
62
|
+
run: yarn test
|
|
63
|
+
|
|
64
|
+
release:
|
|
65
|
+
name: Release
|
|
66
|
+
# https://github.community/t/trigger-job-on-tag-push-only/18076
|
|
67
|
+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
|
|
68
|
+
needs: test_push
|
|
69
|
+
runs-on: ubuntu-20.04
|
|
70
|
+
permissions:
|
|
71
|
+
checks: read
|
|
72
|
+
statuses: write
|
|
73
|
+
contents: write
|
|
74
|
+
packages: write
|
|
75
|
+
steps:
|
|
76
|
+
- name: Checkout
|
|
77
|
+
uses: actions/checkout@v3
|
|
78
|
+
with:
|
|
79
|
+
fetch-depth: 0
|
|
80
|
+
ref: master
|
|
81
|
+
|
|
82
|
+
- name: Setup Node.js
|
|
83
|
+
uses: actions/setup-node@v3
|
|
84
|
+
with:
|
|
85
|
+
node-version: 18
|
|
86
|
+
|
|
87
|
+
- name: Install deps
|
|
88
|
+
run: yarn install
|
|
89
|
+
|
|
90
|
+
- name: Create .npmrc
|
|
91
|
+
env:
|
|
92
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
93
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
94
|
+
VERDACCIO_TOKEN: ${{ secrets.VERDACCIO_TOKEN }}
|
|
95
|
+
run: |
|
|
96
|
+
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
|
|
97
|
+
echo "//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}" >> .npmrc
|
|
98
|
+
|
|
99
|
+
- name: Run tests
|
|
100
|
+
timeout-minutes: 2
|
|
101
|
+
run: yarn test
|
|
102
|
+
|
|
103
|
+
- name: Docs
|
|
104
|
+
run: yarn docs
|
|
105
|
+
|
|
106
|
+
# - name: Codeclimate
|
|
107
|
+
# uses: paambaati/codeclimate-action@v3.0.0
|
|
108
|
+
# env:
|
|
109
|
+
# CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
|
110
|
+
# with:
|
|
111
|
+
# coverageLocations: |
|
|
112
|
+
# ${{github.workspace}}/coverage/*.lcov:lcov
|
|
113
|
+
|
|
114
|
+
- name: Release
|
|
115
|
+
env:
|
|
116
|
+
VERBOSE: ${{ secrets.VERBOSE }}
|
|
117
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
118
|
+
GIT_COMMITTER_NAME: ${{ secrets.GIT_COMMITTER_NAME }}
|
|
119
|
+
GIT_COMMITTER_EMAIL: ${{ secrets.GIT_COMMITTER_EMAIL }}
|
|
120
|
+
run: npm_config_yes=true npx zx-semrel
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# For most projects, this workflow file will not need changing; you simply need
|
|
2
|
+
# to commit it to your repository.
|
|
3
|
+
#
|
|
4
|
+
# You may wish to alter this file to override the set of languages analyzed,
|
|
5
|
+
# or to provide custom queries or build logic.
|
|
6
|
+
#
|
|
7
|
+
# ******** NOTE ********
|
|
8
|
+
# We have attempted to detect the languages in your repository. Please check
|
|
9
|
+
# the `language` matrix defined below to confirm you have the correct set of
|
|
10
|
+
# supported CodeQL languages.
|
|
11
|
+
#
|
|
12
|
+
name: "CodeQL"
|
|
13
|
+
|
|
14
|
+
on:
|
|
15
|
+
push:
|
|
16
|
+
branches: [ master ]
|
|
17
|
+
pull_request:
|
|
18
|
+
# The branches below must be a subset of the branches above
|
|
19
|
+
branches: [ master ]
|
|
20
|
+
schedule:
|
|
21
|
+
- cron: '26 11 * * 4'
|
|
22
|
+
|
|
23
|
+
jobs:
|
|
24
|
+
analyze:
|
|
25
|
+
name: Analyze
|
|
26
|
+
runs-on: ubuntu-latest
|
|
27
|
+
permissions:
|
|
28
|
+
actions: read
|
|
29
|
+
contents: read
|
|
30
|
+
security-events: write
|
|
31
|
+
|
|
32
|
+
strategy:
|
|
33
|
+
fail-fast: false
|
|
34
|
+
matrix:
|
|
35
|
+
language: [ 'javascript' ]
|
|
36
|
+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
|
37
|
+
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
|
38
|
+
|
|
39
|
+
steps:
|
|
40
|
+
- name: Checkout repository
|
|
41
|
+
uses: actions/checkout@v3
|
|
42
|
+
|
|
43
|
+
# Initializes the CodeQL tools for scanning.
|
|
44
|
+
- name: Initialize CodeQL
|
|
45
|
+
uses: github/codeql-action/init@v2
|
|
46
|
+
with:
|
|
47
|
+
languages: ${{ matrix.language }}
|
|
48
|
+
# If you wish to specify custom queries, you can do so here or in a config file.
|
|
49
|
+
# By default, queries listed here will override any specified in a config file.
|
|
50
|
+
# Prefix the list here with "+" to use these queries and those in the config file.
|
|
51
|
+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
|
52
|
+
|
|
53
|
+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
|
54
|
+
# If this step fails, then you should remove it and run the build manually (see below)
|
|
55
|
+
- name: Autobuild
|
|
56
|
+
uses: github/codeql-action/autobuild@v2
|
|
57
|
+
|
|
58
|
+
# ℹ️ Command-line programs to run using the OS shell.
|
|
59
|
+
# 📚 https://git.io/JvXDl
|
|
60
|
+
|
|
61
|
+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
|
62
|
+
# and modify them (or add more) to build your code if your project
|
|
63
|
+
# uses a compiled language
|
|
64
|
+
|
|
65
|
+
#- run: |
|
|
66
|
+
# make bootstrap
|
|
67
|
+
# make release
|
|
68
|
+
|
|
69
|
+
- name: Perform CodeQL Analysis
|
|
70
|
+
uses: github/codeql-action/analyze@v2
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
## [1.0.0](https://github.com/semrel-extra/zx-bulk-release/compare/undefined...v1.0.0) (2022-06-17)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
* feat: handle `workspace:` prefix ([d916069](https://github.com/semrel-extra/zx-bulk-release/commit/d9160696d5beefaf4c11ad27ffdb3675e9125273))
|
|
5
|
+
* feat: add artifact push ([4852e90](https://github.com/semrel-extra/zx-bulk-release/commit/4852e903f7515a13516eae7a8c44e2458113b382))
|
|
6
|
+
* feat: add tag on publish ([dc9af36](https://github.com/semrel-extra/zx-bulk-release/commit/dc9af3634bed102912ef98e3e98fabbc6f1966b7))
|
|
7
|
+
* feat: add metabranch api ([b4c9562](https://github.com/semrel-extra/zx-bulk-release/commit/b4c95622cf5aa3aecf5853a1a266933c2dcddf14))
|
|
8
|
+
* feat: add deps updater ([21e7fa6](https://github.com/semrel-extra/zx-bulk-release/commit/21e7fa60f49910aa65940007e2ba2c05f0b305e9))
|
|
9
|
+
* feat: add tag parser/formatter ([1cee4e6](https://github.com/semrel-extra/zx-bulk-release/commit/1cee4e6f3680711a5eb079f0695c794297f0900f))
|
|
10
|
+
* feat: add pkg commits extractor ([5c4dde2](https://github.com/semrel-extra/zx-bulk-release/commit/5c4dde206123f55f75c15b65d992e61e2ee73204))
|
|
11
|
+
|
|
12
|
+
### Fixes & improvements
|
|
13
|
+
* refactor: separate publish utils ([48d756b](https://github.com/semrel-extra/zx-bulk-release/commit/48d756badf57012b7ae97ae8f4bd4ccbc0dd473d))
|
|
14
|
+
* docs: add refs ([c937fce](https://github.com/semrel-extra/zx-bulk-release/commit/c937fce4472f68c5d8e92e8970a15fca017dc656))
|
|
15
|
+
* docs: add basic description ([bb4d0f4](https://github.com/semrel-extra/zx-bulk-release/commit/bb4d0f4e33cfae78868400e8bf17f488d5d4a2de))
|
|
16
|
+
|
|
17
|
+
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 semrel-extra
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# zx-bulk-release
|
|
2
|
+
> [zx](https://github.com/google/zx)-based alternative for [multi-semantic-release](https://github.com/dhoulb/multi-semantic-release)
|
|
3
|
+
|
|
4
|
+
## Usage
|
|
5
|
+
```shell
|
|
6
|
+
GH_TOKEN=foo NPM_TOKEN=bar npx zx-bulk-release [opts]
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
or just copy-paste, tweak a bit and run with [zx-extra](https://github.com/qiwi/zx-extra):
|
|
10
|
+
```shell
|
|
11
|
+
GH_TOKEN=foo NPM_TOKEN=bar zx-extra zx-bulk-release.mjs
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Roadmap
|
|
15
|
+
* [x] [Semantic commits](https://www.conventionalcommits.org/en/v1.0.0/#specification) trigger releases.
|
|
16
|
+
* [x] Predictable [toposort](https://githib.com/semrel-extra/topo)-driven flow.
|
|
17
|
+
* [x] No blocking (no release commits).
|
|
18
|
+
* [ ] Changelogs, docs, bundles go to: release assets and/or meta branch.
|
|
19
|
+
* [ ] No extra builds. Required deps are fetched from registry / meta branch / release assets.
|
|
20
|
+
|
|
21
|
+
## Tags
|
|
22
|
+
[Lerna](https://github.com/lerna/lerna) tags (like `@pkg/name@v1.0.0-beta.0`) are suitable for monorepos, but they don’t follow [semver spec](https://semver.org/). Therefore, we propose another contract:
|
|
23
|
+
```js
|
|
24
|
+
'2022.6.13-optional-org.pkg-name.v1.0.0-beta.1+sha.1-f0'
|
|
25
|
+
// date name version format
|
|
26
|
+
```
|
|
27
|
+
Note, [npm-package-name charset](https://www.npmjs.com/package/validate-npm-package-name) is wider than [semver](https://semver.org/spec/v2.0.0.html#spec-item-4), so we need a pinch of [base64url magic](https://stackoverflow.com/questions/55389211/string-based-data-encoding-base64-vs-base64url).
|
|
28
|
+
|
|
29
|
+
## References
|
|
30
|
+
* [semrel-extra/zx-semrel](https://github.com/semrel-extra/zx-semrel)
|
|
31
|
+
* [dhoulb/multi-semantic-release](https://github.com/dhoulb/multi-semantic-release)
|
|
32
|
+
* [semantic-release/semantic-release](https://github.com/semantic-release/semantic-release)
|
|
33
|
+
* [tophat/monodeploy](https://github.com/tophat/monodeploy)
|
|
34
|
+
* [conventional-changelog/releaser-tools](https://github.com/conventional-changelog/releaser-tools)
|
|
35
|
+
* [pmowrer/semantic-release-monorepo](https://github.com/pmowrer/semantic-release-monorepo)
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
[MIT](./LICENSE)
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "zx-bulk-release",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "zx-based alternative for multi-semantic-release",
|
|
5
|
+
"exports": "./src/main/js/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "NPM_REGISTRY='http://localhost:4873' NPM_TOKEN='mRv6eIuiaggXGb9ZDFCtBA==' c8 uvu ./src/test -i fixtures -i utils && c8 report -r lcov",
|
|
9
|
+
"docs": "mkdir -p docs && cp ./README.md ./docs/README.md"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@semrel-extra/topo": "^1.4.1",
|
|
13
|
+
"git-glob-cp": "^1.5.1",
|
|
14
|
+
"zx-extra": "^1.7.0"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"c8": "^7.11.3",
|
|
18
|
+
"uvu": "^0.5.3",
|
|
19
|
+
"verdaccio": "^5.13.0"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/semrel-extra/zx-bulk-release.git"
|
|
27
|
+
},
|
|
28
|
+
"author": "Anton Golub <antongolub@antongolub.com>",
|
|
29
|
+
"license": "MIT"
|
|
30
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {ctx, semver} from 'zx-extra'
|
|
2
|
+
|
|
3
|
+
const releaseSeverityOrder = ['major', 'minor', 'patch']
|
|
4
|
+
const semanticRules = [
|
|
5
|
+
{group: 'Features', releaseType: 'minor', prefixes: ['feat']},
|
|
6
|
+
{group: 'Fixes & improvements', releaseType: 'patch', prefixes: ['fix', 'perf', 'refactor', 'docs']},
|
|
7
|
+
{group: 'BREAKING CHANGES', releaseType: 'major', keywords: ['BREAKING CHANGE', 'BREAKING CHANGES']},
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
export const getPkgCommits = async (cwd, since) => ctx(async ($) => {
|
|
11
|
+
$.cwd = cwd
|
|
12
|
+
|
|
13
|
+
const range = since ? `${since}..HEAD` : 'HEAD'
|
|
14
|
+
|
|
15
|
+
return (await $.raw`git log ${range} --format=+++%s__%b__%h__%H -- .`)
|
|
16
|
+
.toString()
|
|
17
|
+
.split('+++')
|
|
18
|
+
.filter(Boolean)
|
|
19
|
+
.map(msg => {
|
|
20
|
+
const [subj, body, short, hash] = msg.split('__').map(raw => raw.trim())
|
|
21
|
+
return {subj, body, short, hash}
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
export const getSemanticChanges = async (cwd, since) => {
|
|
26
|
+
const commits = await getPkgCommits(cwd, since)
|
|
27
|
+
const semanticChanges = commits
|
|
28
|
+
.reduce((acc, {subj, body, short, hash}) => {
|
|
29
|
+
semanticRules.forEach(({group, releaseType, prefixes, keywords}) => {
|
|
30
|
+
const prefixMatcher = prefixes && new RegExp(`^(${prefixes.join('|')})(\\(\\w+\\))?:\\s.+$`)
|
|
31
|
+
const keywordsMatcher = keywords && new RegExp(`(${keywords.join('|')}):\\s(.+)`)
|
|
32
|
+
const change = subj.match(prefixMatcher)?.[0] || body.match(keywordsMatcher)?.[2]
|
|
33
|
+
|
|
34
|
+
if (change) {
|
|
35
|
+
acc.push({
|
|
36
|
+
group,
|
|
37
|
+
releaseType,
|
|
38
|
+
change,
|
|
39
|
+
subj,
|
|
40
|
+
body,
|
|
41
|
+
short,
|
|
42
|
+
hash
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
return acc
|
|
47
|
+
}, [])
|
|
48
|
+
|
|
49
|
+
return semanticChanges
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const getNextReleaseType = (changes) => releaseSeverityOrder.find(type => changes.find(({releaseType}) => type === releaseType))
|
|
53
|
+
|
|
54
|
+
export const getNextVersion = (changes, prevVersion) => {
|
|
55
|
+
if (!prevVersion) return '1.0.0'
|
|
56
|
+
|
|
57
|
+
const releaseType = getNextReleaseType(changes)
|
|
58
|
+
|
|
59
|
+
return semver.inc(prevVersion, releaseType)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const resolvePkgVersion = (changes, prevVersion) =>
|
|
63
|
+
changes.length > 0
|
|
64
|
+
? getNextVersion(changes, prevVersion)
|
|
65
|
+
: prevVersion || null
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {semver} from 'zx-extra'
|
|
2
|
+
|
|
3
|
+
export const depScopes = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']
|
|
4
|
+
|
|
5
|
+
export const updateDeps = async (pkg, packages) => {
|
|
6
|
+
const {manifest} = pkg
|
|
7
|
+
const changes = []
|
|
8
|
+
|
|
9
|
+
for (let scope of depScopes) {
|
|
10
|
+
const deps = manifest[scope]
|
|
11
|
+
if (!deps) continue
|
|
12
|
+
|
|
13
|
+
for (let [name, version] of Object.entries(deps)) {
|
|
14
|
+
const next = resolveVersion(version, packages[name]?.version, pkg.latest.manifest?.[scope]?.[name])
|
|
15
|
+
if (!next) continue
|
|
16
|
+
|
|
17
|
+
deps[name] = next
|
|
18
|
+
|
|
19
|
+
changes.push({
|
|
20
|
+
group: 'Dependencies',
|
|
21
|
+
releaseType: 'patch',
|
|
22
|
+
change: 'perf',
|
|
23
|
+
subj: `perf: ${name} updated to ${next}`,
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return changes
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const resolveVersion = (decl, actual, prev) => {
|
|
32
|
+
if (!decl) return null
|
|
33
|
+
|
|
34
|
+
// https://yarnpkg.com/features/workspaces
|
|
35
|
+
if (decl.startsWith('workspace:')) {
|
|
36
|
+
const [, range, caret] = /^workspace:(([\^~*])?.*)$/.exec(decl)
|
|
37
|
+
|
|
38
|
+
decl = caret === range
|
|
39
|
+
? caret === '*' ? actual : caret + actual
|
|
40
|
+
: range
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!semver.satisfies(actual, decl)) return actual === prev ? null : actual
|
|
44
|
+
|
|
45
|
+
return decl === prev ? null : decl
|
|
46
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {fs} from 'zx-extra'
|
|
2
|
+
import {updateDeps} from './deps.js'
|
|
3
|
+
import {getSemanticChanges, resolvePkgVersion} from './analyzer.js'
|
|
4
|
+
import { topo } from '@semrel-extra/topo'
|
|
5
|
+
|
|
6
|
+
import {publish, getLatest} from './publish.js'
|
|
7
|
+
import {formatTag} from './tag.js'
|
|
8
|
+
|
|
9
|
+
export {parseTag, formatTag, getTags} from './tag.js'
|
|
10
|
+
|
|
11
|
+
export { topo }
|
|
12
|
+
|
|
13
|
+
export const run = async ({cwd = process.cwd(), env = process.env} = {}) => {
|
|
14
|
+
const {packages, queue} = await topo({cwd})
|
|
15
|
+
|
|
16
|
+
for (let name of queue) {
|
|
17
|
+
const pkg = packages[name]
|
|
18
|
+
pkg.latest = await getLatest(cwd, name)
|
|
19
|
+
|
|
20
|
+
const semanticChanges = await getSemanticChanges(pkg.absPath, pkg.latest.tag?.ref)
|
|
21
|
+
const depsChanges = await updateDeps(pkg, packages)
|
|
22
|
+
const changes = [...semanticChanges, ...depsChanges]
|
|
23
|
+
|
|
24
|
+
pkg.version = resolvePkgVersion(changes, pkg.latest.tag?.version || pkg.manifest.version)
|
|
25
|
+
pkg.manifest.version = pkg.version
|
|
26
|
+
|
|
27
|
+
if (changes.length === 0) continue
|
|
28
|
+
|
|
29
|
+
console.log(`semantic changes of '${name}'`, changes)
|
|
30
|
+
|
|
31
|
+
await fs.writeJson(pkg.manifestPath, pkg.manifest, {spaces: 2})
|
|
32
|
+
|
|
33
|
+
await publish(pkg, env)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {formatTag, getLatestTag} from './tag.js'
|
|
2
|
+
import {tempy, ctx, fs, path, $} from 'zx-extra'
|
|
3
|
+
import {copydir} from 'git-glob-cp'
|
|
4
|
+
|
|
5
|
+
const branches = {}
|
|
6
|
+
|
|
7
|
+
export const fetch = async ({cwd: _cwd, branch, origin: _origin}) => ctx(async ($) => {
|
|
8
|
+
let cwd = branches[branch]
|
|
9
|
+
if (cwd) return cwd
|
|
10
|
+
|
|
11
|
+
$.cwd = _cwd
|
|
12
|
+
const origin = _origin || (await $`git remote get-url origin`).toString().trim()
|
|
13
|
+
|
|
14
|
+
cwd = tempy.temporaryDirectory()
|
|
15
|
+
$.cwd = cwd
|
|
16
|
+
try {
|
|
17
|
+
await $`git clone --single-branch --branch ${branch} --depth 1 ${origin} .`
|
|
18
|
+
} catch {
|
|
19
|
+
await $`git init .`
|
|
20
|
+
await $`git remote add origin ${origin}`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
branches[branch] = cwd
|
|
24
|
+
|
|
25
|
+
return cwd
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
export const push = async ({cwd, from, to, branch, origin, msg, ignoreFiles}) => ctx(async ($) => {
|
|
29
|
+
const _cwd = await fetch({cwd, branch, origin})
|
|
30
|
+
await copydir({baseFrom: cwd, from, baseTo: _cwd, to})
|
|
31
|
+
|
|
32
|
+
$.cwd = _cwd
|
|
33
|
+
|
|
34
|
+
await $`git config user.name ${$.env.GIT_COMMITTER_NAME || 'Semrel Extra Bot'}`
|
|
35
|
+
await $`git config user.email ${$.env.GIT_COMMITTER_EMAIL || 'semrel-extra-bot@hotmail.com'}`
|
|
36
|
+
await $`git add .`
|
|
37
|
+
await $`git commit -m ${msg}`
|
|
38
|
+
await $.raw`git push origin HEAD:refs/heads/${branch}`
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
export const publish = async (pkg, env) => ctx(async ($) => {
|
|
42
|
+
const {name, version, files} = pkg.manifest
|
|
43
|
+
const cwd = pkg.absPath
|
|
44
|
+
$.cwd = cwd
|
|
45
|
+
$.env = env
|
|
46
|
+
|
|
47
|
+
const tag = formatTag({name, version})
|
|
48
|
+
const from = files ? [...files, 'package.json'] : ['!node_modules', '*']
|
|
49
|
+
const to = getArtifactPath(tag)
|
|
50
|
+
|
|
51
|
+
console.log(`push release tag ${tag}`)
|
|
52
|
+
await $`git config user.name ${$.env.GIT_COMMITTER_NAME || 'Semrel Extra Bot'}`
|
|
53
|
+
await $`git config user.email ${$.env.GIT_COMMITTER_EMAIL || 'semrel-extra-bot@hotmail.com'}`
|
|
54
|
+
await $`git tag -m ${tag} ${tag}`
|
|
55
|
+
await $`git push origin ${tag}`
|
|
56
|
+
|
|
57
|
+
console.log('push artifact to branch `meta`')
|
|
58
|
+
await push({cwd, from, to, branch: 'meta', msg: `chore: publish artifact ${name} ${version}`, ignoreFiles: '.npmignore'})
|
|
59
|
+
|
|
60
|
+
const registry = env.NPM_REGISTRY || 'https://registry.npmjs.org'
|
|
61
|
+
const npmrc = path.resolve(cwd, '.npmrc')
|
|
62
|
+
console.log(`publish npm package to ${registry}`)
|
|
63
|
+
|
|
64
|
+
await $.raw`echo ${registry.replace(/https?:/, '')}/:_authToken=${$.env.NPM_TOKEN} >> ${npmrc}`
|
|
65
|
+
await $`npm publish --no-git-tag-version --registry=${registry} --userconfig ${npmrc} --no-workspaces`
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
export const getArtifactPath = (tag) => tag.toLowerCase().replace(/[^a-z0-9-]/g, '-')
|
|
69
|
+
|
|
70
|
+
export const getLatestManifest = async (cwd, tag) => {
|
|
71
|
+
if (!tag) return null
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
const meta = await fetch({cwd, branch: 'meta'})
|
|
75
|
+
return await fs.readJson(path.resolve(meta, getArtifactPath(tag), 'package.json'))
|
|
76
|
+
} catch {}
|
|
77
|
+
|
|
78
|
+
return null
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const getLatest = async (cwd, name) => {
|
|
82
|
+
const tag = await getLatestTag(cwd, name)
|
|
83
|
+
const manifest = await getLatestManifest(cwd, tag?.ref)
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
tag,
|
|
87
|
+
manifest
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Semantic tags
|
|
2
|
+
|
|
3
|
+
import {ctx, semver} from 'zx-extra'
|
|
4
|
+
import {Buffer} from 'buffer'
|
|
5
|
+
|
|
6
|
+
const f0 = {
|
|
7
|
+
parse(tag) {
|
|
8
|
+
if (!tag.endsWith('-f0')) return null
|
|
9
|
+
|
|
10
|
+
const pattern = /^(\d{4}\.(?:[1-9]|1[012])\.(?:0[1-9]|[12]\d|30|31))-((?:[a-z0-9-]+\.)?[a-z0-9-]+)\.(v?\d+\.\d+\.\d+.*)-f0$/
|
|
11
|
+
const matched = pattern.exec(tag)
|
|
12
|
+
const [, _date, _name, version] = matched || []
|
|
13
|
+
|
|
14
|
+
if (!semver.valid(version)) return null
|
|
15
|
+
|
|
16
|
+
const date = parseDateTag(_date)
|
|
17
|
+
const name = _name.includes('.') ? `@${_name.replace('.', '/')}` : _name
|
|
18
|
+
|
|
19
|
+
return {date, name, version, format: 'f0', ref: tag}
|
|
20
|
+
},
|
|
21
|
+
format({name, date = new Date(), version}) {
|
|
22
|
+
if (!/^(@?[a-z0-9-]+\/)?[a-z0-9-]+$/.test(name) || !semver.valid(version)) return null
|
|
23
|
+
|
|
24
|
+
const d = formatDateTag(date)
|
|
25
|
+
const n = name.replace('@', '').replace('/', '.')
|
|
26
|
+
|
|
27
|
+
return `${d}-${n}.${version}-f0`
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const f1 = {
|
|
32
|
+
parse(tag) {
|
|
33
|
+
if (!tag.endsWith('-f1')) return null
|
|
34
|
+
|
|
35
|
+
const pattern = /^(\d{4}\.(?:[1-9]|1[012])\.(?:0[1-9]|[12]\d|30|31))-[a-z0-9-]+\.(v?\d+\.\d+\.\d+.*)\.([^.]+)-f1$/
|
|
36
|
+
const matched = pattern.exec(tag)
|
|
37
|
+
const [, _date, version, b64] = matched || []
|
|
38
|
+
|
|
39
|
+
if (!semver.valid(version)) return null
|
|
40
|
+
|
|
41
|
+
const date = parseDateTag(_date)
|
|
42
|
+
const name = Buffer.from(b64, 'base64url').toString('utf8')
|
|
43
|
+
|
|
44
|
+
return {date, name, version, format: 'f1', ref: tag}
|
|
45
|
+
},
|
|
46
|
+
format({name, date = new Date(), version}) {
|
|
47
|
+
if (!semver.valid(version)) return null
|
|
48
|
+
|
|
49
|
+
const b64 = Buffer.from(name).toString('base64url')
|
|
50
|
+
const d = formatDateTag(date)
|
|
51
|
+
const n = name.replace(/[^a-z0-9-]/ig, '')
|
|
52
|
+
|
|
53
|
+
return `${d}-${n}.${version}.${b64}-f1`
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// TODO
|
|
58
|
+
// const variants = [f0, f1]
|
|
59
|
+
// export const parseTag = (tag) => {
|
|
60
|
+
// for (const variant of variants) {
|
|
61
|
+
// const parsed = variant.parse(tag)
|
|
62
|
+
// if (parsed) return parsed
|
|
63
|
+
// }
|
|
64
|
+
//
|
|
65
|
+
// return null
|
|
66
|
+
// }
|
|
67
|
+
|
|
68
|
+
export const parseTag = (tag) => f0.parse(tag) || f1.parse(tag) || null
|
|
69
|
+
|
|
70
|
+
export const formatTag = (tag) => f0.format(tag) || f1.format(tag) || null
|
|
71
|
+
|
|
72
|
+
export const getTags = (cwd) => ctx(async ($) => {
|
|
73
|
+
$.cwd = cwd
|
|
74
|
+
|
|
75
|
+
return (await $`git tag -l --sort=-v:refname`).toString()
|
|
76
|
+
.split('\n')
|
|
77
|
+
.map(tag => parseTag(tag.trim()))
|
|
78
|
+
.filter(Boolean)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
export const getLatestTag = async (cwd, name) =>
|
|
82
|
+
(await getTags(cwd)).find(tag => tag.name === name) || null
|
|
83
|
+
|
|
84
|
+
export const getLatestTaggedVersion = async (cwd, name) =>
|
|
85
|
+
(await getLatestTag(cwd, name))?.version || null
|
|
86
|
+
|
|
87
|
+
export const formatDateTag = (date = new Date()) => `${date.getUTCFullYear()}.${date.getUTCMonth() + 1}.${date.getUTCDate()}`
|
|
88
|
+
|
|
89
|
+
export const parseDateTag = (date) => new Date(date.replaceAll('.', '-')+'Z')
|