Skip to content

Create Update Upstream PR #176

Create Update Upstream PR

Create Update Upstream PR #176

name: Create Update Upstream PR
on:
workflow_dispatch:
inputs:
commit_hash:
description: 'The commit hash to be referenced'
required: false
permissions: write-all
jobs:
check_upstream:
runs-on: ubuntu-latest
outputs:
pr_description: ${{ steps.check_result.outputs.pr_description }}
commit_message: ${{ steps.check_result.outputs.commit_message }}
latest_commit_hash: ${{ steps.latest_commit_hash.outputs.hash }}
steps:
- name: Checkout Git Repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Run check-upstream.sh
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
id: check_result
env:
commit_hash: ${{ inputs.commit_hash }}
with:
result-encoding: string
script: |
const { commit_hash } = process.env
const result = await exec.getExecOutput('bash ./scripts/check-upstream.sh ' + commit_hash);
const output = result.stdout;
core.setOutput('pr_description', output);
core.setOutput('commit_message', 'Updated Upstream (Folia)\n' + output);
- name: Store latest commit hash to output
id: latest_commit_hash
run: echo "hash=$(<paper-ref)" >> $GITHUB_OUTPUT
update_patches_and_open_pr:
runs-on: ubuntu-latest
needs: check_upstream
if: ${{ startsWith(needs.check_upstream.outputs.pr_description, 'Folia Changes:') }}
steps:
- name: Checkout Git Repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up JDK
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # v4.5.0
with:
distribution: 'temurin'
java-version: '21'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@473878a77f1b98e2b5ac4af93489d1656a80a5ed # v4.2.0
with:
cache-read-only: false
- name: Configure Git User Details
run: git config --global user.email "actions@github.com" && git config --global user.name "Github Actions"
- run: chmod +x ./gradlew
- name: Update paper-ref
run: echo -n ${{ needs.check_upstream.outputs.latest_commit_hash }} > paper-ref
- name: Apply Patches
id: apply_patches
continue-on-error: true
run: ./gradlew applyPatches --stacktrace
- name: Rebuild Patches
if: steps.apply_patches.outcome == 'success'
continue-on-error: true
run: ./gradlew rebuildPatches --stacktrace
- name: Build
id: build_jar
if: steps.apply_patches.outcome == 'success'
continue-on-error: true
run: ./gradlew createMojmapPaperclipJar --stacktrace
- name: Specify Labels
id: labels
if: always()
run: |
if [ "${{ steps.apply_patches.outcome }}" != "success" ]; then
echo "result=upstream,rebase-required" >> $GITHUB_OUTPUT
elif [ "${{ steps.build_jar.outcome }}" != "success" ]; then
echo "result=upstream,build-failure" >> $GITHUB_OUTPUT
else
echo "result=upstream" >> $GITHUB_OUTPUT
fi
- name: Create a Pull Request
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5
if: always()
with:
title: Updated Upstream (Folia)
body: ${{ needs.check_upstream.outputs.pr_description }}
commit-message: ${{ needs.check_upstream.outputs.commit_message }}
branch: upstream
labels: ${{ steps.labels.outputs.result }}
draft: ${{ steps.apply_patches.outcome != 'success' && steps.build_jar.outcome != 'success' }}
- name: Upload jar
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
if: steps.build_jar.outcome == 'success'
continue-on-error: true
with:
name: Okocraft-Build-${{ github.run_number }}
path: ./build/libs/okocraft-paperclip-*.jar