Skip to content

Check for New Release #436

Check for New Release

Check for New Release #436

Workflow file for this run

name: Check for New Release
on:
schedule:
- cron: "0 0 * * *" # Run every day
workflow_dispatch:
jobs:
check-release:
permissions: write-all
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4 # Check out this repository
- name: Check for New Release
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
WORKFLOW_ID: main
run: |
echo "Checking for new releases..."
# Use curl to fetch release data from the other repository
LATEST_RELEASE=$(curl -s https://api.github.com/repos/Fitzgerald-Porthmouth-Koenigsegg/Plangothic-Project/releases/latest | jq -r '.tag_name')
# Read the current version from version.json
CURRENT_VERSION=$(cat version.json | jq -r '.version')
# Compare the latest release with the current version
if [ -n "$LATEST_RELEASE" ] && [ "$LATEST_RELEASE" != "$CURRENT_VERSION" ] && [ "$LATEST_RELEASE" != "null" ]; then
echo "New release found: $LATEST_RELEASE"
# Update version.json with the latest version and increment versionCode
NEW_VERSION_CODE=$(( $(cat version.json | jq -r '.versionCode') + 1 ))
ZIP_URL="https://github.com/lakejason0/Plangothic-with-notocjk-magisk-module/releases/download/$LATEST_RELEASE/Plangothic-magisk-module.zip"
NEW_CONTENT="{\"version\": \"$LATEST_RELEASE\", \"versionCode\": $NEW_VERSION_CODE, \"zipUrl\": \"$ZIP_URL\", \"changelog\": \"https://raw.githubusercontent.com/lakejason0/Plangothic-with-notocjk-magisk-module/main/extra/changelog.md\"}"
echo "$NEW_CONTENT" > version.json
sed -i "s/version=.*/version=$LATEST_RELEASE/" module.prop
sed -i "s/versionCode=.*/versionCode=$NEW_VERSION_CODE/" module.prop
cat extra/changelog_latest.md >> extra/changelog.md
printf "\n# $LATEST_RELEASE\nBump version to \`$LATEST_RELEASE\`.\n" > extra\changelog_latest.md
git config user.name "lakejason0"
git config user.email "36039861+lakejason0@users.noreply.github.com"
git commit -a -m "Bump version of Plangothic"
git tag $LATEST_RELEASE
git push origin $LATEST_RELEASE
git push
curl -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/workflows/${WORKFLOW_ID}/dispatches \
-d "{\"ref\":\"$LATEST_RELEASE\"}"
else
echo "No new release found."
fi