Skip to content

Commit 9b81974

Browse files
authored
feat: add automated release flow (#866)
1 parent f1552ab commit 9b81974

15 files changed

+1442
-32
lines changed

.commitlintrc.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ['@commitlint/config-conventional'],
3+
};

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/dist
22
/node_modules
33
/test
4+
scripts/get_changelog_diff.js
45
*.md

.github/CODEOWNERS

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @mahboubii @gumuz @AnatolyRugalev @vishalnarkhede
1+
* @peterdeme @ferhatelmas @gumuz @AnatolyRugalev @vishalnarkhede
+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Create release PR
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "The new version number with 'v' prefix. Example: v1.40.1"
8+
required: true
9+
10+
jobs:
11+
init_release:
12+
name: 🚀 Create release PR
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
with:
17+
fetch-depth: 0 # gives the changelog generator access to all previous commits
18+
19+
- name: Get current tag
20+
id: previoustag
21+
uses: WyriHaximus/github-action-get-previous-tag@v1
22+
23+
- name: Ensure version number higher than current
24+
uses: actions/github-script@v5
25+
env:
26+
PREVIOUS_TAG: ${{ steps.previoustag.outputs.tag }}
27+
DESTINATION_TAG: ${{ github.event.inputs.version }}
28+
with:
29+
script: |
30+
const { PREVIOUS_TAG, DESTINATION_TAG } = process.env;
31+
const result = DESTINATION_TAG.localeCompare(PREVIOUS_TAG, undefined, { numeric: true, sensitivity: 'base' })
32+
33+
if (result != 1) {
34+
throw new Error('The new version number must be greater than the previous one.')
35+
}
36+
37+
- name: Restore dependencies
38+
uses: ./.github/actions/setup-node
39+
40+
- name: Update CHANGELOG.md, package.json and push release branch
41+
uses: actions/github-script@v5
42+
env:
43+
VERSION: ${{ github.event.inputs.version }}
44+
run: |
45+
npm run changelog
46+
git config --global user.name 'github-actions'
47+
git config --global user.email '[email protected]'
48+
git checkout -q -b "release-$VERSION"
49+
git commit -am "chore(release): $VERSION"
50+
git push -q -u origin "release-$VERSION"
51+
52+
- name: Get changelog diff
53+
uses: actions/github-script@v5
54+
with:
55+
script: |
56+
const get_change_log_diff = require('./scripts/get_changelog_diff.js')
57+
core.exportVariable('CHANGELOG', get_change_log_diff())
58+
59+
- name: Open pull request
60+
env:
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
run: |
63+
gh pr create \
64+
-t "Release ${{ github.event.inputs.version }}" \
65+
-b "# :rocket: ${{ github.event.inputs.version }}
66+
Make sure to use squash & merge when merging!
67+
Once this is merged, another job will kick off automatically and publish the package.
68+
# :memo: Changelog
69+
${{ env.CHANGELOG }}"

.github/workflows/lint.yml

+9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
name: Lint
22
on: [pull_request]
33

4+
concurrency:
5+
group: ${{ github.workflow }}-${{ github.head_ref }}
6+
cancel-in-progress: true
7+
48
jobs:
59
lint:
610
runs-on: ubuntu-latest
711
steps:
812
- uses: actions/checkout@v2
13+
914
- uses: ./.github/actions/setup-node
15+
16+
- name: Commit message lint
17+
run: echo "${{ github.event.pull_request.title }}" | yarn commitlinter
18+
1019
- name: Lint
1120
run: yarn lint

.github/workflows/release.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Release
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- master
8+
9+
jobs:
10+
Release:
11+
name: 🚀 Release
12+
if: github.event.pull_request.merged && startsWith(github.head_ref, 'release-')
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
with:
17+
fetch-depth: 0
18+
19+
- uses: actions/github-script@v5
20+
with:
21+
script: |
22+
const get_change_log_diff = require('./scripts/get_changelog_diff.js')
23+
core.exportVariable('CHANGELOG', get_change_log_diff())
24+
25+
// Getting the release version from the PR source branch
26+
// Source branch looks like this: release-1.0.0
27+
const version = context.payload.pull_request.head.ref.split('-')[1]
28+
core.exportVariable('VERSION', version)
29+
30+
- uses: ./.github/actions/setup-node
31+
32+
- name: Publish package
33+
run: npm publish
34+
env:
35+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
36+
37+
- name: Create release on GitHub
38+
uses: ncipollo/release-action@v1
39+
with:
40+
body: ${{ env.CHANGELOG }}
41+
tag: ${{ env.VERSION }}
42+
token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/size.yml

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on:
66
- 'test/**'
77
- '**.md'
88

9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.head_ref }}
11+
cancel-in-progress: true
12+
913
jobs:
1014
build:
1115
runs-on: ubuntu-latest

.github/workflows/type.yml

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: Type Test
22
on: [pull_request]
33

4+
concurrency:
5+
group: ${{ github.workflow }}-${{ github.head_ref }}
6+
cancel-in-progress: true
7+
48
jobs:
59
test:
610
runs-on: ubuntu-latest

.github/workflows/unit.yml

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: Unit Test
22
on: [pull_request]
33

4+
concurrency:
5+
group: ${{ github.workflow }}-${{ github.head_ref }}
6+
cancel-in-progress: true
7+
48
jobs:
59
test:
610
runs-on: ubuntu-latest

CHANGELOG.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
# CHANGELOG
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4+
5+
### [5.1.2](https://github.com/GetStream/stream-chat-js/compare/v5.1.1...v5.1.2) (2022-01-13)
6+
7+
- Types: Fix some missing attributes by @mahboubii in #857
8+
- Chore: Break CI into multiple workflow by @mahboubii in #858
9+
- Fix: FormData accepts browser Blob by @mahboubii in #856
10+
- Fix: Don't add messages from shadow banned users to state by @madsroskar in #859
11+
- Types: Image attachment's dimensions by @vishalnarkhede in #861
212

313
## September 15, 2021 - 4.2.0
414

README.md

+16-7
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,26 @@ client.connectUser({ id: 'testId', nickname: 'testUser', country: 'NL' }, 'TestT
145145
- [Logging](docs/logging.md)
146146
- [User Token](docs/userToken.md)
147147

148-
## Publishing a new version
148+
## Contributing
149149

150-
Note that you need 2FA enabled on NPM, publishing with Yarn gives error, use NPM directly for this:
150+
We welcome code changes that improve this library or fix a problem, please make sure to follow all best practices and add tests if applicable before submitting a Pull Request on Github. We are very happy to merge your code in the official repository. Make sure to sign our [Contributor License Agreement (CLA)](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) first. See our license file for more details.
151151

152-
```bash
153-
npm version patch|minor|major
154-
```
152+
### Commit message convention
155153

156-
## Contributing
154+
Since we're autogenerating our [CHANGELOG](./CHANGELOG.md), we need to follow a specific commit message convention.
155+
You can read about conventional commits [here](https://www.conventionalcommits.org/). Here's how a usual commit message looks like for a new feature: `feat: allow provided config object to extend other configs`. A bugfix: `fix: prevent racing of requests`.
157156

158-
We welcome code changes that improve this library or fix a problem, please make sure to follow all best practices and add tests if applicable before submitting a Pull Request on Github. We are very happy to merge your code in the official repository. Make sure to sign our [Contributor License Agreement (CLA)](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) first. See our license file for more details.
157+
## Release (for Stream developers)
158+
159+
Releasing this package involves two GitHub Action steps:
160+
161+
- Kick off a job called `initiate_release` ([link](https://github.com/GetStream/stream-chat-js/actions/workflows/initiate_release.yml)).
162+
163+
The job creates a pull request with the changelog. Check if it looks good.
164+
165+
- Merge the pull request.
166+
167+
Once the PR is merged, it automatically kicks off another job which will create the tag and created a GitHub release.
159168

160169
## We are hiring
161170

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
"@babel/preset-env": "^7.16.4",
5858
"@babel/preset-typescript": "^7.16.0",
5959
"@babel/register": "^7.16.0",
60+
"@commitlint/cli": "^16.0.2",
61+
"@commitlint/config-conventional": "^16.0.0",
6062
"@rollup/plugin-babel": "^5.3.0",
6163
"@rollup/plugin-commonjs": "^17.1.0",
6264
"@rollup/plugin-node-resolve": "^11.2.0",
@@ -99,12 +101,15 @@
99101
"rollup-plugin-replace": "^2.1.0",
100102
"rollup-plugin-terser": "^7.0.2",
101103
"sinon": "^12.0.1",
104+
"standard-version": "^9.3.2",
102105
"typescript": "^4.2.3",
103106
"uuid": "^8.3.2"
104107
},
105108
"scripts": {
106109
"start": "yarn run compile -w",
107110
"compile": "rollup -c",
111+
"changelog": "standard-version --release-as $VERSION --skip.tag --skip.commit --tag-prefix=v",
112+
"commitlinter": "commitlint",
108113
"build": "rm -rf dist && yarn run types && yarn run compile",
109114
"types": "tsc --emitDeclarationOnly true",
110115
"prettier": "prettier --check '**/*.{js,ts,md,css,scss,json}' .eslintrc.json .prettierrc .babelrc",

scripts/get_changelog_diff.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Here we're trying to parse the latest changes from CHANGELOG.md file.
3+
The changelog looks like this:
4+
5+
## 0.0.3
6+
- Something #3
7+
## 0.0.2
8+
- Something #2
9+
## 0.0.1
10+
- Something #1
11+
12+
In this case we're trying to extract "- Something #3" since that's the latest change.
13+
*/
14+
module.exports = () => {
15+
const fs = require('fs');
16+
17+
changelog = fs.readFileSync('CHANGELOG.md', 'utf8');
18+
releases = changelog.match(/## [?[0-9](.+)/g);
19+
20+
current_release = changelog.indexOf(releases[0]);
21+
previous_release = changelog.indexOf(releases[1]);
22+
23+
latest_changes = changelog.substr(current_release, previous_release - current_release);
24+
25+
return latest_changes;
26+
};

test/typescript/response-generators/moderation.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ async function deletePermission() {
9393
},
9494
},
9595
});
96-
await sleep(2500);
96+
await sleep(5000);
9797
return await authClient.deletePermission('test-delete-permission');
9898
}
9999

0 commit comments

Comments
 (0)