This repository has been archived by the owner on Jul 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
85 lines (67 loc) · 2.32 KB
/
autoupdate.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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