Skip to content

Commit d0cce8b

Browse files
authored
fix the github actions (#2185)
1 parent 2d72ccd commit d0cce8b

1 file changed

Lines changed: 36 additions & 8 deletions

File tree

.github/workflows/version-bump.yml

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,46 @@ on:
44
push:
55
branches: [main]
66

7+
permissions:
8+
contents: write
9+
710
jobs:
811
update-version:
12+
if: github.actor != 'github-actions[bot]'
913
runs-on: ubuntu-latest
1014

1115
steps:
1216
- name: Checkout code
13-
uses: actions/checkout@v2
14-
15-
- name: Bump
16-
uses: tool3/bump@master
17+
uses: actions/checkout@v4
1718
with:
18-
branch: main
19-
github_token: ${{ secrets.GITHUB_TOKEN }}
20-
user: 'github-actions[bot]'
21-
email: 'github-actions[bot]@users.noreply.github.com'
19+
fetch-depth: 0
20+
21+
- name: Bump package version and tag
22+
shell: bash
23+
run: |
24+
set -euo pipefail
25+
26+
git config user.name "github-actions[bot]"
27+
git config user.email "github-actions[bot]@users.noreply.github.com"
28+
git fetch --tags
29+
30+
current_version="$(node -p "require('./package.json').version")"
31+
latest_tag="$(git tag -l 'v[0-9]*.[0-9]*.[0-9]*' --sort=-v:refname | head -n1 || true)"
32+
latest_tag_version="${latest_tag#v}"
33+
34+
if [[ -z "${latest_tag_version}" || "${latest_tag_version}" == "${latest_tag}" ]]; then
35+
base_version="${current_version}"
36+
else
37+
highest_version="$(printf '%s\n%s\n' "${current_version}" "${latest_tag_version}" | sort -V | tail -n1)"
38+
base_version="${highest_version}"
39+
fi
40+
41+
IFS='.' read -r major minor patch <<< "${base_version}"
42+
next_version="${major}.${minor}.$((patch + 1))"
43+
next_tag="v${next_version}"
44+
45+
npm version "${next_version}" --no-git-tag-version
46+
git add package.json
47+
git commit -m "Bump version to ${next_tag}"
48+
git tag "${next_tag}"
49+
git push origin main --follow-tags

0 commit comments

Comments
 (0)