Release SDK #3
This file contains 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: 'Release SDK' | |
on: | |
workflow_dispatch: | |
inputs: | |
release_version: | |
type: choice | |
description: 'Select the version type to release' | |
required: true | |
default: patch | |
options: | |
- patch | |
- minor | |
- major | |
- beta | |
- alpha | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
jobs: | |
release: | |
uses: ./.github/workflows/ci.yml | |
bump-version: | |
runs-on: ubuntu-latest | |
needs: release | |
steps: | |
- name: Bump version | |
id: bump_version | |
run: | | |
# Define function to parse and bump version number | |
bump_version() { | |
if [[ "$1" == "beta" || "$1" == "alpha" ]]; then | |
main_version="${current_version%-*}" | |
prerelease_version="${current_version#*-}" | |
prerelease_identifier="${prerelease_version%[0-9]*}" | |
numeric_part="${prerelease_version#$prerelease_identifier}" | |
numeric_part=$(printf "%01d" $((10#$numeric_part + 1))) | |
echo "${main_version}-${prerelease_identifier}${numeric_part}" | |
else | |
echo "$1" | |
fi | |
} | |
# Fetch current version and determine new version | |
current_version=$(node -p "require('./package.json').version") | |
new_version=$(bump_version "${{ github.event.inputs.release_version }}") | |
# Bump package version and output new version | |
npm version "$new_version" --no-git-tag-version | |
echo "new_version=$new_version" >> $GITHUB_ENV | |
echo "new_branch=release/$new_version" >> $GITHUB_ENV | |
echo "Version bumped to $new_version" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create Release Branch | |
run: | | |
new_branch=$new_version | |
git checkout -b $new_branch | |
git push origin $new_branch | |
- name: Create Tag and Release | |
run: | | |
new_tag="v$new_version" | |
git tag $new_tag | |
git push origin $new_tag | |
gh release create $new_tag --title "Release $new_tag" --notes "Release notes for $new_tag" | |
- name: Publish Package | |
run: | | |
npm config set //registry.npmjs.org/:_authToken ${NODE_AUTH_TOKEN} | |
npm ci | |
npm run build | |
npm publish | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.PUBLISH_TOKEN }} | |
- name: Create Pull Request | |
run: | | |
gh pr create --title "Merge release $new_version into main" --body "This is an automated pull request to update the version." --base main --head $new_branch | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |