Skip to content

Publish Release

Publish Release #85

Workflow file for this run

# This workflow publishes commits to Maven
name: Publish Release
on:
workflow_dispatch:
inputs:
channel:
description: 'Release channel'
required: true
type: string
type:
description: 'Release type'
required: true
default: 'beta'
type: string
jobs:
build:
name: Build and Publish
runs-on: ubuntu-latest
environment: prod
steps:
- name: Checkout git repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Resolve release type
id: release_type
run: |
case $release_type in
"release")
publish_maven=true
publish_launchers=true
publish_gh_release=true
version_format="{major}.{minor}.{patch}"
;;
"beta")
publish_maven=true
publish_launchers=true
publish_gh_release=false
version_format="{major}.{minor}.{patch}-beta+{increment}"
;;
"alpha")
publish_maven=true
publish_launchers=true
publish_gh_release=false
version_format="{major}.{minor}.{patch}-alpha+{increment}"
;;
*)
echo "::warning::Unknown release type: $release_type"
publish_maven=false
publish_launchers=false
publish_gh_release=false
version_format="{major}.{minor}.{patch}-$release_type+{increment}"
esac
tag_format="v$release_channel-{major}.{minor}.{patch}"
echo "release_channel=$release_channel" >> $GITHUB_OUTPUT
echo "release_type=$release_type" >> $GITHUB_OUTPUT
echo "publish_maven=$publish_maven" >> $GITHUB_OUTPUT
echo "publish_launchers=$publish_launchers" >> $GITHUB_OUTPUT
echo "publish_gh_release=$publish_gh_release" >> $GITHUB_OUTPUT
echo "version_format=$version_format" >> $GITHUB_OUTPUT
echo "tag_format=$tag_format" >> $GITHUB_OUTPUT
env:
release_channel: ${{ inputs.channel }}
release_type: ${{ inputs.type }}
# Install python and deps
- name: Set up Python 3.12.1
uses: actions/setup-python@v4
with:
python-version: 3.12.1
- name: Cache PIP packages
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('.github/requirements.txt') }}
- name: Install python deps
run: |
python -m pip install --upgrade pip
python -m pip install -r .github/requirements.txt
- name: Extract Minecraft version
id: mc_version
run: |
mc_version=$(grep '^mc_version=' gradle.properties | cut -d'=' -f2)
echo "mc_version=$mc_version"
echo "mc_version=$mc_version" >> $GITHUB_OUTPUT
- name: Generate version
id: versioning
run: |
version=$(python .github/git_utils.py genVersion --format_str="${{ steps.release_type.outputs.version_format }}")
version_tag=$(python .github/git_utils.py genVersion --format_str="${{ steps.release_type.outputs.tag_format }}")
echo "version=$version"
echo "version_tag=$version_tag"
echo "version=$version" >> $GITHUB_OUTPUT
echo "version_tag=$version_tag" >> $GITHUB_OUTPUT
- name: Generate changelogs
run: |
python .github/git_utils.py genChangelogRaw
python .github/git_utils.py genChangelogMd --next_tag=${{ steps.versioning.outputs.version_tag }}
# Install JDK and build with Gradle
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '21'
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle2-${{ hashFiles('**/build.gradle', '**/build.properties', '**/gradle.properties', '**/gradle-wrapper.properties') }}
- name: Build
run: ./gradlew build
env:
AUTO_GENERATED_VERSION: ${{ steps.versioning.outputs.version }}
- name: Maven publish
if: ${{ steps.release_type.outputs.publish_maven == 'true' }}
run: ./gradlew publish
env:
AUTO_GENERATED_VERSION: ${{ steps.versioning.outputs.version }}
MAVEN_USER: ${{ secrets.MAVEN_USER }}
MAVEN_PASS: ${{ secrets.MAVEN_PASS }}
- name: Publish to Curse
if: ${{ steps.release_type.outputs.publish_launchers == 'true' }}
run: |
# Base args for all modules
COMMON_ARGS=( \
-k $API_TOKEN \
-rt $RELEASE_TYPE \
-v 'Java 17' \
-v $MC_VERSION \
-v NeoForge \
-c ./CHANGELOG.md \
--required-dep codechicken-lib-1-8 \
--required-dep cb-multipart \
)
# All submodules need PR Core
MODULE_ARGS=( \
"${COMMON_ARGS[@]}" \
--required-dep project-red-core \
)
# Fabrication is special and also needs Integration and Transmission
FAB_ARGS=( \
"${MODULE_ARGS[@]}" \
--required-dep project-red-integration \
--required-dep project-red-transmission \
)
python -m curseuploadpy "${COMMON_ARGS[@]}" -p 228702 -f core/build/libs/*-core.jar
python -m curseuploadpy "${MODULE_ARGS[@]}" -p 229048 -f expansion/build/libs/*-expansion.jar
python -m curseuploadpy "${MODULE_ARGS[@]}" -p 229049 -f exploration/build/libs/*-exploration.jar
python -m curseuploadpy "${FAB_ARGS[@]}" -p 230111 -f fabrication/build/libs/*-fabrication.jar
python -m curseuploadpy "${MODULE_ARGS[@]}" -p 229046 -f illumination/build/libs/*-illumination.jar
python -m curseuploadpy "${MODULE_ARGS[@]}" -p 229045 -f integration/build/libs/*-integration.jar
python -m curseuploadpy "${MODULE_ARGS[@]}" -p 478939 -f transmission/build/libs/*-transmission.jar
env:
MC_VERSION: ${{ steps.mc_version.outputs.mc_version }}
RELEASE_TYPE: ${{ steps.release_type.outputs.release_type }}
API_TOKEN: ${{ secrets.CURSE_TOKEN }}
- name: Publish to Modrinth
if: ${{ steps.release_type.outputs.publish_launchers == 'true' }}
run: |
# Base args for all modules
COMMON_ARGS=( \
-k $API_TOKEN \
create-version \
-v "$MOD_VERSION" \
-c ./CHANGELOG.md \
-gv $MC_VERSION \
-vt $RELEASE_TYPE \
-l neoforge \
--required-dep codechicken-lib \
--required-dep cb-multipart \
)
# All submodules need PR Core
MODULE_ARGS=( \
"${COMMON_ARGS[@]}" \
--required-dep project-red-core \
)
# Fabrication is special and also needs Integration and Transmission
FAB_ARGS=( \
"${MODULE_ARGS[@]}" \
--required-dep project-red-integration \
--required-dep project-red-transmission \
)
python -m modrinthpy "${COMMON_ARGS[@]}" -p project-red-core -n "Project Red Core v$MOD_VERSION" -f core/build/libs/*-core.jar
python -m modrinthpy "${MODULE_ARGS[@]}" -p project-red-expansion -n "Project Red Expansion v$MOD_VERSION" -f expansion/build/libs/*-expansion.jar
python -m modrinthpy "${MODULE_ARGS[@]}" -p project-red-exploration -n "Project Red Exploration v$MOD_VERSION" -f exploration/build/libs/*-exploration.jar
python -m modrinthpy "${FAB_ARGS[@]}" -p project-red-fabrication -n "Project Red Fabrication v$MOD_VERSION" -f fabrication/build/libs/*-fabrication.jar
python -m modrinthpy "${MODULE_ARGS[@]}" -p project-red-illumination -n "Project Red Illumination v$MOD_VERSION" -f illumination/build/libs/*-illumination.jar
python -m modrinthpy "${MODULE_ARGS[@]}" -p project-red-integration -n "Project Red Integration v$MOD_VERSION" -f integration/build/libs/*-integration.jar
python -m modrinthpy "${MODULE_ARGS[@]}" -p project-red-transmission -n "Project Red Transmission v$MOD_VERSION" -f transmission/build/libs/*-transmission.jar
env:
MC_VERSION: ${{ steps.mc_version.outputs.mc_version }}
RELEASE_TYPE: ${{ steps.release_type.outputs.release_type }}
API_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
MOD_VERSION: ${{ steps.versioning.outputs.version }}
- name: Tag and Release
if: ${{ steps.release_type.outputs.publish_gh_release == 'true' }}
uses: softprops/action-gh-release@v2
with:
body_path: CHANGELOG.md
tag_name: ${{ steps.versioning.outputs.version_tag }}
target_commitish: ${{ github.sha }}
files: |
*/build/libs/ProjectRed-*.jar
CHANGELOG.md
CHANGELOG.txt
- name: Mark versions in version checker
if: ${{ steps.release_type.outputs.publish_launchers == 'true' }}
run: |
# Function to mark a version in the version checker
mark_version() {
local mod_id=$1
local type=$2
echo "Marking $mod_id as $type..."
python .github/version_checker.py \
--mod_id "$mod_id" \
--mc_version "$MC_VERSION" \
--mod_version "$MOD_VERSION" \
--homepage "https://github.com/MrTJP/ProjectRed" \
--api_key "$API_KEY" \
--type "$type"
}
# List of all modules with their mod IDs
# Note: Mod name "ProjectRed" marked as well for backwards compatibility
MODS=(
"ProjectRed"
"projectred_core"
"projectred_expansion"
"projectred_exploration"
"projectred_fabrication"
"projectred_illumination"
"projectred_integration"
"projectred_transmission"
)
# Mark all modules as latest
for MOD_ID in "${MODS[@]}"; do
mark_version "$MOD_ID" "latest"
done
# Also mark as recommended if this is a full release
if [ "$PUBLISH_GH_RELEASE" = "true" ]; then
for MOD_ID in "${MODS[@]}"; do
mark_version "$MOD_ID" "recommended"
done
fi
env:
MC_VERSION: ${{ steps.mc_version.outputs.mc_version }}
MOD_VERSION: ${{ steps.versioning.outputs.version }}
PUBLISH_GH_RELEASE: ${{ steps.release_type.outputs.publish_gh_release }}
API_KEY: ${{ secrets.VERSION_CHECK_API_KEY }}
- name: Update badge
continue-on-error: true
uses: schneegans/[email protected]
with:
auth: ${{ secrets.GIST_SECRET }}
gistID: 3ef501bc64c896a86fd706dfea8ba367
filename: projectred-badge-${{ steps.release_type.outputs.release_channel }}-${{ steps.release_type.outputs.release_type }}.json
label: Project Red ${{ steps.release_type.outputs.release_channel }}
message: ${{ steps.versioning.outputs.version }}
color: green
namedLogo: CurseForge
cacheSeconds: 300
- name: Cleanup Gradle Cache
# These files shouldn't be cached according to https://docs.github.com/en/actions/guides/building-and-testing-java-with-gradle
run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock
rm -f ~/.gradle/caches/modules-2/gc.properties
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: project-red-${{ steps.versioning.outputs.version }}
path: |
*/build/libs/ProjectRed-*.jar
CHANGELOG.md
CHANGELOG.txt