Skip to content

Commit

Permalink
Merge pull request #29 from WilderForge/buildSystem
Browse files Browse the repository at this point in the history
Fix commit sha not being used correctly in the build workflow
Fix build error on commit push
  • Loading branch information
Gamebuster19901 authored Dec 4, 2024
2 parents 55f04d0 + 25d4aae commit b931f34
Showing 1 changed file with 18 additions and 54 deletions.
72 changes: 18 additions & 54 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
description: 'The commit SHA to checkout and build'
required: true
publish:
description: 'whether to publish after building'
description: 'Whether to publish after building'
required: false
push:
branches:
Expand All @@ -18,20 +18,21 @@ jobs:
runs-on: [self-hosted, linux]

steps:
- name: Set Commit Status to Pending
- name: Determine Commit SHA
id: determine_sha
run: |
# Determine the commit SHA to build
if [ -z "${{ github.event.inputs.sha }}" ]; then
COMMIT_SHA="${{ github.sha }}"
echo "COMMIT_SHA=${{ github.sha }}" >> $GITHUB_ENV
else
COMMIT_SHA="${{ github.event.inputs.sha }}"
echo "COMMIT_SHA=${{ github.event.inputs.sha }}" >> $GITHUB_ENV
fi
- name: Set Commit Status to Pending
run: |
STATUS="pending"
DESCRIPTION="Build in progress for commit $COMMIT_SHA"
DESCRIPTION="Build in progress for commit ${{ env.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" \
Expand All @@ -41,12 +42,12 @@ jobs:
\"context\": \"Build Status\",
\"target_url\": \"$TARGET_URL\"
}" \
"https://api.github.com/repos/${{ github.repository }}/statuses/$COMMIT_SHA"
"https://api.github.com/repos/${{ github.repository }}/statuses/${{ env.COMMIT_SHA }}"
- name: Checkout the repository at SHA
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.sha }}
ref: ${{ env.COMMIT_SHA }}

- name: Set up JDK 17
uses: actions/[email protected]
Expand All @@ -57,65 +58,28 @@ jobs:
- 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
if: always()
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="success"
DESCRIPTION="Build successful"
if [ ${{ job.status }} != "success" ]; then
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" \
Expand All @@ -125,4 +89,4 @@ jobs:
\"context\": \"Build Status\",
\"target_url\": \"$TARGET_URL\"
}" \
"https://api.github.com/repos/${{ github.repository }}/statuses/$COMMIT_SHA"
"https://api.github.com/repos/${{ github.repository }}/statuses/${{ env.COMMIT_SHA }}"

0 comments on commit b931f34

Please sign in to comment.