This repository has been archived by the owner on Jul 6, 2024. It is now read-only.
TT | Autoupdate #5
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: TT | Autoupdate | |
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: Install requests module | |
run: pip install requests | |
- 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 | |
import os | |
response = requests.get(f"https://api.papermc.io/v2/projects/paper/versions/1.20.6/builds") | |
builds_data = response.json() | |
builds = builds_data['builds'] | |
latest_build = max(build['build'] for build in builds) | |
# Output the latest version for GitHub Actions | |
env_file = os.getenv('GITHUB_ENV') | |
# Read the previous release info from the cache file | |
try: | |
with open("previous_build.txt", "r") as f: | |
previous_build = f.read().strip() | |
except FileNotFoundError: | |
previous_build = 0 | |
# Determine if there is a new release | |
new_release = (latest_build > previous_build) | |
if new_release: | |
with open("previous_build.txt", "w") as f: | |
f.write(latest_build) | |
with open(env_file, "a") as f: | |
f.write("new_release=true\n") | |
else: | |
with open(env_file, "a") as f: | |
f.write("new_release=false\n") | |
EOF | |
- name: Load latest release info | |
run: | | |
source latest_release.env | |
echo "Latest build: $latest_build" | |
- name: Check for new release | |
run: | | |
source new_release.env | |
echo "New release: $new_release" | |
id: check_new_release | |
- name: Update cache with the latest release info | |
if: steps.check_new_release.outputs.new_release == 'true' | |
uses: actions/cache@v3 | |
with: | |
path: previous_build.txt | |
key: paper-release | |