Check for New Release #467
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 for New Release | |
on: | |
schedule: | |
- cron: "0 0 * * *" # Run every day | |
workflow_dispatch: | |
jobs: | |
check-release: | |
runs-on: ubuntu-latest | |
permissions: write-all | |
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/repositories/358636775/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 [ "$LATEST_RELEASE" == "null" ]; then | |
echo "New release is null, skipping" | |
exit 1 | |
fi | |
if [ "$LATEST_RELEASE" != "$CURRENT_VERSION" ]; 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/AAnother-Plangothic-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/AAnother-Plangothic-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 |