-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from WilderForge/buildSystem
Add github workflows
- Loading branch information
Showing
5 changed files
with
379 additions
and
41 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
name: Rebuild Approved PR | ||
|
||
on: | ||
issue_comment: | ||
types: [created] | ||
|
||
jobs: | ||
rebuild_approved_pr: | ||
runs-on: ubuntu-latest | ||
if: > | ||
github.event.comment.user.login == 'Gamebuster19901' && | ||
github.event.comment.body == '@WilderForge rebuild' && | ||
github.event.issue.pull_request != null | ||
steps: | ||
- name: Fetch Approval Workflow Run | ||
id: fetch_approval_run | ||
run: | | ||
# Fetch the pull request details | ||
PR_URL=$(jq -r '.pull_request.url' <<< '${{ toJson(github.event.issue) }}') | ||
echo "PR URL: $PR_URL" | ||
PR_DETAILS=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "$PR_URL") | ||
# echo "PR Details: $PR_DETAILS" # Debugging: output PR details to see its contents | ||
PR_NUMBER=$(echo "$PR_DETAILS" | jq -r '.number') | ||
echo "PR Number: $PR_NUMBER" # Debugging: output the PR number | ||
# Get the commit SHA directly from the pull request head object | ||
PR_SHA=$(echo "$PR_DETAILS" | jq -r '.head.sha') | ||
echo "PR SHA: $PR_SHA" # Debugging: output the PR SHA | ||
if [ -z "$PR_SHA" ]; then | ||
echo "Pull request head commit SHA is null. Exiting." | ||
exit 1 | ||
fi | ||
# Get the list of workflow runs for the repository | ||
WORKFLOWS=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | ||
"https://api.github.com/repos/${{ github.repository }}/actions/runs") | ||
# echo "Workflow Runs: $WORKFLOWS" # Debugging: output workflow runs data | ||
# Find the latest completed run of the 'Validate Approval' workflow that matches the head SHA | ||
APPROVAL_RUN=$(echo "$WORKFLOWS" | jq -r \ | ||
'.workflow_runs[] | select(.name == "Validate Approval" and .head_sha == "'$PR_SHA'" and .status == "completed") | .id' | head -n 1) | ||
echo "Approval Run: $APPROVAL_RUN" # Debugging: output the approval run ID | ||
if [ -z "$APPROVAL_RUN" ]; then | ||
echo "The head of this PR has not been validated. Exiting." | ||
exit 1 | ||
fi | ||
# Save the approval run ID to environment variable for use in later steps | ||
echo "APPROVAL_RUN=$APPROVAL_RUN" >> $GITHUB_ENV | ||
- name: Check Approval | ||
id: check_approval_status | ||
run: | | ||
# Fetch the details of the approval workflow run using the saved APPROVAL_RUN ID | ||
APPROVAL_STATUS=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | ||
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ env.APPROVAL_RUN }}") | ||
CONCLUSION=$(echo "$APPROVAL_STATUS" | jq -r '.conclusion') | ||
STATUS=$(echo "$APPROVAL_STATUS" | jq -r '.status') | ||
echo "Approval Workflow Status: $STATUS" # Debugging: output the workflow status | ||
echo "Approval Workflow Conclusion: $CONCLUSION" # Debugging: output the workflow conclusion | ||
if [[ "$CONCLUSION" != "success" || "$STATUS" != "completed" ]]; then | ||
echo "The head of this PR has not been validated. Exiting." | ||
exit 1 | ||
fi | ||
echo "The head of this PR has been validated." | ||
- name: Trigger Build Commit Workflow | ||
if: success() | ||
run: | | ||
# Get the source branch of the PR (from the pull_request object) | ||
PR_BRANCH="${{ github.event.pull_request.head.ref }}" | ||
# Define the API endpoint for dispatching the workflow | ||
WORKFLOW_URL="https://api.github.com/repos/${{ github.repository }}/actions/workflows/build.yml/dispatches" | ||
# Trigger the workflow for the branch of the pull request | ||
echo "Triggering workflow for branch: $PR_BRANCH" | ||
RESPONSE=$(curl -s -w "%{http_code}" -o response.json -X POST \ | ||
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | ||
-d '{"ref": "refs/heads/'${PR_BRANCH}'", "inputs": {"sha": "${{ github.event.review.commit_id }}"}}' \ | ||
"$WORKFLOW_URL") | ||
# Check if the HTTP status code is 2xx (successful) | ||
if [[ "$RESPONSE" -lt 200 || "$RESPONSE" -ge 300 ]]; then | ||
echo "Error triggering the workflow: HTTP $RESPONSE" | ||
cat response.json | ||
exit 1 | ||
else | ||
echo "Successfully triggered the workflow." | ||
fi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
name: Validate Approval | ||
|
||
on: | ||
pull_request_review: | ||
types: [submitted] | ||
|
||
jobs: | ||
approve_and_run: | ||
runs-on: ubuntu-latest | ||
if: | | ||
( | ||
github.event.review.state == 'approved' && | ||
github.event.review.user.login == 'Gamebuster19901' | ||
) || | ||
( | ||
( | ||
github.event.pull_request != null && | ||
github.event.sender.login == 'Gamebuster19901' && | ||
github.event.pull_request.user.login == 'Gamebuster19901' | ||
) && | ||
( | ||
startsWith(github.event.review.body, 'approved') || | ||
startsWith(github.event.review.body, 'reject') | ||
) | ||
) | ||
steps: | ||
- name: Checking Approval | ||
id: "checking_approval" | ||
run: | | ||
DESC="null" | ||
if [[ "${{ github.event.review.body }}" == approved* ]]; then | ||
DESC="${{ github.event.review.user.login }} APPROVED build for ${{ github.event.review.commit_id }}" | ||
echo $DESC | ||
echo "conclusion=success" >> "$GITHUB_ENV" | ||
echo "description=$DESC" >> "$GITHUB_ENV" | ||
exit 0 | ||
elif [[ "${{ github.event.review.body }}" == reject* ]]; then | ||
DESC="${{ github.event.review.user.login }} REJECTED build for ${{ github.event.review.commit_id }}" | ||
echo $DESC | ||
echo "conclusion=failure" >> "$GITHUB_ENV" | ||
echo "description=$DESC" >> "$GITHUB_ENV" | ||
exit 1 | ||
else | ||
DESC="Assertion Error: Review body expected start with 'approved' or 'reject'. This step should have been skipped but it ran anyway!" | ||
echo $DESC | ||
echo "conclusion=failure" >> "$GITHUB_ENV" | ||
echo "description=$DESC" >> "$GITHUB_ENV" | ||
exit 1 | ||
fi | ||
- name: Post Status Check | ||
if: | ||
always() | ||
run: | | ||
echo "${{ env.approved_sha }}" | ||
STATUS="${{ env.conclusion }}" | ||
DESCRIPTION="${{ env.description }}" | ||
CONTEXT="Approval Validation" | ||
APPROVED_SHA="${{ github.event.review.commit_id }}" | ||
TARGET_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" | ||
# Post the status using GitHub API | ||
curl -s -X POST \ | ||
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | ||
-H "Content-Type: application/json" \ | ||
-d "{ | ||
\"state\": \"$STATUS\", | ||
\"description\": \"$DESCRIPTION\", | ||
\"context\": \"Approval Validation\", | ||
\"target_url\": \"$TARGET_URL\" | ||
}" \ | ||
"https://api.github.com/repos/${{ github.repository }}/statuses/$APPROVED_SHA" | ||
|
||
- name: Trigger Build Commit Workflow | ||
if: success() | ||
run: | | ||
# Get the source branch of the PR (from the pull_request object) | ||
PR_BRANCH="${{ github.event.pull_request.head.ref }}" | ||
# Define the API endpoint for dispatching the workflow | ||
WORKFLOW_URL="https://api.github.com/repos/${{ github.repository }}/actions/workflows/build.yml/dispatches" | ||
# Trigger the workflow for the branch of the pull request | ||
echo "Triggering workflow for branch: $PR_BRANCH" | ||
RESPONSE=$(curl -s -w "%{http_code}" -o response.json -X POST \ | ||
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | ||
-d '{"ref": "refs/heads/'${PR_BRANCH}'", "inputs": {"sha": "${{ github.event.review.commit_id }}"}}' \ | ||
"$WORKFLOW_URL") | ||
# Check if the HTTP status code is 2xx (successful) | ||
if [[ "$RESPONSE" -lt 200 || "$RESPONSE" -ge 300 ]]; then | ||
echo "Error triggering the workflow: HTTP $RESPONSE" | ||
cat response.json | ||
exit 1 | ||
else | ||
echo "Successfully triggered the workflow." | ||
fi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
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" |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.