Commit 0f05f99d by Jonathan Thomas

First draft of deployment CI in gitlab for Modrinth and Curseforge

parent 16f0dce0
Pipeline #12217 failed
......@@ -9,7 +9,9 @@ cache:
stages:
- build
- deploy
# Build JAR files for each Minecraft & Fabric version
build_mod:
stage: build
before_script:
......@@ -59,6 +61,42 @@ build_mod:
- creaturechat-*.jar
- fabric-api-*.jar
only:
- develop
- new-deploy-ci
tags:
- minecraft
# Deploy to Modrinth
deploy_modrinth:
stage: deploy
script:
- chmod +x ./deploy_modrinth.sh
- ./deploy_modrinth.sh
only:
- new-deploy-ci
artifacts:
paths:
- creaturechat*.jar
environment:
name: production
secrets:
MODRINTH_API_KEY:
description: "API key for Modrinth"
required: true
# Deploy to CurseForge
deploy_curseforge:
stage: deploy
script:
- chmod +x ./deploy_curseforge.sh
- ./deploy_curseforge.sh
only:
- new-deploy-ci
artifacts:
paths:
- creaturechat*.jar
environment:
name: production
secrets:
CURSEFORGE_API_KEY:
description: "API key for CurseForge"
required: true
\ No newline at end of file
#!/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"
# Function to fetch game version IDs
fetch_game_version_ids() {
local minecraft_version="$1"
local response=$(curl -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
# Upload the version with the file
echo "Uploading $FILE_BASENAME as version $VERSION_NUMBER..."
HTTP_RESPONSE=$(curl --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"
# 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 --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
# Upload the version with the file
echo "Uploading $FILE_BASENAME as version $VERSION_NUMBER..."
RESPONSE=$(curl --fail -s -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
echo "Response:"
echo "$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