Merge pull request #28 from WilderForge/buildSystem #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Specific Commit | |
on: | |
workflow_dispatch: | |
inputs: | |
sha: | |
description: 'The commit SHA to checkout and build' | |
required: true | |
publish: | |
description: 'whether to publish after building' | |
required: false | |
push: | |
branches: | |
- master | |
jobs: | |
build_commit: | |
runs-on: [self-hosted, linux] | |
steps: | |
- name: Set Commit Status to Pending | |
run: | | |
# Determine the commit SHA to build | |
if [ -z "${{ github.event.inputs.sha }}" ]; then | |
COMMIT_SHA="${{ github.sha }}" | |
else | |
COMMIT_SHA="${{ github.event.inputs.sha }}" | |
fi | |
STATUS="pending" | |
DESCRIPTION="Build in progress for commit $COMMIT_SHA" | |
TARGET_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
# Post the pending status to the commit using GitHub API | |
curl -s -X POST \ | |
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Content-Type: application/json" \ | |
-d "{ | |
\"state\": \"$STATUS\", | |
\"description\": \"$DESCRIPTION\", | |
\"context\": \"Build Status\", | |
\"target_url\": \"$TARGET_URL\" | |
}" \ | |
"https://api.github.com/repos/${{ github.repository }}/statuses/$COMMIT_SHA" | |
- name: Checkout the repository at SHA | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.inputs.sha }} | |
- name: Set up JDK 17 | |
uses: actions/[email protected] | |
with: | |
java-version: '17' | |
distribution: 'adopt' | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@v4 | |
- name: Parse `settings.gradle` for wilderworkspace version | |
id: parse_version | |
run: | | |
# Parse settings.gradle for the version of wilderworkspace | |
VERSION=$(grep -oP "useModule\('com\.wildermods:wilderworkspace:(.*?)'\)" settings.gradle | sed -E "s/useModule\('com\.wildermods:wilderworkspace:(.*)'\)/\1/") | |
echo "WILDERWORKSPACE_VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Download WilderWorkspace JAR from GitHub | |
run: | | |
# Create libs directory if it doesn't exist | |
mkdir -p libs | |
# Construct the GitHub release URL based on the version | |
RELEASE_URL="https://github.com/WilderForge/WilderWorkspace/releases/download/${{ env.WILDERWORKSPACE_VERSION }}/wilderworkspace-${{ env.WILDERWORKSPACE_VERSION }}.jar" | |
# Add ?raw=true to ensure we download the raw file | |
RAW_URL="${RELEASE_URL}?raw=true" | |
# Echo the URL for debugging purposes | |
echo "Downloading from URL: $RAW_URL" | |
# Download the wilderworkspace JAR using curl | |
curl -L -o libs/wilderworkspace-${{ env.WILDERWORKSPACE_VERSION }}.jar $RAW_URL | |
# Verify download success | |
ls -lh libs | |
- name: Clear Game Files | |
run: ./gradlew clearLocalRuntime | |
- name: Setup Decompiled Workspace | |
run: ./gradlew setupDecompWorkspace | |
- name: Build With Gradle | |
run: ./gradlew build | |
- name: Publish Build | |
if: ${{ github.event.inputs.publish == 'true' }} | |
run: | | |
echo "Publishing build..." | |
./gradlew publish -PmavenRepoUrl=${{ secrets.MAVEN_REPO }} | |
- name: Post Build Status | |
if: always() # Ensures this step runs regardless of previous step success/failure | |
run: | | |
COMMIT_SHA="${{ github.event.inputs.sha }}" | |
# Determine status based on the build result | |
if [[ $? -eq 0 ]]; then | |
STATUS="success" | |
DESCRIPTION="Build successful" | |
else | |
STATUS="failure" | |
DESCRIPTION="Build failed" | |
fi | |
TARGET_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
# Post the status to the commit using GitHub API | |
curl -s -X POST \ | |
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Content-Type: application/json" \ | |
-d "{ | |
\"state\": \"$STATUS\", | |
\"description\": \"$DESCRIPTION\", | |
\"context\": \"Build Status\", | |
\"target_url\": \"$TARGET_URL\" | |
}" \ | |
"https://api.github.com/repos/${{ github.repository }}/statuses/$COMMIT_SHA" |