update-jar-and-release #29
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: update-jar-and-release | |
on: | |
schedule: | |
- cron: '0 10 * * *' # Run daily at 5 AM EST | |
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: Get current version from variables.tf | |
id: current-version | |
run: | | |
current_version=$(grep 'default.*JMusicBot-' variables.tf | sed -n 's/.*JMusicBot-\(.*\)\.jar.*/\1/p') | |
echo "Current version in variables.tf: $current_version" | |
echo "current_version=$current_version" >> $GITHUB_OUTPUT | |
- 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-version.outputs.current_version }}" | |
latest_version="${{ steps.check-release.outputs.new_version }}" | |
if [ "$latest_version" != "$current_version" ]; then | |
echo "New version available: $latest_version" | |
# Update variables.tf | |
sed -i 's/default\s*=\s*"JMusicBot-.*\.jar"/default = "JMusicBot-'$latest_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 JMusicBot version to $latest_version in variables.tf" | |
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: 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 |