-
Notifications
You must be signed in to change notification settings - Fork 0
53 lines (48 loc) · 2.06 KB
/
update-script-version.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
name: Bump Script Version
on:
push:
pull_request:
jobs:
update_version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
# Check if main.py has been modified since the last commit
- name: Update Script Version
id: update-script
env:
GIT_AUTH: ${{ secrets.GIT_AUTH }}
run: |
if ! git diff HEAD~1 --name-only | grep -q "main.py"; then
echo "No changes to main.py since last commit"
exit 0
else
echo "main.py file has been modified"
# Get the previous SCRIPT_VERSION from the last commit
PREVIOUS_SCRIPT_VERSION=$(git show HEAD~:main.py | grep "SCRIPT_VERSION = " | cut -d "=" -f 2 | tr -d " '\"")
# Get the current SCRIPT_VERSION from main.py
SCRIPT_VERSION=$(grep "SCRIPT_VERSION = " main.py | cut -d '"' -f 2)
# Check if the SCRIPT_VERSION has been manually updated
if [[ "$SCRIPT_VERSION" != "$PREVIOUS_SCRIPT_VERSION" ]]; then
echo "SCRIPT_VERSION has been manually updated"
exit 0
else
echo 'SCRIPT_VERSION has NOT been manually updated'
# Increment the SCRIPT_VERSION by 0.1
NEW_SCRIPT_VERSION=$(awk -v prev="$SCRIPT_VERSION" 'BEGIN { printf "%.1f", prev+0.1 }')
# Update the SCRIPT_VERSION in main.py
sed -i "s/SCRIPT_VERSION = \"$SCRIPT_VERSION\"/SCRIPT_VERSION = \"$NEW_SCRIPT_VERSION\"/" main.py
if [[ $(git status) == *"nothing to commit, working tree clean"* ]]; then
echo "Nothing to commit, working tree clean"
exit 0
fi
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git remote set-url origin https://${{ secrets.GIT_AUTH }}@github.com/origamiofficial/rclone-http-updater.git
git add main.py
git commit -m "Bump Script Version"
git push
fi
fi