@@ -36,75 +36,25 @@ jobs:
3636
3737 - name : Get the latest tag
3838 id : get_tag
39- run : |
40- latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null)
41- if [ -z "$latest_tag" ]; then
42- latest_tag="v0.0.0"
43- fi
44- echo "latest_tag=$latest_tag" >> $GITHUB_ENV
39+ run : bash .github/scripts/get-latest-tag.sh
4540
4641 - name : Check for [skip] in PR title
4742 id : check_skip
48- run : |
49- pr_title="${{ github.event.pull_request.title }}"
50-
51- if [[ "$pr_title" == "[Skip]"* ]]; then
52- echo "skip=true" >> $GITHUB_ENV
53- else
54- echo "skip=false" >> $GITHUB_ENV
55- fi
43+ run : bash .github/scripts/check-skip.sh "${{ github.event.pull_request.title }}"
5644
5745 - name : Determine version increment
5846 if : env.skip == 'false'
5947 id : determine_increment
60- run : |
61- pr_title="${{ github.event.pull_request.title }}"
62- latest_tag=${{ env.latest_tag }}
63-
64- # Extract major, minor, and patch components from the latest tag
65- major=$(echo $latest_tag | cut -d. -f1 | sed 's/v//')
66- minor=$(echo $latest_tag | cut -d. -f2)
67- patch=$(echo $latest_tag | cut -d. -f3)
68-
69- # Determine the increment type based on PR title
70- if [[ "$pr_title" == "[Major]"* ]]; then
71- major=$((major + 1))
72- minor=0
73- patch=0
74- elif [[ "$pr_title" == "[Minor]"* ]]; then
75- minor=$((minor + 1))
76- patch=0
77- elif [[ "$pr_title" == "[Patch]"* ]]; then
78- patch=$((patch + 1))
79- else
80- echo "PR title must start with [Major], [Minor], or [Patch]."
81- exit 1
82- fi
83-
84- # Construct the new tag
85- new_tag="v${major}.${minor}.${patch}"
86- echo "new_tag=$new_tag" >> $GITHUB_ENV
87-
88- - name : Configure Git User
89- if : env.skip == 'false'
90- run : |
91- git config user.name "github-actions[bot]"
92- git config user.email "github-actions[bot]@users.noreply.github.com"
48+ run : bash .github/scripts/verify-pr-title.sh "${{ github.event.pull_request.title }}" "${{ env.latest_tag }}"
9349
9450 - name : Check if tag exists on remote
9551 id : check_tag
96- run : |
97- if git rev-parse "refs/tags/${{ env.new_tag }}" >/dev/null 2>&1; then
98- echo "Tag ${{ env.new_tag }} already exists."
99- exit 0
100- fi
52+ run : bash .github/scripts/check-tag-exists.sh "${{ env.new_tag }}"
10153
10254 - name : Create new tag
10355 if : env.skip == 'false' && steps.check_tag.outcome == 'success'
10456 id : create_tag
105- run : |
106- git tag ${{ env.new_tag }}
107- git push origin ${{ env.new_tag }}
57+ run : bash .github/scripts/create-tag.sh "${{ env.new_tag }}"
10858
10959 - name : Create GitHub Release
11060 if : env.skip == 'false' && steps.create_tag.outcome == 'success'
@@ -131,20 +81,11 @@ jobs:
13181
13282 - name : Set up .npmrc
13383 if : env.skip == 'false'
134- run : |
135- echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_PUBLISH_KEY }}" > ~/.npmrc
136- echo "registry=https://registry.npmjs.org/" >> ~/.npmrc
84+ run : bash .github/scripts/setup-npmrc.sh "${{ secrets.NPM_PUBLISH_KEY }}"
13785
13886 - name : Create temp_package
13987 if : env.skip == 'false'
140- run : |
141- mkdir temp_package
142- cp -r dist/. temp_package/ # Copy all contents of dist, including hidden files
143- cp package.json temp_package/
144- cp README.md temp_package/
145- cp LICENSE temp_package/
146- cd temp_package
147- npm pack # Create a tarball from the contents
88+ run : bash .github/scripts/create-package.sh
14889
14990 - name : Publish to NPM
15091 if : env.skip == 'false'
@@ -172,29 +113,10 @@ jobs:
172113 with :
173114 name : failed-tag
174115
175- - name : Configure Git User
176- run : |
177- git config user.name "github-actions[bot]"
178- git config user.email "github-actions[bot]@users.noreply.github.com"
179-
180- - name : Delete Git Tag
181- run : |
182- tag=$(cat failed-tag)
183- git tag -d $tag
184- git push origin :refs/tags/$tag
185- env :
186- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
187-
188- - name : Delete GitHub Release
116+ - name : Delete release and tag
189117 run : |
190118 tag=$(cat failed-tag)
191- release_id=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
192- -H "Accept: application/vnd.github.v3+json" \
193- "https://api.github.com/repos/${{ github.repository }}/releases/tags/$tag" \
194- | jq -r '.id')
195- curl -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
196- -H "Accept: application/vnd.github.v3+json" \
197- "https://api.github.com/repos/${{ github.repository }}/releases/$release_id"
119+ bash .github/scripts/delete-release.sh "$tag" "${{ secrets.GITHUB_TOKEN }}" "${{ github.repository }}"
198120 env :
199121 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
200122
0 commit comments