Skip to content

Automatically update Paper commit hash #794

Automatically update Paper commit hash

Automatically update Paper commit hash #794

Workflow file for this run

name: Automatically update Paper commit hash
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *"
jobs:
fetch_update:
name: Fetch Update
# Run workflow only on main repo
if: ${{ github.repository == 'Winds-Studio/Leaf' }}
runs-on: ubuntu-latest
outputs:
update_needed: ${{ steps.checkUpdate.outputs.update_needed }}
latest_paper_commit: ${{ steps.latestPaperCommit.outputs.latest_paper_commit }}
curr_paper_commit: ${{ steps.currPaperCommit.outputs.curr_paper_commit }}
steps:
- name: Checkout Leaf repository
uses: actions/checkout@v6
with:
path: 'Leaf'
token: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout Paper repository
uses: actions/checkout@v6
with:
path: 'Paper'
repository: "PaperMC/Paper"
ref: "main"
token: ${{ secrets.GITHUB_TOKEN }}
- name: Get Paper latest commit hash
id: latestPaperCommit
run: |
cd Paper
echo "latest_paper_commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Get Leaf current Paper commit hash
id: currPaperCommit
run: |
cd Leaf
currPaperCommit=$(awk -F '= *' '/^paperCommit/ {print $2}' gradle.properties)
echo "curr_paper_commit=$currPaperCommit" >> $GITHUB_OUTPUT
- name: Check if update is needed
id: checkUpdate
run: |
if [ "$LATEST_PAPER_COMMIT" != "$CURR_PAPER_COMMIT" ]; then
echo "update_needed=true" >> $GITHUB_OUTPUT
else
echo "update_needed=false" >> $GITHUB_OUTPUT
fi
env:
LATEST_PAPER_COMMIT: ${{ steps.latestPaperCommit.outputs.latest_paper_commit }}
CURR_PAPER_COMMIT: ${{ steps.currPaperCommit.outputs.curr_paper_commit }}
build:
name: Update and Build Leaf
needs: fetch_update
if: ${{ needs.fetch_update.outputs.update_needed == 'true' }}
runs-on: ubuntu-latest
env:
MC_VERSION: "1.21.11"
PR_BRANCH: "chore/update-upstream-${{ github.run_number }}"
steps:
- name: Checkout Leaf repository
uses: actions/checkout@v6
with:
path: 'Leaf'
token: ${{ secrets.GITHUB_TOKEN }}
- name: Update paperCommit in Leaf
run: |
cd Leaf
sed -i "s/\(paperCommit\s*=\s*\).*/\1$LATEST_PAPER_COMMIT/" gradle.properties
env:
LATEST_PAPER_COMMIT: ${{ needs.fetch_update.outputs.latest_paper_commit }}
- name: Grant execute permission for gradlew
run: |
cd Leaf
git config --global user.email "no-reply@github.com"
git config --global user.name "Github Actions"
chmod +x gradlew
- uses: actions/setup-java@v5
with:
distribution: 'zulu'
java-version: '21'
- name: Running tests before push
run: |
cd Leaf
if ! git diff --quiet; then
echo "Running tests...."
./gradlew applyAllPatches
./gradlew build -x test
./gradlew rebuildPaperPatches
./gradlew rebuildAllServerPatches
fi
- name: Check for changes and commit
run: |
cd Leaf
if ! git diff --quiet; then
echo "Writing to repo....."
git checkout -b "${{ env.PR_BRANCH }}"
git add .
chmod +x ./scripts/upstreamCommit.sh
./scripts/upstreamCommit.sh --paper $CURR_PAPER_COMMIT
git push origin "${{ env.PR_BRANCH }}"
else
echo "No changes to commit."
fi
env:
CURR_PAPER_COMMIT: ${{ needs.fetch_update.outputs.curr_paper_commit }}
- name: Create PR
run: |
cd Leaf
gh pr create \
--base "ver/${{ env.MC_VERSION }}" \
--head "${{ env.PR_BRANCH }}" \
--label "type: general" \
--title "Updated Upstream" \
--body "This PR is auto-generated by GitHub Actions"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}