-
Notifications
You must be signed in to change notification settings - Fork 515
49 lines (39 loc) · 1.48 KB
/
version-bump.yml
File metadata and controls
49 lines (39 loc) · 1.48 KB
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
name: Bump package.json version
on:
push:
branches: [main]
permissions:
contents: write
jobs:
update-version:
if: github.actor != 'github-actions[bot]'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Bump package version and tag
shell: bash
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git fetch --tags
current_version="$(node -p "require('./package.json').version")"
latest_tag="$(git tag -l 'v[0-9]*.[0-9]*.[0-9]*' --sort=-v:refname | head -n1 || true)"
latest_tag_version="${latest_tag#v}"
if [[ -z "${latest_tag_version}" || "${latest_tag_version}" == "${latest_tag}" ]]; then
base_version="${current_version}"
else
highest_version="$(printf '%s\n%s\n' "${current_version}" "${latest_tag_version}" | sort -V | tail -n1)"
base_version="${highest_version}"
fi
IFS='.' read -r major minor patch <<< "${base_version}"
next_version="${major}.${minor}.$((patch + 1))"
next_tag="v${next_version}"
npm version "${next_version}" --no-git-tag-version
git add package.json
git commit -m "Bump version to ${next_tag}"
git tag "${next_tag}"
git push origin main --follow-tags