Create release PR #48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Create release PR | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "The new version number following semantic versioning convention. Example: v1.40.1" | |
| required: true | |
| type: string | |
| pattern: "^v[0-9]+\\.[0-9]+\\.[0-9]+$" | |
| jobs: | |
| init_release: | |
| name: 🚀 Create release PR | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # gives the changelog generator access to all previous commits | |
| # Go resolves a v2+ module only if go.mod carries the matching /vN suffix, so a major | |
| # release tagged before the module path is migrated is unusable (see v5.0.0). | |
| - name: Verify module path matches the requested major | |
| env: | |
| VERSION: ${{ github.event.inputs.version }} | |
| run: | | |
| requested="${VERSION#v}" | |
| requested="${requested%%.*}" | |
| module_path="$(sed -n 's/^module //p' go.mod)" | |
| case "$module_path" in | |
| */v[0-9]*) module_major="${module_path##*/v}" ;; | |
| *) module_major=1 ;; | |
| esac | |
| expected="$requested" | |
| [ "$expected" = "0" ] && expected=1 | |
| if [ "$module_major" != "$expected" ]; then | |
| echo "::error::go.mod declares '$module_path' (major v$module_major) but the release is $VERSION." | |
| echo "::error::Migrate go.mod and every self-import to .../v$requested first, then re-run this workflow." | |
| exit 1 | |
| fi | |
| - name: Update CHANGELOG.md and version.go, then push release branch | |
| env: | |
| VERSION: ${{ github.event.inputs.version }} | |
| run: | | |
| # Generate the changelog without creating a tag or commit | |
| npx --yes standard-version@9.3.2 --release-as "$VERSION" --skip.tag --skip.commit --tag-prefix=v | |
| # Update version in version.go | |
| sed -i "s/\(versionName = \)\"[^\"]*\"/\1\"$VERSION\"/" version.go | |
| # Stage the new or updated files | |
| git add CHANGELOG.md version.go | |
| # Set up Git configuration | |
| git config --global user.name 'github-actions' | |
| git config --global user.email 'release@getstream.io' | |
| # Create a release branch with the version and push it | |
| git checkout -q -b "release-$VERSION" | |
| git commit -am "chore(release): $VERSION" | |
| git push -q -u origin "release-$VERSION" | |
| - 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 | |
| $(cat CHANGELOG.md)" | |