forked from minecraft-access/minecraft-access
-
Notifications
You must be signed in to change notification settings - Fork 0
156 lines (141 loc) · 6.09 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# 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
NEOFORGE_PATH: neoforge/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 neoforge build files with mv command
# Copy build files into upload directory
run: |
upload_path=${{ github.WORKSPACE }}/${{ env.UPLOAD_PATH }}
mkdir -p ${upload_path}
fabric_lib_path=${{ github.WORKSPACE }}/${{ env.FABRIC_PATH }}
neoforge_lib_path=${{ github.WORKSPACE }}/${{ env.NEOFORGE_PATH }}
if [ -d ${fabric_lib_path} ]; then
cd ${fabric_lib_path}
for f in *.jar; do mv -- "$f" "${f%.jar}-fabric.jar"; done
cp *.jar ${upload_path}
fi
if [ -d ${neoforge_lib_path} ]; then
cd ${{ github.WORKSPACE }}/${{ env.NEOFORGE_PATH }}
for f in *.jar; do mv -- "$f" "${f%.jar}-neoforge.jar"; done
cp *.jar ${upload_path}
fi
- 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 neoforge mod files with cp command
# Copy mod files into upload directory
run: |
mkdir -p ${{ env.UPLOAD_PATH }}
fabric_mod_path=${{ env.FABRIC_PATH }}/${{ env.MOD_FILE_PREFIX }}${{ env.MOD_VERSION }}.jar
neoforge_mod_path=${{ env.NEOFORGE_PATH }}/${{ env.MOD_FILE_PREFIX }}${{ env.MOD_VERSION }}.jar
upload_path=${{ env.UPLOAD_PATH }}/${{ env.MOD_FILE_PREFIX }}${{ env.MOD_VERSION }}
if [ -f ${fabric_mod_path} ]; then
mv ${fabric_mod_path} ${upload_path}-fabric.jar
fi
if [ -f ${neoforge_mod_path} ]; then
mv ${neoforge_mod_path} ${upload_path}-neoforge.jar
fi
# 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@v4
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 }}