Commit eb9872b2 by Jonathan Thomas

Fixed CurseForge deploy script to be much faster, and correctly lookup valid Type and Version IDs

parent fa3a5d72
Pipeline #12655 passed with stages
in 1 minute 55 seconds
...@@ -4,6 +4,11 @@ All notable changes to **CreatureChat** are documented in this file. The format ...@@ -4,6 +4,11 @@ All notable changes to **CreatureChat** are documented in this file. The format
[Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html). [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Changed
- Fixed CurseForge deploy script to be much faster, and correctly lookup valid Type and Version IDs
## [1.0.7] - 2024-07-03 ## [1.0.7] - 2024-07-03
### Added ### Added
......
...@@ -8,19 +8,58 @@ API_URL="https://minecraft.curseforge.com/api" ...@@ -8,19 +8,58 @@ API_URL="https://minecraft.curseforge.com/api"
PROJECT_ID=1012118 PROJECT_ID=1012118
DEPENDENCY_SLUG="fabric-api" DEPENDENCY_SLUG="fabric-api"
USER_AGENT="CreatureChat-Minecraft-Mod:curseforge@owlmaddie.com" USER_AGENT="CreatureChat-Minecraft-Mod:curseforge@owlmaddie.com"
SLEEP_DURATION=30 SLEEP_DURATION=5
# Function to fetch game version IDs # Function to fetch version types and return the base game type ID
fetch_base_version_id() {
local base_version="$1"
local version_types_cache="/tmp/version_types.json"
if [ ! -f "$version_types_cache" ]; then
curl --retry 3 --retry-delay 5 -s -H "X-Api-Token: $CURSEFORGE_API_KEY" "$API_URL/game/version-types" > "$version_types_cache"
fi
local version_types_response=$(cat "$version_types_cache")
local base_version_id=$(echo "$version_types_response" | jq -r --arg base_version "Minecraft $base_version" '.[] | select(.name == $base_version) | .id')
if [ -z "$base_version_id" ]; then
echo "ERROR: Base version ID not found."
exit 1
fi
echo "$base_version_id"
}
# Main function to fetch game version IDs
fetch_game_version_ids() { fetch_game_version_ids() {
local minecraft_version="$1" local minecraft_version="$1"
local response=$(curl --retry 3 --retry-delay 5 -s -H "X-Api-Token: $CURSEFORGE_API_KEY" "$API_URL/game/versions") local base_version=$(echo "$minecraft_version" | grep -oE '^[0-9]+\.[0-9]+')
# Fetch the base version ID
local base_version_id=$(fetch_base_version_id "$base_version")
# Cache the game versions JSON data
local game_versions_cache="/tmp/game_versions.json"
if [ ! -f "$game_versions_cache" ]; then
curl --retry 3 --retry-delay 5 -s -H "X-Api-Token: $CURSEFORGE_API_KEY" "$API_URL/game/versions" > "$game_versions_cache"
fi
local response=$(cat "$game_versions_cache")
# Find the specific version ID from the cached data
local minecraft_id=$(echo "$response" | jq -r --arg base_version_id "$base_version_id" --arg full_version "$minecraft_version" '.[] | select(.gameVersionTypeID == ($base_version_id | tonumber) and .name == $full_version) | .id' | head -n 1)
if [ -z "$minecraft_id" ]; then
echo "ERROR: Minecraft version ID not found."
exit 1
fi
# Retrieve the other IDs as before
local client_id=$(echo "$response" | jq -r '.[] | select(.name == "Client") | .id') local client_id=$(echo "$response" | jq -r '.[] | select(.name == "Client") | .id')
local server_id=$(echo "$response" | jq -r '.[] | select(.name == "Server") | .id') local server_id=$(echo "$response" | jq -r '.[] | select(.name == "Server") | .id')
local fabric_id=$(echo "$response" | jq -r '.[] | select(.name == "Fabric") | .id') local fabric_id=$(echo "$response" | jq -r '.[] | select(.name == "Fabric") | .id')
local minecraft_id=$(echo "$response" | jq -r --arg mv "$minecraft_version" '.[] | select(.name == $mv) | .id' | head -n 1)
if [ -z "$client_id" ] || [ -z "$server_id" ] || [ -z "$fabric_id" ] || [ -z "$minecraft_id" ]; then if [ -z "$client_id" ] || [ -z "$server_id" ] || [ -z "$fabric_id" ]; then
echo "ERROR: One or more game version IDs not found." echo "ERROR: One or more game version IDs not found."
exit 1 exit 1
fi fi
...@@ -64,14 +103,19 @@ for FILE in creaturechat*.jar; do ...@@ -64,14 +103,19 @@ for FILE in creaturechat*.jar; do
echo "Preparing to upload $FILE_BASENAME as version $VERSION_NUMBER..." echo "Preparing to upload $FILE_BASENAME as version $VERSION_NUMBER..."
# Fetch game version IDs # Fetch game version IDs
GAME_TYPE_ID=$(fetch_base_version_id "$MINECRAFT_VERSION")
GAME_VERSION_IDS=($(fetch_game_version_ids "$MINECRAFT_VERSION")) GAME_VERSION_IDS=($(fetch_game_version_ids "$MINECRAFT_VERSION"))
# DEBUG
echo "Minecraft Type ID: $GAME_TYPE_ID"
echo "Minecraft Versions IDs (client_id: ${GAME_VERSION_IDS[0]}, server_id: ${GAME_VERSION_IDS[1]}, fabric_id: ${GAME_VERSION_IDS[2]}, minecraft_id: ${GAME_VERSION_IDS[3]})"
# Create a new version payload # Create a new version payload
PAYLOAD=$(jq -n --arg changelog "$CHANGELOG" \ PAYLOAD=$(jq -n --arg changelog "$CHANGELOG" \
--arg changelogType "markdown" \ --arg changelogType "markdown" \
--arg displayName "$FILE_BASENAME" \ --arg displayName "$FILE_BASENAME" \
--argjson gameVersions "$(printf '%s\n' "${GAME_VERSION_IDS[@]}" | jq -R . | jq -s .)" \ --argjson gameVersions "$(printf '%s\n' "${GAME_VERSION_IDS[@]}" | jq -R . | jq -s .)" \
--argjson gameVersionTypeIds '[75125]' \ --argjson gameVersionTypeIds "[$GAME_TYPE_ID]" \
--arg releaseType "release" \ --arg releaseType "release" \
--argjson relations '[{"slug": "'"$DEPENDENCY_SLUG"'", "type": "requiredDependency"}]' \ --argjson relations '[{"slug": "'"$DEPENDENCY_SLUG"'", "type": "requiredDependency"}]' \
'{ '{
......
...@@ -8,7 +8,7 @@ API_URL="https://api.modrinth.com/v2" ...@@ -8,7 +8,7 @@ API_URL="https://api.modrinth.com/v2"
USER_AGENT="CreatureChat-Minecraft-Mod:modrinth@owlmaddie.com" USER_AGENT="CreatureChat-Minecraft-Mod:modrinth@owlmaddie.com"
PROJECT_ID="rvR0de1E" PROJECT_ID="rvR0de1E"
AUTHOR_ID="k6RiShdd" AUTHOR_ID="k6RiShdd"
SLEEP_DURATION=10 SLEEP_DURATION=5
# Read the first changelog block # Read the first changelog block
CHANGELOG=$(awk '/^## \[/{ if (p) exit; p=1 } p' "$CHANGELOG_FILE") CHANGELOG=$(awk '/^## \[/{ if (p) exit; p=1 } p' "$CHANGELOG_FILE")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment