Skip to content
This repository has been archived by the owner on Jul 6, 2024. It is now read-only.

TT | Autoupdate

TT | Autoupdate #18

Workflow file for this run

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_build.txt
key: paper-build
- 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 = int(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 = int(f.read().strip())
except FileNotFoundError:
previous_build = 0
# Determine if there is a new release
new_release = (latest_build > previous_build)
print(latest_build, previous_build, new_release)
if new_release:
with open("previous_build.txt", "w") as f:
f.write(str(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: Check for new release
run: |
source $GITHUB_ENV
echo "New release: $new_release"
id: check_new_release
- name: Update cache with the latest release info
if: env.new_release == 'true'
uses: actions/cache@v3
with:
path: previous_build.txt
key: paper-build
- name: Trigger new update & build workflow
if: env.new_release == 'true'
run: |
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/TurnipTales/turniptales-paper/actions/workflows/update.yml/dispatches \
-d '{
"ref":"master",
"inputs": {
"paperclip": "true"
}
}'