Skip to content

Build Specific Commit #9

Build Specific Commit

Build Specific Commit #9

Workflow file for this run

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: Determine Commit SHA
id: determine_sha
run: |
if [ -z "${{ github.event.inputs.sha }}" ]; then
echo "COMMIT_SHA=${{ github.sha }}" >> $GITHUB_ENV
else
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 ${{ env.COMMIT_SHA }}"
TARGET_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
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/${{ env.COMMIT_SHA }}"
- name: Checkout the repository at SHA
uses: actions/checkout@v3
with:
ref: ${{ env.COMMIT_SHA }}
- name: Set up JDK 17
uses: actions/setup-java@v4.5.0
with:
java-version: '17'
distribution: 'adopt'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- 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()
run: |
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 }}"
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/${{ env.COMMIT_SHA }}"