Skip to content

Commit c76c8f5

Browse files
authored
ci: add release flow (#167)
1 parent 0a1a824 commit c76c8f5

File tree

8 files changed

+158
-3
lines changed

8 files changed

+158
-3
lines changed

Diff for: .github/CODEOWNERS

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @mahboubii @yaziine
1+
* @ferhatelmas @yaziine

Diff for: .github/workflows/go.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ concurrency:
1111

1212
jobs:
1313
test-build:
14-
name: Test & Build
14+
name: 👷 Test & Build
1515
runs-on: ubuntu-latest
1616
strategy:
1717
max-parallel: 1

Diff for: .github/workflows/initiate_release.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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: Update CHANGELOG.md, version.go and push release branch
20+
env:
21+
VERSION: ${{ github.event.inputs.version }}
22+
run: |
23+
npx --yes [email protected] --release-as "$VERSION" --skip.tag --skip.commit --tag-prefix=v
24+
git config --global user.name 'github-actions'
25+
git config --global user.email '[email protected]'
26+
git checkout -q -b "release-$VERSION"
27+
git commit -am "chore(release): $VERSION"
28+
git push -q -u origin "release-$VERSION"
29+
30+
- name: Get changelog diff
31+
uses: actions/github-script@v5
32+
with:
33+
script: |
34+
const get_change_log_diff = require('./scripts/get_changelog_diff.js')
35+
core.exportVariable('CHANGELOG', get_change_log_diff())
36+
37+
- name: Open pull request
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
run: |
41+
gh pr create \
42+
-t "Release ${{ github.event.inputs.version }}" \
43+
-b "# :rocket: ${{ github.event.inputs.version }}
44+
Make sure to use squash & merge when merging!
45+
Once this is merged, another job will kick off automatically and publish the package.
46+
# :memo: Changelog
47+
${{ env.CHANGELOG }}"

Diff for: .github/workflows/lint.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ concurrency:
88

99
jobs:
1010
lint:
11-
name: Lint
11+
name: 👮 Lint
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Checkout
1515
uses: actions/checkout@v2
1616
with:
1717
fetch-depth: 0
1818

19+
- name: Commit message linter
20+
uses: wagoid/commitlint-github-action@v4
21+
1922
- name: Setup Go
2023
uses: actions/setup-go@v2
2124
with:

Diff for: .github/workflows/release.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
- name: Create release on GitHub
31+
uses: ncipollo/release-action@v1
32+
with:
33+
body: ${{ env.CHANGELOG }}
34+
tag: ${{ env.VERSION }}
35+
token: ${{ secrets.GITHUB_TOKEN }}

Diff for: .versionrc.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const versionFileUpdater = {
2+
MAJOR_REGEX: /versionMajor = (\d+)/,
3+
MINOR_REGEX: /versionMinor = (\d+)/,
4+
PATCH_REGEX: /versionPatch = (\d+)/,
5+
6+
readVersion: function (contents) {
7+
const major = this.MAJOR_REGEX.exec(contents)[1];
8+
const minor = this.MINOR_REGEX.exec(contents)[1];
9+
const patch = this.PATCH_REGEX.exec(contents)[1];
10+
11+
return `${major}.${minor}.${patch}`;
12+
},
13+
14+
writeVersion: function (contents, version) {
15+
const splitted = version.split('.');
16+
const [major, minor, patch] = [splitted[0], splitted[1], splitted[2]];
17+
18+
return contents
19+
.replace(this.MAJOR_REGEX.exec(contents)[0], `versionMajor = ${major}`)
20+
.replace(this.MINOR_REGEX.exec(contents)[0], `versionMinor = ${minor}`)
21+
.replace(this.PATCH_REGEX.exec(contents)[0], `versionPatch = ${patch}`);
22+
}
23+
}
24+
25+
module.exports = {
26+
bumpFiles: [{ filename: './version.go', updater: versionFileUpdater }],
27+
}

Diff for: CONTRIBUTING.md

+17
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,20 @@ We enforce code formatting with [`gufumpt`](https://github.com/mvdan/gofumpt) (a
2424
```
2525

2626
Gofumpt will mostly take care of your linting issues as well.
27+
28+
## Commit message convention
29+
30+
Since we're autogenerating our [CHANGELOG](./CHANGELOG.md), we need to follow a specific commit message convention.
31+
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`.
32+
33+
## Release (for Stream developers)
34+
35+
Releasing this package involves two GitHub Action steps:
36+
37+
- Kick off a job called `initiate_release` ([link](https://github.com/GetStream/stream-chat-go/actions/workflows/initiate_release.yml)).
38+
39+
The job creates a pull request with the changelog. Check if it looks good.
40+
41+
- Merge the pull request.
42+
43+
Once the PR is merged, it automatically kicks off another job which will create the tag and created a GitHub release.

Diff for: 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+
}

0 commit comments

Comments
 (0)