Skip to content

Refresh Available Vanilla Versions #47

Refresh Available Vanilla Versions

Refresh Available Vanilla Versions #47

name: "Refresh Available Vanilla Versions"
on:
# Manual trigger for just in case.
workflow_dispatch:
inputs:
branch:
description: 'Branch to run workflow on'
required: false
default: 'main' # Uses the branch name that triggered the run
schedule:
# Set to run action once a day at 0:00 server time.
- cron: '0 0 * * *'
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write # Allow pushing to the repository for the action.
steps:
# Setup main as default branch if no other branch is supplied.
- name: Use input or default branch
run: |
EVENT_NAME="${{ github.event_name }}"
if [[ "$EVENT_NAME" = "workflow_dispatch" ]]; then
echo "TARGET_BRANCH=${{ inputs.branch }}" >> $GITHUB_ENV
else
echo "TARGET_BRANCH=main" >> $GITHUB_ENV
fi
- name: Checkout repo
uses: actions/checkout@v4
with:
# Required for the action to be able to push
fetch-depth: 0
# This uses the specific ref (branch/tag/SHA) that the workflow was triggered on
ref: ${{ env.TARGET_BRANCH }}
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
architecture: "x64"
cache: pip
cache-dependency-path: scripts/python-requirements.txt
- name: Install required packages
run: |
python -m pip install --upgrade pip
pip install -r scripts/python-requirements.txt
- name: Execute refresh script
run: python scripts/refresh_vanilla_versions.py > pyscript.log
- name: Add any changed files
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add -A
- name: Commit changes if any
run: |
if git diff --cached --quiet --exit-code; then
echo "No changes to commit. Skipping push."
echo "PUSH_NEEDED=false" >> $GITHUB_ENV
else
FORMATTED_VERSIONS="$(grep -Po "Version: \K[^ ]+" pyscript.log | sed 's/^/- /')"
VERSION_COUNT=$(echo "${FORMATTED_VERSIONS}" | tr -d -c '\n' | wc -c)
TITLE="Added new minecraft version"
if (( $VERSION_COUNT > 1 )); then
TITLE="Added new minecraft versions"
fi
echo -e "${TITLE}\n\n${FORMATTED_VERSIONS}" > commit.log
git commit --file commit.log
rm commit.log
echo "Changes committed. Proceeding with push."
echo "PUSH_NEEDED=true" >> $GITHUB_ENV
fi
if [ -f "pyscript.log" ] && [ ! -s "pyscript.log" ]; then
echo "Removing empty python output log file."
rm pyscript.log
fi
- name: Upload surplus log files as an artifact
if: always() # Run this regardless failed step. May need to get python script failed logs.
uses: actions/upload-artifact@v4
with:
name: Log Files
if-no-files-found: ignore
path: |
**/*.log
- name: Push changes when change detected
if: env.PUSH_NEEDED == 'true' # Check the environment variable
run: git push