Skip to content

Posting jars on Curseforge and Modrinth #111

Posting jars on Curseforge and Modrinth

Posting jars on Curseforge and Modrinth #111

name: curseforge-modrinth-publish
run-name: Posting jars on Curseforge and Modrinth
on:
release:
types: [ published ]
jobs:
publish:
runs-on: ubuntu-22.04
steps:
- name: fetching asset paths
id: assets
shell: bash
run: |
echo Attachments
fileNames=(${{ github.event.release.assets[0].name }} ${{ github.event.release.assets[1].name }} ${{ github.event.release.assets[2].name }})
filePaths=(${{ github.event.release.assets[0].browser_download_url }} ${{ github.event.release.assets[1].browser_download_url }} ${{ github.event.release.assets[2].browser_download_url }})
for i in 0 1 2 3
do
echo "${fileNames[i]}"
echo "${filePaths[i]}"
if [ -n "${filePaths[i]}" ]; then
curl -L -o "./${fileNames[i]}" "${filePaths[i]}"
fi
if [[ "${fileNames[i]}" == *"fabric"* ]]; then
echo "FABRIC_FILE_NAME=${fileNames[i]}" >> $GITHUB_OUTPUT
echo "FABRIC_FILE_PATH=./${fileNames[i]}" >> $GITHUB_OUTPUT
elif [[ "${fileNames[i]}" == *"neoforge"* ]]; then
echo "NEOFORGE_FILE_NAME=${fileNames[i]}" >> $GITHUB_OUTPUT
echo "NEOFORGE_FILE_PATH=./${fileNames[i]}" >> $GITHUB_OUTPUT
elif [[ "${fileNames[i]}" == *"forge"* ]]; then
echo "FORGE_FILE_NAME=${fileNames[i]}" >> $GITHUB_OUTPUT
echo "FORGE_FILE_PATH=./${fileNames[i]}" >> $GITHUB_OUTPUT
elif [[ "${fileNames[i]}" == *"quilt"* ]]; then
echo "QUILT_FILE_NAME=${fileNames[i]}" >> $GITHUB_OUTPUT
echo "QUILT_FILE_PATH=./${fileNames[i]}" >> $GITHUB_OUTPUT
fi
done
ls -l
- run: echo "fabric is ${{ steps.assets.outputs.FABRIC_FILE_NAME }}"
- run: echo "neoforge is ${{ steps.assets.outputs.NEOFORGE_FILE_NAME }}"
- run: echo "forge is ${{ steps.assets.outputs.FORGE_FILE_NAME }}"
- run: echo "quilt is ${{ steps.assets.outputs.QUILT_FILE_NAME }}"
- name: getting version info from files
id: version
shell: bash
run: |
parse_fabric () {
unzip -o -j "$1" "$2" -d ./fabric
deps=false
bracket=false
parsedVersion=""
depReg='\s+"depends"'
minecraftVersionReg='\s*?"minecraft":\s*?(.+?)*'
wordReg="(.*?),*"
bracketReg="(.*])"
while read -r; do
if [[ $REPLY =~ $depReg ]]; then
deps=true
elif [[ $REPLY =~ $minecraftVersionReg && $deps == "true" ]]; then
if [[ ${BASH_REMATCH[1]} =~ $wordReg ]]; then
parsedVersion=${BASH_REMATCH[1]}
if [[ ${BASH_REMATCH[1]} == "[" ]]; then
bracket=true
fi
fi
elif [[ $bracket == "true" && $REPLY != *"]"* ]]; then
parsedVersion=${parsedVersion}$REPLY
elif [[ $bracket == "true" && $REPLY =~ $bracketReg ]]; then
parsedVersion=${parsedVersion}${BASH_REMATCH[1]}
bracket=false
fi
done < ./fabric/$2
}
parse_forge () {
unzip -o -j "$1" "META-INF/$2" -d ./forge
minecraftDep=false
minecraftIdReg='modId\s+=\s+"minecraft"'
versionRangeReg='versionRange\s+=\s+"(.+?)"'
while read -r; do
if [[ $REPLY =~ $minecraftIdReg ]]; then
minecraftDep=true
echo "$REPLY"
elif [[ $REPLY =~ $versionRangeReg && $minecraftDep == "true" ]]; then
parsedVersion="${BASH_REMATCH[1]}"
echo "${BASH_REMATCH[0]}"
echo "${BASH_REMATCH[1]}"
fi
done < ./forge/$2
}
file=""
if [ -n "${{ steps.assets.outputs.FABRIC_FILE_NAME }}" ]; then
file="${{ steps.assets.outputs.FABRIC_FILE_NAME }}"
elif [ -n "${{ steps.assets.outputs.FORGE_FILE_NAME }}" ]; then
file="${{ steps.assets.outputs.FORGE_FILE_NAME }}"
elif [ -n "${{ steps.assets.outputs.NEOFORGE_FILE_NAME }}" ]; then
file="${{ steps.assets.outputs.NEOFORGE_FILE_NAME }}"
else
file="${{ steps.assets.outputs.QUILT_FILE_NAME }}"
fi
echo "$file"
# save the current IFS value
OLDIFS=$IFS
# set the IFS to the delimiter ("-")
IFS="-"
# split the string into an array, limiting it to a maximum of 3 fields
array=($file)
# restore the IFS value
IFS=$OLDIFS
# alphas or beats should be included in the version
if [ ${array[3]:0:1} = "a" ] || [ ${array[3]:0:1} = "b" ]; then
array[2]=${array[2]}-${array[3]}
fi
release_type="release"
if [ ${array[3]:0:1} = "a" ]; then
release_type="alpha"
elif [ ${array[3]:0:1} = "b" ]; then
release_type="beta"
fi
echo "release type: ${release_type}"
echo "RELEASE_TYPE=${release_type}" >> $GITHUB_OUTPUT
mc_version=${array[1]}
# mod loaders
loaders_fabric=fabric
# check if there is a quilt specific jar
if [ -z "${{ steps.assets.outputs.QUILT_FILE_NAME }}" ]; then
loaders_fabric="${loaders_fabric} quilt"
else
loaders_quilt="quilt"
fi
loaders_forge="forge"
loaders_neoforge="neoforge"
if [ -n "${{ steps.assets.outputs.FABRIC_FILE_NAME }}" ]; then
parse_fabric ${{ steps.assets.outputs.FABRIC_FILE_NAME }} "fabric.mod.json"
echo "FABRIC_MC_VERSIONS="${parsedVersion}"" >> $GITHUB_OUTPUT
fi
if [ -n "${{ steps.assets.outputs.FORGE_FILE_NAME }}" ]; then
parse_forge ${{ steps.assets.outputs.FORGE_FILE_NAME }} "mods.toml"
echo "FORGE_MC_VERSIONS="${parsedVersion}"" >> $GITHUB_OUTPUT
fi
if [ -n "${{ steps.assets.outputs.NEOFORGE_FILE_NAME }}" ]; then
parse_forge ${{ steps.assets.outputs.NEOFORGE_FILE_NAME }} "neoforge.mods.toml"
echo "NEOFORGE_MC_VERSIONS="${parsedVersion}"" >> $GITHUB_OUTPUT
fi
if [ -n "${{ steps.assets.outputs.QUILT_FILE_NAME }}" ]; then
parse_fabric ${{ steps.assets.outputs.QUILT_FILE_NAME }} "quilt.mod.json"
echo "QUILT_MC_VERSIONS="${parsedVersion}"" >> $GITHUB_OUTPUT
fi
echo "loaders fabric: ${loaders_fabric}"
echo "LOADERS_FABRIC=${loaders_fabric}" >> $GITHUB_OUTPUT
echo "loaders forge: ${loaders_forge}"
echo "LOADERS_FORGE=${loaders_forge}" >> $GITHUB_OUTPUT
echo "loaders neoforge: ${loaders_neoforge}"
echo "LOADERS_NEOFORGE=${loaders_neoforge}" >> $GITHUB_OUTPUT
echo "loaders quilt: ${loaders_quilt}"
echo "LOADERS_QUILT=${loaders_quilt}" >> $GITHUB_OUTPUT
mod_name="${array[0]^} $mc_version-${array[2]}"
echo "file name fabric: '${mod_name}-fabric'"
echo "VERSION_NAME_FABRIC=${mod_name}-fabric" >> $GITHUB_OUTPUT
echo "file name forge: '${mod_name}-forge'"
echo "VERSION_NAME_FORGE=${mod_name}-forge" >> $GITHUB_OUTPUT
echo "file name neoforge: '${mod_name}-neoforge'"
echo "VERSION_NAME_NEOFORGE=${mod_name}-neoforge" >> $GITHUB_OUTPUT
echo "file name quilt: '${mod_name}-quilt'"
echo "VERSION_NAME_QUILT=${mod_name}-quilt" >> $GITHUB_OUTPUT
# modrinth mod versions
base_version="$mc_version-${array[2]}"
echo "MOD_VERSION_FABRIC=${base_version}-fabric" >> $GITHUB_OUTPUT
echo "MOD_VERSION_FORGE=${base_version}-forge" >> $GITHUB_OUTPUT
echo "MOD_VERSION_NEOFORGE=${base_version}-neoforge" >> $GITHUB_OUTPUT
echo "MOD_VERSION_QUILT=${base_version}-quilt" >> $GITHUB_OUTPUT
echo "MOD_VERSION=${base_version}" >> $GITHUB_OUTPUT
- run: echo "release type is ${{ steps.version.outputs.RELEASE_TYPE }}"
- run: echo "fabric mc versions are ${{ steps.version.outputs.FABRIC_MC_VERSIONS }}"
- run: echo "fabric mod version ${{ steps.version.outputs.MOD_VERSION_FABRIC }}"
- run: echo "forge mc versions are ${{ steps.version.outputs.FORGE_MC_VERSIONS }}"
- run: echo "forge mod version ${{ steps.version.outputs.MOD_VERSION_FORGE }}"
- run: echo "neoforge mc versions are ${{ steps.version.outputs.NEOFORGE_MC_VERSIONS }}"
- run: echo "neoforge mod version ${{ steps.version.outputs.MOD_VERSION_NEOFORGE }}"
- run: echo "quilt mc versions are ${{ steps.version.outputs.QUILT_MC_VERSIONS }}"
- run: echo "quilt mod version ${{ steps.version.outputs.MOD_VERSION_QUILT }}"
- name: publish fabric
if: steps.assets.outputs.FABRIC_FILE_PATH != ''
uses: Kir-Antipov/[email protected]
with:
modrinth-id: wGoQDPN5
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
modrinth-featured: false
curseforge-id: 667903
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
files: ${{ steps.assets.outputs.FABRIC_FILE_PATH }}
name: "${{ steps.version.outputs.VERSION_NAME_FABRIC }}"
version: "${{ steps.version.outputs.MOD_VERSION_FABRIC }}"
version-type: "${{ steps.version.outputs.RELEASE_TYPE }}"
loaders: "${{ steps.version.outputs.LOADERS_FABRIC }}"
#game-versions: "${{ steps.version.outputs.FABRIC_MC_VERSIONS }}"
- name: publish forge
if: steps.assets.outputs.FORGE_FILE_PATH != ''
uses: Kir-Antipov/[email protected]
with:
modrinth-id: wGoQDPN5
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
modrinth-featured: false
curseforge-id: 667903
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
files: ${{ steps.assets.outputs.FORGE_FILE_PATH }}
name: "${{ steps.version.outputs.VERSION_NAME_FORGE }}"
version: "${{ steps.version.outputs.MOD_VERSION_FORGE }}"
version-type: "${{ steps.version.outputs.RELEASE_TYPE }}"
loaders: "${{ steps.version.outputs.LOADERS_FORGE}}"
#game-versions: "${{ steps.version.outputs.FORGE_MC_VERSIONS }}"
- name: publish neoforge
if: steps.assets.outputs.NEOFORGE_FILE_PATH != ''
uses: Kir-Antipov/[email protected]
with:
modrinth-id: wGoQDPN5
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
modrinth-featured: false
curseforge-id: 667903
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
files: ${{ steps.assets.outputs.NEOFORGE_FILE_PATH }}
name: "${{ steps.version.outputs.VERSION_NAME_NEOFORGE }}"
version: "${{ steps.version.outputs.MOD_VERSION_NEOFORGE }}"
version-type: "${{ steps.version.outputs.RELEASE_TYPE }}"
loaders: "${{ steps.version.outputs.LOADERS_NEOFORGE}}"
#game-versions: "${{ steps.version.outputs.FORGE_MC_VERSIONS }}"
- name: publish quilt
if: steps.assets.outputs.QUILT_FILE_PATH != ''
uses: Kir-Antipov/[email protected]
with:
modrinth-id: wGoQDPN5
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
modrinth-featured: false
curseforge-id: 667903
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
files: ${{ steps.assets.outputs.QUILT_FILE_PATH }}
name: "${{ steps.version.outputs.VERSION_NAME_QUILT }}"
version: "${{ steps.version.outputs.MOD_VERSION_QUILT}}"
version-type: "${{ steps.version.outputs.RELEASE_TYPE }}"
loaders: "${{ steps.version.outputs.LOADERS_QUILT}}"
#game-versions: "${{ steps.version.outputs.QUILT_MC_VERSIONS }}"
# update forge versions json
- name: checkout repo forge-versions
if: steps.assets.outputs.FORGE_FILE_PATH != '' || steps.assets.outputs.NEOFORGE_FILE_PATH != ''
uses: actions/checkout@v4
with:
ref: 'forge-versions'
- name: setup python
if: steps.assets.outputs.FORGE_FILE_PATH != '' || steps.assets.outputs.NEOFORGE_FILE_PATH != ''
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: execute py script to update forge json
if: steps.assets.outputs.FORGE_FILE_PATH != ''
run: |
python -c "
import sys, json
print(sys.argv)
mc_version = sys.argv[1]
mod_version = sys.argv[2]
release_type = sys.argv[3]
jsonContent = {}
with open('forge_updates.json', 'r') as infile:
jsonContent = json.load(infile)
for str in mc_version.split(','):
version = str.strip('[]\" ')
if version != '' and version[-1:] != ')' and version[:1] != '(':
jsonContent['promos'][version + '-latest'] = mod_version
print('added ' + version + '-latest:' + mod_version)
if release_type == 'release':
jsonContent['promos'][version + '-recommended'] = mod_version
print('added ' + version + '-recommended:' + mod_version)
print(json.dumps(jsonContent, indent='\t'))
with open('forge_updates.json', 'w') as outfile:
outfile.write(json.dumps(jsonContent, indent='\t'))
" "${{ steps.version.outputs.FORGE_MC_VERSIONS }}" "${{ steps.version.outputs.MOD_VERSION }}" "${{ steps.version.outputs.RELEASE_TYPE }}"
- name: execute py script to update neoforge json
if: steps.assets.outputs.NEOFORGE_FILE_PATH != ''
run: |
python -c "
import sys, json
print(sys.argv)
mc_version = sys.argv[1]
mod_version = sys.argv[2]
release_type = sys.argv[3]
jsonContent = {}
with open('neoforge_updates.json', 'r') as infile:
jsonContent = json.load(infile)
for str in mc_version.split(','):
version = str.strip('[]\" ')
if version != '' and version[-1:] != ')' and version[:1] != '(':
jsonContent['promos'][version + '-latest'] = mod_version
print('added ' + version + '-latest:' + mod_version)
if release_type == 'release':
jsonContent['promos'][version + '-recommended'] = mod_version
print('added ' + version + '-recommended:' + mod_version)
print(json.dumps(jsonContent, indent='\t'))
with open('neoforge_updates.json', 'w') as outfile:
outfile.write(json.dumps(jsonContent, indent='\t'))
" "${{ steps.version.outputs.NEOFORGE_MC_VERSIONS }}" "${{ steps.version.outputs.MOD_VERSION }}" "${{ steps.version.outputs.RELEASE_TYPE }}"
- name: push new update json forge
if: steps.assets.outputs.FORGE_FILE_PATH != '' && steps.assets.outputs.NEOFORGE_FILE_PATH == ''
uses: EndBug/add-and-commit@v9
with:
message: 'update forge ${{ steps.version.outputs.FORGE_MC_VERSIONS }} to ${{ steps.version.outputs.MOD_VERSION }}'
push: true
- name: push new update json neoforge
if: steps.assets.outputs.FORGE_FILE_PATH == '' && steps.assets.outputs.NEOFORGE_FILE_PATH != ''
uses: EndBug/add-and-commit@v9
with:
message: 'update neoforge ${{ steps.version.outputs.NEOFORGE_MC_VERSIONS }} to ${{ steps.version.outputs.MOD_VERSION }}'
push: true
- name: push new update json forge+neoforge
if: steps.assets.outputs.FORGE_FILE_PATH != '' && steps.assets.outputs.NEOFORGE_FILE_PATH != ''
uses: EndBug/add-and-commit@v9
with:
message: 'update forge ${{ steps.version.outputs.FORGE_MC_VERSIONS }} to ${{ steps.version.outputs.MOD_VERSION }} and update neoforge ${{ steps.version.outputs.NEOFORGE_MC_VERSIONS }} to ${{ steps.version.outputs.MOD_VERSION }}'
push: true