From e7683b916beb1bc1b299b6dde41fd8dc290f2234 Mon Sep 17 00:00:00 2001 From: Chris Tracy <58871574+ChrisTracy@users.noreply.github.com> Date: Fri, 22 Mar 2024 01:33:40 -0500 Subject: [PATCH 1/2] Create update_paper_version.yml --- .github/workflows/update_paper_version.yml | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/update_paper_version.yml diff --git a/.github/workflows/update_paper_version.yml b/.github/workflows/update_paper_version.yml new file mode 100644 index 0000000..e9cc366 --- /dev/null +++ b/.github/workflows/update_paper_version.yml @@ -0,0 +1,34 @@ +name: Update Paper Version + +on: + schedule: + - cron: '30 6 * * *' + workflow_dispatch: + +jobs: + update-version: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install Python dependencies + run: | + python -m pip install --upgrade pip + pip install requests beautifulsoup4 + + - name: Check for new Paper version and update files + run: python .github/scripts/check_update_paper.py + + - name: Commit and push if there are changes + run: | + git config --global user.email "${{ secrets.GIT_USER_EMAIL }}" + git config --global user.name "${{ secrets.GIT_USER_NAME }}" + git diff --quiet && git diff --staged --quiet || (git commit -am "Update Paper version" && git push) + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 39aebe376d04e520197722f502b9886e77e280c0 Mon Sep 17 00:00:00 2001 From: Chris Tracy <58871574+ChrisTracy@users.noreply.github.com> Date: Fri, 22 Mar 2024 01:34:35 -0500 Subject: [PATCH 2/2] Create check_update_paper.py --- .github/scripts/check_update_paper.py | 87 +++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 .github/scripts/check_update_paper.py diff --git a/.github/scripts/check_update_paper.py b/.github/scripts/check_update_paper.py new file mode 100644 index 0000000..33b2077 --- /dev/null +++ b/.github/scripts/check_update_paper.py @@ -0,0 +1,87 @@ +from datetime import datetime +import glob +import re +import os +import requests +from bs4 import BeautifulSoup + +def get_latest_version(): + # Fetches and returns the latest version of PaperMC from its downloads page. + url = 'https://papermc.io/downloads/paper' + response = requests.get(url) + soup = BeautifulSoup(response.content, 'html.parser') + version_element = soup.find('span', class_='text-blue-600') + if version_element: + version_text = version_element.text.strip() + print(f"Latest version found: {version_text}") + return version_text + else: + print("No version found on the page.") + return None + +def is_valid_version(version): + # Checks if the given version string matches the expected version pattern. + return bool(re.match(r'^\d+\.\d+\.\d+$', version)) + +def get_date_suffix(day): + # Returns the appropriate ordinal suffix for a given day of the month. + return 'th' if 11 <= day <= 13 else {1: 'st', 2: 'nd', 3: 'rd'}.get(day % 10, 'th') + +def update_readme(latest_version): + # Updates the README.md file with the latest version information under the update history section. + today = datetime.now() + date_suffix = get_date_suffix(today.day) + formatted_date = today.strftime(f'%B %d{date_suffix} %Y') + update_entry = f"\n
  • {formatted_date}
  • \n \n" + + with open('README.md', 'r+') as file: + content = file.read() + updated_content = re.sub(r'(

    Update History

    \n