Commit b906c360 by Jonathan Thomas

Merge branch 'new-deploy-ci' into 'develop'

New automated deployments to Modrinth and CurseForge

See merge request !5
parents 16f0dce0 c8122a85
Pipeline #12224 passed with stages
in 2 minutes 17 seconds
......@@ -9,7 +9,9 @@ cache:
stages:
- build
- deploy
# Build JAR files for each Minecraft & Fabric version
build_mod:
stage: build
before_script:
......@@ -62,3 +64,27 @@ build_mod:
- develop
tags:
- minecraft
# Deploy to Modrinth
Modrinth:
stage: deploy
when: manual
script:
- chmod +x ./deploy-modrinth.sh
- ./deploy-modrinth.sh
only:
- develop
tags:
- minecraft
# Deploy to CurseForge
CurseForge:
stage: deploy
when: manual
script:
- chmod +x ./deploy-curseforge.sh
- ./deploy-curseforge.sh
only:
- develop
tags:
- minecraft
#!/bin/bash
set -e
CURSEFORGE_API_KEY=${CURSEFORGE_API_KEY}
CHANGELOG_FILE="./CHANGELOG.md"
API_URL="https://minecraft.curseforge.com/api"
PROJECT_ID=1012118
DEPENDENCY_SLUG="fabric-api"
USER_AGENT="CreatureChat-Minecraft-Mod:curseforge@owlmaddie.com"
SLEEP_DURATION=10
# Function to fetch game version IDs
fetch_game_version_ids() {
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 client_id=$(echo "$response" | jq -r '.[] | select(.name == "Client") | .id')
local server_id=$(echo "$response" | jq -r '.[] | select(.name == "Server") | .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
echo "ERROR: One or more game version IDs not found."
exit 1
fi
echo "$client_id $server_id $fabric_id $minecraft_id"
}
# Read the first changelog block
CHANGELOG=$(awk '/^## \[/{ if (p) exit; p=1 } p' "$CHANGELOG_FILE")
echo "CHANGELOG:"
echo "$CHANGELOG"
echo ""
# Check if the changelog contains "UNRELEASED"
if echo "$CHANGELOG" | grep -qi "UNRELEASED"; then
echo "ERROR: Changelog contains UNRELEASED. Please finalize the changelog before deploying."
exit 1
fi
# Extract the version
VERSION=$(echo "$CHANGELOG" | head -n 1 | sed -n 's/^## \[\(.*\)\] - .*/\1/p')
echo "VERSION:"
echo "$VERSION"
echo ""
# Iterate over each jar file in the artifacts
for FILE in creaturechat*.jar; do
if [ -f "$FILE" ]; then
FILE_BASENAME=$(basename "$FILE")
OUR_VERSION=$(echo "$FILE_BASENAME" | sed -n 's/creaturechat-\(.*\)+.*\.jar/\1/p')
MINECRAFT_VERSION=$(echo "$FILE_BASENAME" | sed -n 's/.*+\(.*\)\.jar/\1/p')
VERSION_NUMBER="$OUR_VERSION-$MINECRAFT_VERSION"
# Verify that OUR_VERSION and MINECRAFT_VERSION are not empty and OUR_VERSION matches VERSION
if [ -z "$OUR_VERSION" ] || [ -z "$MINECRAFT_VERSION" ] || [ "$OUR_VERSION" != "$VERSION" ]; then
echo "ERROR: Version mismatch or missing version information in $FILE_BASENAME. OUR_VERSION: $OUR_VERSION, MINECRAFT_VERSION: $MINECRAFT_VERSION, EXPECTED VERSION: $VERSION"
exit 1
fi
echo "Preparing to upload $FILE_BASENAME as version $VERSION_NUMBER..."
# Fetch game version IDs
GAME_VERSION_IDS=($(fetch_game_version_ids "$MINECRAFT_VERSION"))
# Create a new version payload
PAYLOAD=$(jq -n --arg changelog "$CHANGELOG" \
--arg changelogType "markdown" \
--arg displayName "$FILE_BASENAME" \
--argjson gameVersions "$(printf '%s\n' "${GAME_VERSION_IDS[@]}" | jq -R . | jq -s .)" \
--argjson gameVersionTypeIds '[75125]' \
--arg releaseType "release" \
--argjson relations '[{"slug": "'"$DEPENDENCY_SLUG"'", "type": "requiredDependency"}]' \
'{
"changelog": $changelog,
"changelogType": $changelogType,
"displayName": $displayName,
"gameVersions": $gameVersions | map(tonumber),
"gameVersionTypeIds": $gameVersionTypeIds,
"releaseType": $releaseType,
"relations": {
"projects": $relations
}
}')
# Write the payload to a temporary file to avoid issues with large payloads
echo "$PAYLOAD" > metadata.json
# Sleep for the specified duration
sleep $SLEEP_DURATION
# Upload the version with the file
echo "Uploading $FILE_BASENAME as version $VERSION_NUMBER..."
HTTP_RESPONSE=$(curl --retry 3 --retry-delay 5 --fail -o response.txt -w "\nHTTP Code: %{http_code}\n" -X POST "$API_URL/projects/$PROJECT_ID/upload-file" \
-H "X-Api-Token: $CURSEFORGE_API_KEY" \
-H "User-Agent: $USER_AGENT" \
-F "metadata=<metadata.json;type=application/json" \
-F "file=@$FILE;type=application/java-archive")
# Output the response and HTTP code
echo "Response:"
cat response.txt
echo "$HTTP_RESPONSE"
echo "Uploaded $FILE_BASENAME as version $VERSION_NUMBER."
fi
done
#!/bin/bash
set -e
MODRINTH_API_KEY=${MODRINTH_API_KEY}
CHANGELOG_FILE="./CHANGELOG.md"
API_URL="https://api.modrinth.com/v2"
USER_AGENT="CreatureChat-Minecraft-Mod:modrinth@owlmaddie.com"
PROJECT_ID="rvR0de1E"
AUTHOR_ID="k6RiShdd"
SLEEP_DURATION=10
# Read the first changelog block
CHANGELOG=$(awk '/^## \[/{ if (p) exit; p=1 } p' "$CHANGELOG_FILE")
echo "CHANGELOG:"
echo "$CHANGELOG"
echo ""
# Check if the changelog contains "UNRELEASED"
if echo "$CHANGELOG" | grep -qi "UNRELEASED"; then
echo "ERROR: Changelog contains UNRELEASED. Please finalize the changelog before deploying."
exit 1
fi
# Extract the version
VERSION=$(echo "$CHANGELOG" | head -n 1 | sed -n 's/^## \[\(.*\)\] - .*/\1/p')
echo "VERSION:"
echo "$VERSION"
echo ""
# Iterate over each jar file in the artifacts
for FILE in creaturechat*.jar; do
if [ -f "$FILE" ]; then
FILE_BASENAME=$(basename "$FILE")
OUR_VERSION=$(echo "$FILE_BASENAME" | sed -n 's/creaturechat-\(.*\)+.*\.jar/\1/p')
MINECRAFT_VERSION=$(echo "$FILE_BASENAME" | sed -n 's/.*+\(.*\)\.jar/\1/p')
VERSION_NUMBER="$OUR_VERSION+$MINECRAFT_VERSION"
# Verify that OUR_VERSION and MINECRAFT_VERSION are not empty and OUR_VERSION matches VERSION
if [ -z "$OUR_VERSION" ] || [ -z "$MINECRAFT_VERSION" ] || [ "$OUR_VERSION" != "$VERSION" ]; then
echo "ERROR: Version mismatch or missing version information in $FILE_BASENAME. OUR_VERSION: $OUR_VERSION, MINECRAFT_VERSION: $MINECRAFT_VERSION, EXPECTED VERSION: $VERSION"
exit 1
fi
# Check if the version already exists
echo "Checking if version $VERSION_NUMBER already exists on Modrinth..."
if curl --retry 3 --retry-delay 5 --silent --fail -X GET "$API_URL/project/creaturechat/version/$VERSION_NUMBER" > /dev/null 2>&1; then
echo "Version $VERSION_NUMBER already exists, skipping."
continue
fi
echo "Version $VERSION_NUMBER does not exist. Preparing to upload..."
# Calculate file hashes
SHA512_HASH=$(sha512sum "$FILE" | awk '{ print $1 }')
SHA1_HASH=$(sha1sum "$FILE" | awk '{ print $1 }')
FILE_SIZE=$(stat -c%s "$FILE")
# Create a new version payload
PAYLOAD=$(jq -n --arg version_number "$VERSION_NUMBER" \
--arg changelog "$CHANGELOG" \
--argjson dependencies '[{"project_id": "P7dR8mSH", "dependency_type": "required"}]' \
--argjson game_versions '["'"$MINECRAFT_VERSION"'"]' \
--argjson loaders '["fabric"]' \
--arg project_id "$PROJECT_ID" \
--arg name "CreatureChat $VERSION_NUMBER" \
--argjson file_parts '["file"]' \
--arg requested_status "listed" \
'{
"game_versions": $game_versions,
"loaders": $loaders,
"project_id": $project_id,
"name": $name,
"version_number": $version_number,
"changelog": $changelog,
"version_type": "release",
"featured": false,
"dependencies": $dependencies,
"file_parts": $file_parts,
"requested_status": $requested_status
}')
# Write the payload to a temporary file to avoid issues with large payloads
echo "$PAYLOAD" > metadata.json
# Sleep for the specified duration
sleep $SLEEP_DURATION
# Upload the version with the file
echo "Uploading $FILE_BASENAME as version $VERSION_NUMBER..."
HTTP_RESPONSE=$(curl --retry 3 --retry-delay 5 --fail -o response.txt -w "\nHTTP Code: %{http_code}\n" -X POST "$API_URL/version" \
-H "Authorization: $MODRINTH_API_KEY" \
-H "User-Agent: $USER_AGENT" \
-F "data=@metadata.json;type=application/json;filename=metadata.json" \
-F "file=@$FILE;type=application/java-archive;filename=$FILE_BASENAME")
# Output the response and HTTP code
echo "Response:"
cat response.txt
echo "$HTTP_RESPONSE"
# Check if the response contains errors
if [ $? -ne 0 ]; then
echo "ERROR: Failed to upload $FILE_BASENAME as version $VERSION_NUMBER. Response:"
exit 1
fi
echo "Uploaded $FILE_BASENAME as version $VERSION_NUMBER."
fi
done
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