-
Notifications
You must be signed in to change notification settings - Fork 0
67 lines (55 loc) · 1.98 KB
/
version-manage.yml
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
name: Bump JSON Version and update Version file
on:
push:
branches:
- master
jobs:
bump-version:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Bump version in JSON
run: |
shell: bash
# Read the current version from the JSON file
VERSION=$(jq -r '.version' ./info.json)
echo "Current version: $VERSION"
# Bump the patch version
IFS='.' read -ra VER <<< "$VERSION"
echo "Current version parts: ${VER[0]}, ${VER[1]}, ${VER[2]}"
if ! [[ "${VER[2]}" =~ ^[0-9]+$ ]]; then
echo "Error: Patch version '${VER[2]}' is not a number."
exit 1
fi
((VER[2]++))
NEW_VERSION="${VER[0]}.${VER[1]}.${VER[2]}"
echo "New version: $NEW_VERSION"
# Update the JSON file with the new version
if ! jq --arg v "$NEW_VERSION" '.version = $v' ./info.json > temp.json; then
echo "Failed to update JSON file"
exit 1
fi
mv temp.json ./info.json
echo "New version saved"
# Write the new version to a separate file
echo $NEW_VERSION > ./ndr_core/VERSION
echo "Version file updated"
# Set up Git
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
# Add changes to staging
git add ./info.json ./ndr_core/VERSION
echo "Files added to Git staging"
# Check if there are changes to commit
git diff --cached --exit-code
if [ $? -ne 0 ]; then
# Commit and push the changes
git commit -m "Bump version to $NEW_VERSION"
echo "Commit made"
git push
echo "Changes pushed"
else
echo "No changes to commit."
exit 1
end