Build Mod Files #43
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
# For running this workflow to build previous version of mod, | |
# [lang repo](https://github.com/khanshoaib3/minecraft-access-i18n) | |
# must have same version tag (git tag) as target build version. | |
name: Build Mod Files | |
on: | |
# workflow_dispatch: You can trigger it manually from the Actions page | |
# ref: https://docs.github.com/en/actions/using-workflows/manually-running-a-workflow | |
workflow_dispatch: | |
inputs: | |
version: | |
default: 'latest' | |
required: false | |
description: Version to be published (git tag like 'v1.5.2-1.20.4', DO use default value to build the latest version) | |
# workflow_call: Or it will be triggered by release workflow | |
# ref: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_call | |
workflow_call: | |
inputs: | |
jdk-version: | |
required: true | |
type: string | |
build-files-cache-key: | |
required: true | |
type: string | |
version: | |
default: 'latest' | |
required: false | |
type: string | |
env: | |
FABRIC_PATH: fabric/build/libs | |
FORGE_PATH: forge/build/libs | |
MOD_FILE_PREFIX: minecraft-access- | |
UPLOAD_PATH: upload | |
JDK_VERSION: ${{ inputs.jdk-version || '21' }} | |
jobs: | |
test: | |
name: Run Test Suite | |
uses: ./.github/workflows/test.yml | |
with: | |
# Context "env" is not allowed here | |
# Available contexts are "github", "inputs", "matrix", "needs", "strategy", "vars" | |
# ref: https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability | |
jdk-version: ${{ inputs.jdk-version || '21' }} | |
build: | |
# Run build job only if test job is successfully passed | |
# ref: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idneeds | |
# | |
# ref='' for default value (HEAD of main branch) of checkout action | |
# ref: https://github.com/actions/checkout | |
name: Run Gradle Build and Preserve Build Files | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ inputs.version == 'latest' && github.ref || inputs.version }} | |
- name: Fetch Latest Lang Assert | |
if: ${{ inputs.version == 'latest' }} | |
uses: actions/checkout@v4 | |
with: | |
# ref: https://github.com/khanshoaib3/minecraft-access | |
repository: 'khanshoaib3/minecraft-access-i18n' | |
# Checkout the repo in mod's language assert path | |
path: './common/src/main/resources/assets/minecraft_access/lang' | |
- name: Fetch Lang Assert at Given Version | |
if: ${{ inputs.version != 'latest' }} | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ inputs.version }} | |
repository: 'khanshoaib3/minecraft-access-i18n' | |
path: './common/src/main/resources/assets/minecraft_access/lang' | |
- name: Remove Unnecessary Lang Repository Files | |
run: | | |
pushd . | |
cd ./common/src/main/resources/assets/minecraft_access/lang | |
ls | grep -vE "??_??\.json" | xargs rm | |
popd | |
- name: Set up JDK | |
uses: actions/setup-java@v4 | |
with: | |
java-version: ${{ env.JDK_VERSION }} | |
distribution: 'temurin' | |
cache: 'gradle' | |
- name: Build Mod with Gradle | |
run: ./gradlew build | |
- name: Set Environment Variables | |
# Get current time in YYYYMMDD-HHMMSS format | |
# Get mod version from gradle.properties | |
run: | | |
echo "BUILD_TIME=$(date +%Y%m%d-%H%M%S)" >> $GITHUB_ENV | |
echo "MOD_VERSION=$(grep "mod_version" gradle.properties | cut -d'=' -f2)" >> $GITHUB_ENV | |
- name: Move All Build Files to Upload Directory | |
if: ${{ !inputs.build-files-cache-key }} | |
# Add platform suffix for fabric and forge build files with mv command | |
# Copy build files into upload directory | |
run: | | |
mkdir -p ${{ env.UPLOAD_PATH }} | |
cd ${{ github.WORKSPACE }}/${{ env.FABRIC_PATH }} | |
for f in *.jar; do mv -- "$f" "${f%.jar}-fabric.jar"; done | |
cp *.jar "${{ github.WORKSPACE }}/${{ env.UPLOAD_PATH }}" | |
cd ${{ github.WORKSPACE }}/${{ env.FORGE_PATH }} | |
for f in *.jar; do mv -- "$f" "${f%.jar}-forge.jar"; done | |
cp *.jar "${{ github.WORKSPACE }}/${{ env.UPLOAD_PATH }}" | |
- name: Move Only Mod Files to Upload Directory | |
if: ${{ inputs.build-files-cache-key }} | |
# Remove shadow and source files for only matching mod file with in cp command | |
# Add platform suffix for fabric and forge mod files with cp command | |
# Copy mod files into upload directory | |
run: | | |
mkdir -p ${{ env.UPLOAD_PATH }} | |
mv ${{ env.FABRIC_PATH }}/${{ env.MOD_FILE_PREFIX }}${{ env.MOD_VERSION }}.jar \ | |
${{ env.UPLOAD_PATH }}/${{ env.MOD_FILE_PREFIX }}${{ env.MOD_VERSION }}-fabric.jar | |
mv ${{ env.FORGE_PATH }}/${{ env.MOD_FILE_PREFIX }}${{ env.MOD_VERSION }}.jar \ | |
${{ env.UPLOAD_PATH }}/${{ env.MOD_FILE_PREFIX }}${{ env.MOD_VERSION }}-forge.jar | |
# Then we can download them from workflow result page | |
- name: Upload Mod Files To Artifact | |
# Only run artifact upload when triggered manually | |
if: ${{ !inputs.build-files-cache-key }} | |
uses: actions/upload-artifact@v3 | |
with: | |
# Name of zip file that we download from workflow result page | |
name: minecraft-access-mod-${{ env.BUILD_TIME }} | |
path: ${{ env.UPLOAD_PATH }} | |
- name: Cache Mod Files for Publishing | |
# Only run file cache when triggered by release workflow | |
if: ${{ inputs.build-files-cache-key }} | |
uses: actions/cache/save@v4 | |
with: | |
path: ${{ env.UPLOAD_PATH }} | |
key: ${{ inputs.build-files-cache-key || env.MOD_VERSION }} |