-
Notifications
You must be signed in to change notification settings - Fork 2
86 lines (74 loc) · 2.67 KB
/
release_sdk.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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 }}