Skip to content

Update Detector #555

Update Detector

Update Detector #555

name: Update Detector
on:
schedule:
- cron: '0 */2 * * *'
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
check_for_updates:
runs-on: ubuntu-latest
name: Check for updates
steps:
- name: Check out the repository
uses: actions/checkout@v4.2.2
with:
fetch-depth: 0
token: ${{ secrets.HA_GITHUB_TOKEN }}
- name: Create empty "changed" env variable.
run: |
echo "changed=" >> $GITHUB_ENV;
- name: SkinsRestorer
run: |
resourceID='2124'
resp=$(curl --silent -X 'GET' "https://api.spiget.org/v2/resources/$resourceID/versions/latest" -H 'accept: application/json')
echo "$resp"
latestVers=$(echo "$resp" | jq -r .id)
echo "latest version: $latestVers"
# currentVers=$(cat ./mc-all-platform-velocity/Dockerfile | grep -Po '(?<=SKINRESTORE_VERS=")[0-9]+')
# echo "current version: $currentVers"
# if [ "$latestVers" != "$currentVers" ]; then
# echo "changed=${{ env.changed }} SkinsRestorer" >> $GITHUB_ENV;
# sed -i -E "s/SKINRESTORE_BUILD=\"[0-9]+\"/SKINRESTORE_BUILD=\"$latestBuild\"/" ./mc-all-platform-velocity/Dockerfile
# fi
# https://download.geysermc.org/v2/projects/geyser/versions/$GEYSER_VERS/builds/$GEYSER_BUILD/downloads/velocity
- name: Geyser
run: |
resp=$(curl --silent -X 'GET' "https://download.geysermc.org/v2/projects/geyser" -H 'accept: application/json')
echo "$resp"
latestVers=$(echo "$resp" | jq -r .versions.[-1])
echo "latest version: $latestVers"
resp2=$(curl --silent -X 'GET' "https://download.geysermc.org/v2/projects/geyser/versions/$latestVers" -H 'accept: application/json')
echo "$resp2"
latestBuild=$(echo "$resp2" | jq -r .builds.[-1])
echo "latest build: $latestBuild"
currentVers=$(cat ./mc-all-platform-velocity/Dockerfile | grep -Po '(?<=GEYSER_VERS=")[0-9]+\.[0-9]+\.[0-9]+')
echo "current version: $currentVers"
currentBuild=$(cat ./mc-all-platform-velocity/Dockerfile | grep -Po '(?<=GEYSER_BUILD=")[0-9]+')
echo "current build: $currentBuild"
if [ $latestVers != $currentVers -o $latestBuild != $currentBuild ]; then
echo "UPDATE"
echo "changed=${{ env.changed }} Geyser" >> $GITHUB_ENV;
fi
if [ $latestVers != $currentVers ]; then
echo "VERSION update"
sed -i -E "s/GEYSER_VERS=\"[0-9]+\.[0-9]+\.[0-9]+\"/GEYSER_VERS=\"$latestBuild\"/" ./mc-all-platform-velocity/Dockerfile
fi
if [ $latestBuild != $currentBuild ]; then
echo "BUILD update"
sed -i -E "s/GEYSER_BUILD=\"[0-9]+\"/GEYSER_BUILD=\"$latestBuild\"/" ./mc-all-platform-velocity/Dockerfile
fi
- name: Floodgate
run: |
resp=$(curl --silent -X 'GET' "https://download.geysermc.org/v2/projects/floodgate" -H 'accept: application/json')
echo "$resp"
latestVers=$(echo "$resp" | jq -r .versions.[-1])
echo "latest version: $latestVers"
resp2=$(curl --silent -X 'GET' "https://download.geysermc.org/v2/projects/floodgate/versions/$latestVers" -H 'accept: application/json')
echo "$resp2"
latestBuild=$(echo "$resp2" | jq -r .builds.[-1])
echo "latest build: $latestBuild"
currentVers=$(cat ./mc-all-platform-velocity/Dockerfile | grep -Po '(?<=FLOOD_VERS=")[0-9]+\.[0-9]+\.[0-9]+')
echo "current version: $currentVers"
currentBuild=$(cat ./mc-all-platform-velocity/Dockerfile | grep -Po '(?<=FLOOD_BUILD=")[0-9]+')
echo "current build: $currentBuild"
if [ "$latestVers" != "$currentVers" -o "$latestBuild" != "$currentBuild" ]; then
echo "UPDATE"
echo "changed=${{ env.changed }} Floodgate" >> $GITHUB_ENV;
fi
if [ $latestVers != $currentVers ]; then
echo "VERSION update"
sed -i -E "s/FLOOD_VERS=\"[0-9]+\.[0-9]+\.[0-9]+\"/FLOOD_VERS=\"$latestVers\"/" ./mc-all-platform-velocity/Dockerfile
fi
if [ $latestBuild != $currentBuild ]; then
echo "BUILD update"
sed -i -E "s/FLOOD_BUILD=\"[0-9]+\"/FLOOD_BUILD=\"$latestBuild\"/" ./mc-all-platform-velocity/Dockerfile
fi
- name: ViaVersion
run: |
latestVers=$(curl --silent -X 'GET' \
-H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" \
"https://hangar.papermc.io/api/v1/projects/ViaVersion/latestrelease")
echo "latest version: $latestVers"
currentVers=$(cat ./mc-all-platform-velocity/Dockerfile | grep -Po '(?<=VIAVERSION_VERS=")[0-9]+\.[0-9]+\.[0-9]+')
echo "current version: $currentVers"
if [ "$latestVers" != "$currentVers" ]; then
echo "changed=${{ env.changed }} ViaVersion" >> $GITHUB_ENV;
sed -i -E "s/VIAVERSION_VERS=\"[0-9]+\.[0-9]+\.[0-9]+\"/VIAVERSION_VERS=\"$latestVers\"/" ./mc-all-platform-velocity/Dockerfile
fi
- name: ViaBackwards
run: |
latestVers=$(curl --silent -X 'GET' -H "Accept-Encoding: identity" \
-H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" \
"https://hangar.papermc.io/api/v1/projects/ViaBackwards/latestrelease")
echo "latest version: $latestVers"
currentVers=$(cat ./mc-all-platform-velocity/Dockerfile | grep -Po '(?<=VIABACKWARDS_VERS=")[0-9]+\.[0-9]+\.[0-9]+')
echo "current version: $currentVers"
if [ "$latestVers" != "$currentVers" ]; then
echo "changed=${{ env.changed }} ViaBackwards" >> $GITHUB_ENV;
sed -i -E "s/VIABACKWARDS_VERS=\"[0-9]+\.[0-9]+\.[0-9]+\"/VIABACKWARDS_VERS=\"$latestVers\"/" ./mc-all-platform-velocity/Dockerfile
fi
- name: ViaRewind
run: |
latestVers=$(curl --silent -X 'GET' -H "Accept-Encoding: identity" \
-H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" \
"https://hangar.papermc.io/api/v1/projects/ViaRewind/latestrelease")
echo "latest version: $latestVers"
currentVers=$(cat ./mc-all-platform-velocity/Dockerfile | grep -Po '(?<=VIAREWIND_VERS=")[0-9]+\.[0-9]+\.[0-9]+')
echo "current version: $currentVers"
if [ "$latestVers" != "$currentVers" ]; then
echo "changed=${{ env.changed }} ViaRewind" >> $GITHUB_ENV;
sed -i -E "s/VIAREWIND_VERS=\"[0-9]+\.[0-9]+\.[0-9]+\"/VIAREWIND_VERS=\"$latestVers\"/" ./mc-all-platform-velocity/Dockerfile
fi
- name: EaglercraftXVelocity
run: |
resp=$(curl --silent -X 'GET' -H "Accept-Encoding: identity" -H 'accept: application/json' \
-H "Accept-Language: en" -L -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4.212 Safari/537.36" \
"https://git.eaglercraft.rip/api/v1/repos/eaglercraft/eaglercraft-1.8/commits?path=gateway%2FEaglercraftXVelocity%2Fsrc%2Fmain%2Fjava%2Fnet%2Flax1dude%2Feaglercraft%2Fv1_8%2Fplugin%2Fgateway_velocity%2FEaglerXVelocityVersion.java")
latestID=$(echo "$resp" | jq -r .[0].sha)
echo "latest commit: $latestID"
currentID=$(cat ./mc-all-platform-velocity/Dockerfile | grep -Po '(?<=EAGLER_COMMIT_ID=")[0-9a-z]+')
echo "current commit: $currentID"
if [ "$latestID" != "$currentID" ]; then
echo "changed=${{ env.changed }} EaglercraftXVelocity" >> $GITHUB_ENV;
sed -i -E "s/EAGLER_COMMIT_ID=\"[0-9a-z]+\"/EAGLER_COMMIT_ID=\"$latestID\"/" ./mc-all-platform-velocity/Dockerfile
fi
- name: "Check what needs to be done"
run: |
echo ${{ env.changed }}
if [ "${{ env.changed }}" != "" ]; then
REGEX_PATTERN="update-deps-[a-f0-9]{7}"
BRANCHES=$(git branch -r)
echo "Branches: $BRANCHES"
BRANCH_NAME=$(echo "$BRANCHES" | grep -E "$REGEX_PATTERN" | sed 's|origin/||' | head -n 1 | xargs )
echo "Found branch: $BRANCH_NAME"
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
if [ -z "$BRANCH_NAME" ]; then
echo "No branch matching the pattern found."
echo "need_pr=true" >> $GITHUB_ENV;
exit 0
fi
echo "Branch $BRANCH_NAME exists."
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git add .
if [ -z "$(git status --porcelain)" ]; then
echo "No changes to commit"
exit 0
fi
git commit -m "Update deps:${{ env.changed }}"
echo "need_pr_update=true" >> $GITHUB_ENV;
fi
- name: Push changes to exiting PR branch
if: ${{ env.need_pr_update }}
uses: ad-m/github-push-action@master
with:
branch: ${{ env.BRANCH_NAME }}
force: true
- name: Create Pull Request
if: ${{ env.need_pr }}
uses: peter-evans/create-pull-request@v7.0.6
with:
commit-message: |
Update deps:
${{ env.changed }}
branch: update-deps
delete-branch: true
branch-suffix: short-commit-hash
title: "Update deps:${{ env.changed }}"
body: "This pull request was created automatically."
labels: dependencies
maintainer-can-modify: true
token: ${{ secrets.HA_GITHUB_TOKEN }}