This repository has been archived by the owner on Jul 6, 2024. It is now read-only.
TT | Autoupdate #2
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 PaperMC Latest Stable Release | |
on: | |
schedule: | |
- cron: '0 0 * * 1' # Runs every Monday at 00:00 UTC | |
workflow_dispatch: | |
jobs: | |
check-latest-release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.x' | |
- name: Restore previous release from cache | |
id: cache | |
uses: actions/cache@v3 | |
with: | |
path: previous_release.txt | |
key: paper-release | |
- name: Get latest stable release | |
id: get_latest_release | |
run: | | |
python - <<EOF | |
import requests | |
# Fetch the latest version information | |
response = requests.get("https://api.papermc.io/v2/projects/paper") | |
data = response.json() | |
versions = data['versions'] | |
# Assuming the latest version is the highest version number | |
latest_version = versions[-1] | |
response = requests.get(f"https://api.papermc.io/v2/projects/paper/versions/{latest_version}/builds") | |
builds_data = response.json() | |
builds = builds_data['builds'] | |
latest_build = max(build['build'] for build in builds) | |
# Output the latest version and build for GitHub Actions | |
print(f"::set-output name=latest_version::{latest_version}") | |
print(f"::set-output name=latest_build::{latest_build}") | |
# Read the previous release info from the cache file | |
try: | |
with open("previous_release.txt", "r") as f: | |
previous_version, previous_build = f.read().split(',') | |
previous_build = int(previous_build) | |
except FileNotFoundError: | |
previous_version, previous_build = None, None | |
# Determine if there is a new release | |
new_release = (latest_version != previous_version) or (latest_build > previous_build) | |
if new_release: | |
print("New stable release found") | |
with open("previous_release.txt", "w") as f: | |
f.write(f"{latest_version},{latest_build}") | |
print("::set-output name=new_release::true") | |
else: | |
print("No new stable release") | |
print("::set-output name=new_release::false") | |
EOF | |
- name: Update cache with the latest release info | |
if: steps.get_latest_release.outputs.new_release == 'true' | |
uses: actions/cache@v3 | |
with: | |
path: previous_release.txt | |
key: paper-release |