Check uMod Plugin Updates #75
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: Check uMod Plugin Updates | |
on: | |
schedule: | |
- cron: '10 */2 * * *' # Check every 2 hours at 10 minutes past the hour | |
workflow_dispatch: # Allow manual trigger | |
jobs: | |
check-and-release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Check for uMod Plugin Updates | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
PLUGIN_NAME="AutoPlant" | |
# Fetch current plugin file from uMod | |
curl -O "https://umod.org/plugins/${PLUGIN_NAME}.cs" | |
# Extract the version from the Info attribute in the file | |
plugin_version=$(sed -n 's/.*\[Info("[^"]*", "[^"]*", "\([^"]*\)".*/\1/p' ${PLUGIN_NAME}.cs) | |
echo "Plugin version in file: $plugin_version" | |
# Get latest GitHub release version | |
git fetch --tags | |
latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null || echo "v0.0.0") | |
current_version=${latest_tag#v} | |
echo "Latest GitHub release version: $current_version" | |
# Compare versions | |
echo "Current version in repo: $current_version" | |
echo "Latest version in plugin file: $plugin_version" | |
# Compare versions | |
if [ "$current_version" != "$plugin_version" ]; then | |
echo "New version found: $plugin_version" | |
# Commit and push new version | |
git config --global user.name "github-actions" | |
git config --global user.email "github-actions@github.com" | |
git add ${PLUGIN_NAME}.cs | |
git commit -m "v${plugin_version}" | |
git push | |
# Create GitHub release | |
gh release create "v${plugin_version}" ${PLUGIN_NAME}.cs \ | |
--title "${PLUGIN_NAME} v${plugin_version}" \ | |
--notes "Automatic release of new version from uMod." | |
else | |
echo "No new version" | |
fi |