-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (94 loc) · 4.42 KB
/
update-jar.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
name: update-jar-and-release
on:
schedule:
- cron: '0 5 * * *' # Run daily at 5 AM UTC
workflow_dispatch: # Allow manual triggers
jobs:
check-and-update-jar:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Fetch all history for all tags and branches
- name: Check for existing JAR and get current version
id: current-jar
run: |
mkdir -p jdiscordmusicbot
current_jar=$(ls jdiscordmusicbot/JMusicBot-*.jar 2>/dev/null | sort -V | tail -n 1 || echo "")
if [ -z "$current_jar" ]; then
echo "No existing JAR found."
echo "current_version=0.0.0" >> $GITHUB_OUTPUT
else
current_version=$(echo "$current_jar" | sed -n 's/.*JMusicBot-\(.*\)\.jar/\1/p')
echo "Current JAR version: $current_version"
echo "current_version=$current_version" >> $GITHUB_OUTPUT
fi
- name: Check for new MusicBot release
id: check-release
run: |
latest_release=$(curl -s https://api.github.com/repos/jagrosh/MusicBot/releases/latest | jq -r .tag_name)
echo "Latest release: $latest_release"
echo "new_version=$latest_release" >> $GITHUB_OUTPUT
- name: Update JAR file
id: update-jar
run: |
current_version="${{ steps.current-jar.outputs.current_version }}"
latest_version="${{ steps.check-release.outputs.new_version }}"
if [ "$latest_version" != "$current_version" ]; then
echo "New version available: $latest_version"
wget https://github.com/jagrosh/MusicBot/releases/download/$latest_version/JMusicBot-$latest_version.jar -O jdiscordmusicbot/JMusicBot-$latest_version.jar
git config user.name github-actions
git config user.email github-actions@github.com
git add jdiscordmusicbot/JMusicBot-$latest_version.jar
git commit -m "Add JMusicBot version $latest_version"
git push
echo "updated=true" >> $GITHUB_OUTPUT
echo "new_version=$latest_version" >> $GITHUB_OUTPUT
else
echo "No new version available. Current version is up to date."
echo "updated=false" >> $GITHUB_OUTPUT
fi
- name: Update variables.tf
if: steps.update-jar.outputs.updated == 'true'
run: |
if [ -f variables.tf ]; then
if grep -q "default\s*=\s*\"JMusicBot-${{ steps.check-release.outputs.new_version }}.jar\"" variables.tf; then
echo "variables.tf already contains the latest version. No update needed."
else
sed -i 's/default\s*=\s*"JMusicBot-.*\.jar"/default = "JMusicBot-${{ steps.check-release.outputs.new_version }}.jar"/' variables.tf
git config user.name github-actions
git config user.email github-actions@github.com
git add variables.tf
git commit -m "Update default JAR version in variables.tf"
git push
echo "variables.tf updated successfully."
fi
else
echo "variables.tf not found. Skipping update."
fi
- name: Exit if no new release found
if: steps.update-jar.outputs.updated == 'false'
run: |
echo "No new JMusicBot version found. Exiting workflow."
exit 0
- name: Get latest release version
id: get_latest_release
run: |
latest_release=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name || echo "v0.0.0")
latest_release=${latest_release#v} # Remove 'v' prefix if present
IFS='.' read -r -a version_parts <<< "$latest_release"
new_patch=$((version_parts[2] + 1))
new_version="${version_parts[0]}.${version_parts[1]}.$new_patch"
echo "new_version=$new_version" >> $GITHUB_OUTPUT
- name: Create Release
if: steps.update-jar.outputs.updated == 'true'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.get_latest_release.outputs.new_version }}
release_name: Release ${{ steps.get_latest_release.outputs.new_version }}
body: |
Updated to JMusicBot version ${{ steps.check-release.outputs.new_version }}
draft: false
prerelease: false