Skip to content

Commit

Permalink
ci: fix release flow (#75)
Browse files Browse the repository at this point in the history
Co-authored-by: peterdeme <peter.deme@getstream.io>
  • Loading branch information
peterdeme and peterdeme committed Dec 6, 2021
1 parent cb4ae54 commit 74cf9f9
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 46 deletions.
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Expand Up @@ -5,5 +5,6 @@
- [ ] I have signed the [Stream CLA](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) (required).
- [ ] The code changes follow best practices
- [ ] Code changes are tested (add some information if not applicable)
- [ ] Commit message fits [conventional commits](https://www.conventionalcommits.org). Important for [CHANGELOG](./../CHANGELOG.md) generation.

## Description of the pull request
38 changes: 38 additions & 0 deletions .github/workflows/initiate_release.yml
@@ -0,0 +1,38 @@
name: Create release PR

on:
workflow_dispatch:
inputs:
version:
description: 'The new version number. Example: 1.40.1'
required: true

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

- name: Create release branch
run: scripts/create_release_branch.sh "${{ github.event.inputs.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 }}"
41 changes: 22 additions & 19 deletions .github/workflows/release.yaml
@@ -1,23 +1,30 @@
name: Release

on:
workflow_dispatch:
inputs:
version:
description: 'The new version number. Example: 1.40.1'
required: true
push:
branches:
- master

jobs:
release:
Release:
if: "${{ startsWith(github.event.head_commit.message, 'chore(release)') }}"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # gives standard-version access to all previous commits

- name: Update version number in files
run: scripts/prepare_release.sh "${{ github.event.inputs.version }}"

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 commit message
// Commit message looks like this: chore(release): 1.0.0
const version = context.payload.head_commit.message.split(' ')[1]
core.exportVariable('VERSION', version)
- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
Expand All @@ -33,12 +40,8 @@ jobs:
run: dotnet nuget push "./src/stream-chat-net/bin/Release/*.nupkg" -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }}

- name: Create release on GitHub
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: ncipollo/release-action@v1
with:
tag_name: ${{ github.event.inputs.version }}
release_name: ${{ github.event.inputs.version }}

- name: Push back changes to master
run: git push
body: ${{ env.CHANGELOG }}
tag: ${{ env.VERSION }}
token: ${{ secrets.GITHUB_TOKEN }}
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -282,6 +282,12 @@ if (complete)
}
```

## Contributing

## Contributing

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.
## We are hiring!

We've recently closed a [$38 million Series B funding round](https://techcrunch.com/2021/03/04/stream-raises-38m-as-its-chat-and-activity-feed-apis-power-communications-for-1b-users/) and we keep actively growing.
Expand Down
24 changes: 24 additions & 0 deletions scripts/create_release_branch.sh
@@ -0,0 +1,24 @@
#!/bin/bash

VERSION=$1
echo "Preparing release $VERSION"

# Update .csproj file
# This regex switches all occurences of >0.21.0< to >0.22.0<
# So <PackageVersion>0.21.0</PackageVersion> becomes <PackageVersion>0.22.0</PackageVersion>
sed -i -r "s/>[0-9]+\.[0-9]+\.[0-9]+</>$VERSION</g" src/stream-chat-net/stream-chat-net.csproj

# Create changelog
# --skip.commit: We manually commit the changes
# --skip-tag: tagging will done by the GitHub release step, so skip it here
# --tag-prefix: by default it tries to compare v0.1.0 to v0.2.0. Since we do not prefix our tags with 'v'
# we set it to an empty string
npx --yes standard-version@9.3.2 --release-as "$VERSION" --skip.tag --skip.commit --tag-prefix=

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"

echo "Done!"
26 changes: 26 additions & 0 deletions scripts/get_changelog_diff.js
@@ -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
}
27 changes: 0 additions & 27 deletions scripts/prepare_release.sh

This file was deleted.

0 comments on commit 74cf9f9

Please sign in to comment.