Skip to content

Commit

Permalink
update release workflow, to update forge version json
Browse files Browse the repository at this point in the history
add yml to editorconfig
  • Loading branch information
fayer3 committed Oct 8, 2023
1 parent e52c7a9 commit 23b1d5a
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 30 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ ij_smart_tabs = false
ij_visual_guides = none
ij_wrap_on_typing = false

[{*.yml,*.yaml}]
indent_size = 2
ij_yaml_align_values_properties = do_not_align
ij_yaml_autoinsert_sequence_marker = true
ij_yaml_block_mapping_on_new_line = false
ij_yaml_indent_sequence_value = true
ij_yaml_keep_indents_on_empty_lines = false
ij_yaml_keep_line_breaks = true
ij_yaml_sequence_on_new_line = false
ij_yaml_space_before_colon = false
ij_yaml_spaces_within_braces = true
ij_yaml_spaces_within_brackets = true

[{*.vrmanifest,*.har,*.jsb2,*.jsb3,*.json,*.png.mcmeta,.babelrc,.eslintrc,.stylelintrc,bowerrc,jest.config,mcmod.info,pack.mcmeta}]
indent_size = 2
ij_json_array_wrapping = on_every_item
Expand Down
155 changes: 125 additions & 30 deletions .github/workflows/publish-on-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ run-name: Posting jars on Curseforge and Modrinth

on:
release:
types: [published]
types: [ published ]

jobs:
publish:
Expand All @@ -25,7 +25,7 @@ jobs:
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
Expand All @@ -48,6 +48,33 @@ jobs:
id: version
shell: bash
run: |
parse_fabric () {
unzip -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
}
file=""
if [ -n "${{ steps.assets.outputs.FABRIC_FILE_NAME }}" ]; then
file="${{ steps.assets.outputs.FABRIC_FILE_NAME }}"
Expand All @@ -57,7 +84,7 @@ jobs:
file="${{ steps.assets.outputs.QUILT_FILE_NAME }}"
fi
echo $file
# save the current IFS value
OLDIFS=$IFS
# set the IFS to the delimiter ("-")
Expand All @@ -66,24 +93,24 @@ jobs:
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
Expand All @@ -93,39 +120,67 @@ jobs:
loaders_quilt="quilt"
fi
loaders_forge="forge"
echo mc version: $mc_version
echo "MC_VERSION=$mc_version" >> $GITHUB_OUTPUT
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
unzip -j "${{ steps.assets.outputs.FORGE_FILE_NAME }}" "META-INF/mods.toml" -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
echo "FORGE_MC_VERSIONS="${BASH_REMATCH[1]}"" >> $GITHUB_OUTPUT
echo ${BASH_REMATCH[0]}
echo ${BASH_REMATCH[1]}
fi
done < ./forge/mods.toml
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 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 quilt: "${mod_name}-quilt"
echo "VERSION_NAME_QUILT=${mod_name}-quilt" >> $GITHUB_OUTPUT
# modrinth mod versions
base_version="$mc_version-${array[2]}"
echo md version fabric: "${base_version}-fabric"
echo "MD_VERSION_FABRIC=${base_version}-fabric" >> $GITHUB_OUTPUT
echo md version forge: "${base_version}-forge"
echo "MD_VERSION_FORGE=${base_version}-forge" >> $GITHUB_OUTPUT
echo md version fquilt: "${base_version}-quilt"
echo "MD_VERSION_QUILT=${base_version}-quilt" >> $GITHUB_OUTPUT
- run: echo Minecraft target version is ${{ steps.version.outputs.MC_VERSION }}
echo "MOD_VERSION_FABRIC=${base_version}-fabric" >> $GITHUB_OUTPUT
echo "MOD_VERSION_FORGE=${base_version}-forge" >> $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 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]
Expand All @@ -140,11 +195,11 @@ jobs:
files-primary: ${{ steps.assets.outputs.FABRIC_FILE_PATH }}

name: "${{ steps.version.outputs.VERSION_NAME_FABRIC }}"
version: "${{ steps.version.outputs.MD_VERSION_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.MC_VERSION }}"
game-versions: "${{ steps.version.outputs.FABRIC_MC_VERSIONS }}"

- name: publish forge
if: steps.assets.outputs.FORGE_FILE_PATH != ''
Expand All @@ -160,11 +215,11 @@ jobs:
files-primary: ${{ steps.assets.outputs.FORGE_FILE_PATH }}

name: "${{ steps.version.outputs.VERSION_NAME_FORGE }}"
version: "${{ steps.version.outputs.MD_VERSION_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.MC_VERSION }}"
game-versions: "${{ steps.version.outputs.FORGE_MC_VERSIONS }}"

- name: publish quilt
if: steps.assets.outputs.QUILT_FILE_PATH != ''
Expand All @@ -180,8 +235,48 @@ jobs:
files-primary: ${{ steps.assets.outputs.QUILT_FILE_PATH }}

name: "${{ steps.version.outputs.VERSION_NAME_QUILT }}"
version: "${{ steps.version.outputs.MD_VERSION_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.MC_VERSION }}"
game-versions: "${{ steps.version.outputs.QUILT_MC_VERSIONS }}"

# update forge versions json
- name: checkout repo forge-versions
if: steps.assets.outputs.FORGE_FILE_PATH != ''
uses: actions/checkout@v4
with:
ref: 'forge-versions'

- name: setup python
if: steps.assets.outputs.FORGE_FILE_PATH != ''
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: execute py script to update 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]
jsonContent = {}
with open('forge_updates.json', 'r') as infile:
jsonContent = json.load(infile)
for str in mc_version.split(','):
version = str.strip('[]\" ')
if version != '':
jsonContent['promos'][version + '-latest'] = mod_version
jsonContent['promos'][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 }}"
- name: push new update json
if: steps.assets.outputs.FORGE_FILE_PATH != ''
uses: EndBug/add-and-commit@v9
with:
message: 'update ${{ steps.version.outputs.FORGE_MC_VERSIONS }} to ${{ steps.version.outputs.MOD_VERSION }}'
push: true

0 comments on commit 23b1d5a

Please sign in to comment.