Skip to content

Commit

Permalink
🔨 Add linux shell
Browse files Browse the repository at this point in the history
  • Loading branch information
17TheWord committed Feb 14, 2025
1 parent c6e3e24 commit 6080563
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 43 deletions.
84 changes: 41 additions & 43 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,89 +11,87 @@ permissions:

env:
GH_TOKEN: ${{ github.token }}
USERNAME: ${{ github.actor }}
PACKAGE_READ_ONLY_TOKEN: ${{ secrets.PACKAGE_READ_ONLY_TOKEN }}
JAVA_8_LIST: '["forge-1.16.5","fabric-1.16.5"]'
JAVA_17_LIST: '["fabric-1.18.2","fabric-1.19.1","fabric-1.19.2","fabric-1.19.3","fabric-1.19.4","fabric-1.20","fabric-1.20.3","forge-1.18.2","forge-1.19","forge-1.20","forge-1.20.2","forge-1.20.3"]'
JAVA_21_LIST: '["fabric-1.20.5","fabric-1.21","fabric-1.21.2","fabric-1.21.4","neoforge-1.20.2","neoforge-1.20.3","neoforge-1.20.4","neoforge-1.20.5","neoforge-1.21.0","neoforge-1.21.2","neoforge-1.21.4"]'

jobs:
generate-matrix:
runs-on: windows-latest
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- name: Generate Matrix
id: set-matrix
shell: pwsh
run: .\matrix.ps1 -path "fabric","forge","spigot","velocity","minecraft","neoforge"
run: chmod 777 matrix.sh && ./matrix.sh -path "fabric","forge","spigot","velocity","minecraft","neoforge"

build:
runs-on: windows-latest
runs-on: ubuntu-latest
needs:
- generate-matrix
strategy:
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
steps:
- uses: actions/checkout@v4
- name: Chose JDK 21

- name: Chose JDK 8
uses: actions/setup-java@v4
if: contains(env.JAVA_8_LIST, format('{0}-{1}', matrix.config.mc-loader,matrix.config.mc-version))
with:
java-version: '21'
java-version: '8'
distribution: 'temurin'

- name: Cache Gradle dependencies
uses: actions/cache@v2
- name: Chose JDK 17
uses: actions/setup-java@v4
if: contains(env.JAVA_17_LIST, format('{0}-{1}', matrix.config.mc-loader,matrix.config.mc-version))
with:
path: |
~/.gradle/caches
~/.gradle/wrapper/dists
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
java-version: '17'
distribution: 'temurin'

- name: Chose JDK 21
uses: actions/setup-java@v4
if: contains(env.JAVA_21_LIST, format('{0}-{1}', matrix.config.mc-loader,matrix.config.mc-version))
with:
java-version: '21'
distribution: 'temurin'

- name: Read version.txt and save to variable
shell: pwsh
run: |
$mod_version = Get-Content version.txt
Write-Host "Version: $mod_version"
echo "MOD_VERSION=$mod_version" | Out-File -Append -Encoding utf8 -FilePath $env:GITHUB_ENV
mod_version=$(cat version.txt)
echo "Version: $mod_version"
echo "MOD_VERSION=$mod_version" >> "$GITHUB_ENV"
- name: Init Files
shell: pwsh
run: ./init.ps1

- name: Run Game Test Server
if: ${{ (matrix.config.mc-loader == 'forge' || matrix.config.mc-loader == 'neoforge') && matrix.config.mc-version != '1.16.5' }}
shell: pwsh
run: |
cd ${{ matrix.config.mc-loader }}/${{ matrix.config.mc-loader }}-${{ matrix.config.mc-version }}
echo Y | ./gradlew runGameTestServer # Automate "Y" input for prompts
cd ../..
run: chmod 777 init.sh && ./init.sh

- name: Build
- name: Build Mod
env:
USERNAME: ${{ github.actor }}
PACKAGE_READ_ONLY_TOKEN: ${{ secrets.PACKAGE_READ_ONLY_TOKEN }}
run: |
cd ${{ matrix.config.mc-loader }}/${{ matrix.config.mc-loader }}-${{ matrix.config.mc-version }}
chmod 777 gradlew
./gradlew clean build
cd ../..
- name: Set Version Type
id: set-version-type
shell: pwsh
run: |
if ($env:GITHUB_REF -eq 'refs/heads/main') {
echo "VERSION_TYPE=release" | Out-File -Append -Encoding utf8 -FilePath $env:GITHUB_ENV
} else {
echo "VERSION_TYPE=beta" | Out-File -Append -Encoding utf8 -FilePath $env:GITHUB_ENV
}
if [ "${GITHUB_REF}" == "refs/heads/main" ]; then
echo "VERSION_TYPE=release" >> $GITHUB_ENV
else
echo "VERSION_TYPE=beta" >> $GITHUB_ENV
fi
- name: Set Game Version
id: set-game-version
shell: pwsh
run: |
if ("${{ matrix.config.mc-loader }}" -eq 'velocity') {
echo "game_version=1.20.1" | Out-File -Append -Encoding utf8 -FilePath $env:GITHUB_ENV
} else {
echo "game_version=${{ matrix.config.mc-version }}" | Out-File -Append -Encoding utf8 -FilePath $env:GITHUB_ENV
}
if [ "${{ matrix.config.mc-loader }}" == "velocity" ]; then
echo "game_version=1.20.1" >> $GITHUB_ENV
else
echo "game_version=${{ matrix.config.mc-version }}" >> $GITHUB_ENV
fi
- uses: actions/upload-artifact@v4
with:
Expand Down
9 changes: 9 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

file=$(find tool -name "ModMultiVersionTool*.jar" | head -n 1)

if [ -n "$file" ]; then
java -jar "$file"
else
echo "can't find ModMultiVersionTool.jar"
fi
52 changes: 52 additions & 0 deletions matrix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

while [[ $# -gt 0 ]]; do
case $1 in
-path)
IFS=',' read -r -a paths <<< "$2"
shift 2
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done

# 用于存储所有文件夹的数组
allFolderObjects=()

# 遍历每个路径
for path in "${paths[@]}"; do
# 获取指定路径下的文件夹
folders=$(find "$path" -mindepth 1 -maxdepth 1 -type d)

# 过滤掉名为 "origin" 的文件夹
for folder in $folders; do
folderName=$(basename "$folder")
if [[ "$folderName" != "origin" ]]; then
# 提取 mc-version 和 mc-loader 信息
mcVersion="${folderName//$path-/}"
mcLoader="$path"
supportVersionFile="$mcLoader/$mcLoader-$mcVersion/support_version.txt"
if [[ -f "$supportVersionFile" ]]; then
supportVersion=$(cat "$supportVersionFile")
else
supportVersion="$mcVersion"
fi

if [ "$mcLoader" == "fabric" ]; then
publishLoaders="fabric quilt"
else
publishLoaders="$mcLoader"
fi
allFolderObjects+=("{\"mc-version\": \"$mcVersion\", \"mc-loader\": \"$mcLoader\", \"publish-loaders\": \"$publishLoaders\", \"publish-version\": \"$supportVersion\"}")
fi
done
done

# 创建 JSON 格式的输出
json=$(printf "{\"config\":[%s]}" "$(IFS=,; echo "${allFolderObjects[*]}")")

# 输出最终的 JSON 结果
echo "matrix=$json" >> $GITHUB_OUTPUT

0 comments on commit 6080563

Please sign in to comment.