Skip to content

Commit

Permalink
feat: add automated release flow (#866)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdeme authored Jan 19, 2022
1 parent f1552ab commit 9b81974
Show file tree
Hide file tree
Showing 15 changed files with 1,442 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .commitlintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
};
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/dist
/node_modules
/test
scripts/get_changelog_diff.js
*.md
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @mahboubii @gumuz @AnatolyRugalev @vishalnarkhede
* @peterdeme @ferhatelmas @gumuz @AnatolyRugalev @vishalnarkhede
69 changes: 69 additions & 0 deletions .github/workflows/initiate_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Create release PR

on:
workflow_dispatch:
inputs:
version:
description: "The new version number with 'v' prefix. Example: v1.40.1"
required: true

jobs:
init_release:
name: 🚀 Create release PR
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # gives the changelog generator access to all previous commits

- name: Get current tag
id: previoustag
uses: WyriHaximus/github-action-get-previous-tag@v1

- name: Ensure version number higher than current
uses: actions/github-script@v5
env:
PREVIOUS_TAG: ${{ steps.previoustag.outputs.tag }}
DESTINATION_TAG: ${{ github.event.inputs.version }}
with:
script: |
const { PREVIOUS_TAG, DESTINATION_TAG } = process.env;
const result = DESTINATION_TAG.localeCompare(PREVIOUS_TAG, undefined, { numeric: true, sensitivity: 'base' })
if (result != 1) {
throw new Error('The new version number must be greater than the previous one.')
}
- name: Restore dependencies
uses: ./.github/actions/setup-node

- name: Update CHANGELOG.md, package.json and push release branch
uses: actions/github-script@v5
env:
VERSION: ${{ github.event.inputs.version }}
run: |
npm run changelog
git config --global user.name 'github-actions'
git config --global user.email 'release@getstream.io'
git checkout -q -b "release-$VERSION"
git commit -am "chore(release): $VERSION"
git push -q -u origin "release-$VERSION"
- name: Get changelog diff
uses: actions/github-script@v5
with:
script: |
const get_change_log_diff = require('./scripts/get_changelog_diff.js')
core.exportVariable('CHANGELOG', get_change_log_diff())
- name: Open pull request
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr create \
-t "Release ${{ github.event.inputs.version }}" \
-b "# :rocket: ${{ github.event.inputs.version }}
Make sure to use squash & merge when merging!
Once this is merged, another job will kick off automatically and publish the package.
# :memo: Changelog
${{ env.CHANGELOG }}"
9 changes: 9 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
name: Lint
on: [pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: ./.github/actions/setup-node

- name: Commit message lint
run: echo "${{ github.event.pull_request.title }}" | yarn commitlinter

- name: Lint
run: yarn lint
42 changes: 42 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Release

on:
pull_request:
types: [closed]
branches:
- master

jobs:
Release:
name: 🚀 Release
if: github.event.pull_request.merged && startsWith(github.head_ref, 'release-')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- uses: actions/github-script@v5
with:
script: |
const get_change_log_diff = require('./scripts/get_changelog_diff.js')
core.exportVariable('CHANGELOG', get_change_log_diff())
// Getting the release version from the PR source branch
// Source branch looks like this: release-1.0.0
const version = context.payload.pull_request.head.ref.split('-')[1]
core.exportVariable('VERSION', version)
- uses: ./.github/actions/setup-node

- name: Publish package
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Create release on GitHub
uses: ncipollo/release-action@v1
with:
body: ${{ env.CHANGELOG }}
tag: ${{ env.VERSION }}
token: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions .github/workflows/size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
- 'test/**'
- '**.md'

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/type.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Type Test
on: [pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/unit.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Unit Test
on: [pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
Expand Down
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# CHANGELOG
# Changelog

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.

### [5.1.2](https://github.com/GetStream/stream-chat-js/compare/v5.1.1...v5.1.2) (2022-01-13)

- Types: Fix some missing attributes by @mahboubii in #857
- Chore: Break CI into multiple workflow by @mahboubii in #858
- Fix: FormData accepts browser Blob by @mahboubii in #856
- Fix: Don't add messages from shadow banned users to state by @madsroskar in #859
- Types: Image attachment's dimensions by @vishalnarkhede in #861

## September 15, 2021 - 4.2.0

Expand Down
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,26 @@ client.connectUser({ id: 'testId', nickname: 'testUser', country: 'NL' }, 'TestT
- [Logging](docs/logging.md)
- [User Token](docs/userToken.md)

## Publishing a new version
## Contributing

Note that you need 2FA enabled on NPM, publishing with Yarn gives error, use NPM directly for this:
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.

```bash
npm version patch|minor|major
```
### Commit message convention

## Contributing
Since we're autogenerating our [CHANGELOG](./CHANGELOG.md), we need to follow a specific commit message convention.
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`.

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.
## Release (for Stream developers)

Releasing this package involves two GitHub Action steps:

- Kick off a job called `initiate_release` ([link](https://github.com/GetStream/stream-chat-js/actions/workflows/initiate_release.yml)).

The job creates a pull request with the changelog. Check if it looks good.

- Merge the pull request.

Once the PR is merged, it automatically kicks off another job which will create the tag and created a GitHub release.

## We are hiring

Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
"@babel/preset-env": "^7.16.4",
"@babel/preset-typescript": "^7.16.0",
"@babel/register": "^7.16.0",
"@commitlint/cli": "^16.0.2",
"@commitlint/config-conventional": "^16.0.0",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-node-resolve": "^11.2.0",
Expand Down Expand Up @@ -99,12 +101,15 @@
"rollup-plugin-replace": "^2.1.0",
"rollup-plugin-terser": "^7.0.2",
"sinon": "^12.0.1",
"standard-version": "^9.3.2",
"typescript": "^4.2.3",
"uuid": "^8.3.2"
},
"scripts": {
"start": "yarn run compile -w",
"compile": "rollup -c",
"changelog": "standard-version --release-as $VERSION --skip.tag --skip.commit --tag-prefix=v",
"commitlinter": "commitlint",
"build": "rm -rf dist && yarn run types && yarn run compile",
"types": "tsc --emitDeclarationOnly true",
"prettier": "prettier --check '**/*.{js,ts,md,css,scss,json}' .eslintrc.json .prettierrc .babelrc",
Expand Down
26 changes: 26 additions & 0 deletions scripts/get_changelog_diff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Here we're trying to parse the latest changes from CHANGELOG.md file.
The changelog looks like this:
## 0.0.3
- Something #3
## 0.0.2
- Something #2
## 0.0.1
- Something #1
In this case we're trying to extract "- Something #3" since that's the latest change.
*/
module.exports = () => {
const fs = require('fs');

changelog = fs.readFileSync('CHANGELOG.md', 'utf8');
releases = changelog.match(/## [?[0-9](.+)/g);

current_release = changelog.indexOf(releases[0]);
previous_release = changelog.indexOf(releases[1]);

latest_changes = changelog.substr(current_release, previous_release - current_release);

return latest_changes;
};
2 changes: 1 addition & 1 deletion test/typescript/response-generators/moderation.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async function deletePermission() {
},
},
});
await sleep(2500);
await sleep(5000);
return await authClient.deletePermission('test-delete-permission');
}

Expand Down
Loading

0 comments on commit 9b81974

Please sign in to comment.