Skip to content

Commit 33b8a4b

Browse files
committed
Split auto update workflow to only run updates if needed
1 parent 46619a9 commit 33b8a4b

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

.github/workflows/auto-update.yml

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ on:
66
- cron: "0 0 * * *"
77

88
jobs:
9-
build:
9+
fetch_update:
10+
name: Fetch Update
1011
# Run workflow only on main repo
1112
if: ${{ github.repository == 'Winds-Studio/Leaf' }}
1213
runs-on: ubuntu-latest
14+
outputs:
15+
update_needed: ${{ steps.checkUpdate.outputs.update_needed }}
16+
paper_commit: ${{ steps.paperCommit.outputs.paper_commit }}
17+
curr_paper_commit: ${{ steps.currPaperCommit.outputs.curr_paper_commit }}
1318
steps:
1419
- name: Checkout Leaf repository
1520
uses: actions/checkout@v6
@@ -22,33 +27,58 @@ jobs:
2227
with:
2328
path: 'Paper'
2429
repository: "PaperMC/Paper"
30+
ref: "ver/1.21.8"
2531
token: ${{ secrets.GITHUB_TOKEN }}
2632

27-
- name: Get Paper latest commit Hash
33+
- name: Get Paper latest commit hash
2834
id: paperCommit
2935
run: |
3036
cd Paper
31-
echo "paperCommit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
37+
echo "paper_commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
3238
33-
- name: Get Leaf Current Paper commit Hash
39+
- name: Get Leaf current Paper commit hash
3440
id: currPaperCommit
3541
run: |
3642
cd Leaf
37-
currPaperCommit=$(grep "^paperCommit\s*=" gradle.properties | sed 's/^paperCommit\s*=\s*//')
38-
echo "currPaperCommit=$currPaperCommit" >> $GITHUB_OUTPUT
43+
currPaperCommit=$(awk -F '= *' '/^paperCommit/ {print $2}' gradle.properties)
44+
echo "curr_paper_commit=$currPaperCommit" >> $GITHUB_OUTPUT
45+
46+
- name: Check if update is needed
47+
id: checkUpdate
48+
run: |
49+
if [ "$PAPER_COMMIT" != "$CURR_PAPER_COMMIT" ]; then
50+
echo "update_needed=true" >> $GITHUB_OUTPUT
51+
else
52+
echo "update_needed=false" >> $GITHUB_OUTPUT
53+
fi
54+
env:
55+
PAPER_COMMIT: ${{ steps.currPaperCommit.outputs.paper_commit }}
56+
CURR_PAPER_COMMIT: ${{ steps.paperCommit.outputs.curr_paper_commit }}
57+
58+
build:
59+
name: Update and Build Leaf
60+
needs: fetch_update
61+
if: ${{ needs.fetch_update.outputs.update_needed == 'true' }}
62+
runs-on: ubuntu-latest
63+
steps:
64+
- name: Checkout Leaf repository
65+
uses: actions/checkout@v6
66+
with:
67+
path: 'Leaf'
68+
token: ${{ secrets.GITHUB_TOKEN }}
3969

4070
- name: Update paperCommit in Leaf
4171
run: |
4272
cd Leaf
4373
sed -i "s/\(paperCommit\s*=\s*\).*/\1$PAPER_COMMIT/" gradle.properties
4474
env:
45-
PAPER_COMMIT: ${{ steps.paperCommit.outputs.paperCommit }}
75+
PAPER_COMMIT: ${{ needs.fetch_update.outputs.paper_commit }}
4676

4777
- name: Grant execute permission for gradlew
4878
run: |
4979
cd Leaf
50-
git config --global user.name "Dreeam-qwq"
51-
git config --global user.email [email protected]
80+
git config --global user.email "[email protected]"
81+
git config --global user.name "Github Actions"
5282
chmod +x gradlew
5383
5484
- uses: actions/setup-java@v5
@@ -80,4 +110,4 @@ jobs:
80110
echo "No changes to commit."
81111
fi
82112
env:
83-
CURR_PAPER_COMMIT: ${{ steps.currPaperCommit.outputs.currPaperCommit }}
113+
CURR_PAPER_COMMIT: ${{ needs.fetch_update.outputs.curr_paper_commit }}

0 commit comments

Comments
 (0)