11name : Release
22
33on :
4- push :
5- tags :
6- - ' v*.*.*'
4+ pull_request :
5+ types : [closed]
6+ branches :
7+ - main
78
89permissions :
910 contents : write
10- pull-requests : write
1111
1212jobs :
1313 release :
14+ if : github.event.pull_request.merged == true
1415 runs-on : ubuntu-latest
1516
1617 steps :
@@ -26,57 +27,19 @@ jobs:
2627 - name : Install dependencies
2728 run : yarn install --frozen-lockfile
2829
29- - name : Configure Git
30+ - name : Extract version from package.json
31+ id : extract_version
3032 run : |
31- git config --global user.name 'github-actions'
32- git config --global user.email '[email protected] ' 33-
34- - name : Fetch all tags
35- run : git fetch --tags
36-
37- - name : Extract version and previous tag
38- id : extract_info
39- run : |
40- VERSION=${GITHUB_REF#refs/tags/v}
41- PREVIOUS_TAG=$(git describe --tags $(git rev-list --tags --skip=1 --max-count=1))
33+ VERSION=$(jq -r '.version' package.json)
4234 echo "VERSION=$VERSION" >> $GITHUB_ENV
43- echo "PREVIOUS_TAG=$PREVIOUS_TAG" >> $GITHUB_ENV
44-
45- - name : Determine update type
46- id : determine_update_type
47- run : |
48- IFS='.' read -r -a NEW_VERSION_PARTS <<< "${VERSION}"
49- IFS='.' read -r -a OLD_VERSION_PARTS <<< "${PREVIOUS_TAG#v}"
50-
51- if [ "${NEW_VERSION_PARTS[0]}" != "${OLD_VERSION_PARTS[0]}" ]; then
52- UPDATE_TYPE=major
53- elif [ "${NEW_VERSION_PARTS[1]}" != "${OLD_VERSION_PARTS[1]}" ]; then
54- UPDATE_TYPE=minor
55- else
56- UPDATE_TYPE=patch
57- fi
58- echo "UPDATE_TYPE=$UPDATE_TYPE" >> $GITHUB_ENV
5935
60- - name : Create and push new branch
36+ - name : Create Git tag
6137 run : |
62- NEW_BRANCH=release-v${VERSION}
63- git checkout -b ${NEW_BRANCH}
64- git push origin ${NEW_BRANCH}
65- echo "NEW_BRANCH=$NEW_BRANCH" >> $GITHUB_ENV
66-
67- - name : Update version in package.json
68- run : jq --arg new_version "$VERSION" '.version = $new_version' package.json > temp.json && mv temp.json package.json
38+ git tag -a "$VERSION" -m "Release $VERSION"
39+ git push origin "$VERSION"
6940
7041 - name : Build the package
7142 run : yarn build
7243
73- - name : Create Pull Request
74- uses : peter-evans/create-pull-request@v6
75- with :
76- token : ${{ secrets.GITHUB_TOKEN }}
77- commit-message : " Update version to ${{ env.VERSION }} [${{ env.UPDATE_TYPE }}] and upgrade dependencies"
78- branch : ${{ env.NEW_BRANCH }}
79- base : main
80- title : " Release ${{ env.VERSION }}"
81- body : " This PR updates the version to ${{ env.VERSION }} and upgrades dependencies."
82- labels : release
44+ - name : Notify release
45+ run : echo "Release ${{ env.VERSION }} has been successfully created."
0 commit comments