diff --git a/.github/workflows/gradle.build.yaml b/.github/workflows/gradle.build.yaml index 9e3a4d2..69f4e22 100644 --- a/.github/workflows/gradle.build.yaml +++ b/.github/workflows/gradle.build.yaml @@ -5,53 +5,49 @@ on: workflow_call: inputs: java: - description: "The version of Java to use to run Gradle" # Note: Gradle's Java toolchains feature is used for compiling, which is separate from this + description: "The version of Java to use to run Gradle" required: false type: string default: "21" gradle_tasks: - description: "The Gradle task(s) to run at publication" + description: "The Gradle task(s) to run for building" required: false type: string - default: "publish" + default: "build" secrets: - CROWDIN_API_KEY: - required: true - GRADLE_ENCRYPTION_KEY: - required: true + description: The AES key to enable Gradle cache encryption + required: false permissions: contents: read - statuses: write - packages: write jobs: compute-version: - name: Compute version + uses: ./.github/workflows/gradle.version.yaml + + build: + needs: [ "compute-version" ] runs-on: ubuntu-latest - outputs: - version: ${{ steps.version.outputs.version }} - version_tag: ${{ steps.version.outputs.version_tag }} - minecraft_version: ${{ steps.minecraftVersion.outputs.minecraft_version }} steps: - id: checkout name: "📦 Checkout" uses: actions/checkout@v4 - with: - fetch-depth: 0 - fetch-tags: true - - id: minecraftVersion - name: "📦 Extract Minecraft version" + - id: setupJava + name: "🔧 Setup Java" run: | - cat gradle.properties | grep exactMinecraftVersion | cut -d "=" -f 2 > minecraft_version.txt - echo "Minecraft version: $(cat minecraft_version.txt)" - echo "minecraft_version=$(cat minecraft_version.txt)" >> "$GITHUB_OUTPUT" + echo "JAVA_HOME=$(echo $JAVA_HOME_${{ inputs.java }}_X64)" >> "$GITHUB_ENV" + + - id: setupGradle + name: "🔧 Setup Gradle" + uses: gradle/actions/setup-gradle@v4 + with: + gradle-version: wrapper + cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }} - id: computeBranchSuffix name: "🔢 Compute branch suffix" - if: github.event_name == 'push' run: | gitRef="${{ github.ref }}" branchName=$(echo "${gitRef/refs\/heads\//}") @@ -62,49 +58,9 @@ jobs: echo "branch_suffix=$cleanedBranchName" >> "$GITHUB_OUTPUT" - - id: version - name: "🔢 Compute version" - uses: PaulHatch/semantic-version@v5.4.0 - with: - tag_prefix: "v" - search_commit_body: true - debug: true - bump_each_commit: true - version_format: "${major}.${minor}.${patch}-${{ steps.minecraftVersion.outputs.minecraft_version }}-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || format('branch-{0}', steps.computeBranchSuffix.outputs.branch_suffix) }}" - - gradle: - needs: ["compute-version"] # Make sure we now the version before starting to build - runs-on: ubuntu-latest - steps: - - id: checkout - name: "📦 Checkout" - uses: actions/checkout@v4 - with: - fetch-depth: 1000 - fetch-tags: true - - - id: setupJava - name: "🔧 Setup Java" - # https://github.com/actions/runner-images/blob/main/images/linux/Ubuntu2204-Readme.md#java - # language=bash - run: | - echo "JAVA_HOME=$(echo $JAVA_HOME_${{ inputs.java }}_X64)" >> "$GITHUB_ENV" - - - id: setupGradle - name: "🔧 Setup Gradle" - uses: gradle/actions/setup-gradle@v4 - with: - gradle-version: wrapper - cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }} - - id: build name: "🏗️ Build" run: ./gradlew --build-cache ${{ inputs.gradle_tasks }} env: - crowdinKey: ${{ secrets.CROWDIN_API_KEY }} - Version: "${{ needs.compute-version.outputs.version }}" - GITHUB_TOKEN: ${{ github.token }} - GITHUB_REPOSITORY: ${{ github.repository }} - GITHUB_USERNAME: ${{ github.actor }} - - + MOD_VERSION: ${{ needs.compute-version.outputs.version }} + MOD_VERSION_SUFFIX: "beta-${{ steps.computeBranchSuffix.outputs.branch_suffix }}" \ No newline at end of file diff --git a/.github/workflows/gradle.prerelease.yaml b/.github/workflows/gradle.prerelease.yaml new file mode 100644 index 0000000..8f4e38e --- /dev/null +++ b/.github/workflows/gradle.prerelease.yaml @@ -0,0 +1,65 @@ +# Based off https://github.com/MinecraftForge/SharedActions/blob/main/.github/workflows/gradle.yml +name: Gradle Pre-release CI + +on: + workflow_call: + inputs: + java: + description: "The version of Java to use to run Gradle" + required: false + type: string + default: "21" + gradle_tasks: + description: "The Gradle task(s) to run for building" + required: false + type: string + default: "publish" + secrets: + GRADLE_ENCRYPTION_KEY: + description: The AES key to enable Gradle cache encryption + required: true + CROWDIN_API_KEY: + required: true + +permissions: + contents: read + statuses: write + packages: write + +jobs: + compute-version: + uses: ./.github/workflows/gradle.version.yaml + + gradle: + needs: [ "compute-version" ] + runs-on: ubuntu-latest + steps: + - id: checkout + name: "📦 Checkout" + uses: actions/checkout@v4 + with: + fetch-depth: 1000 + fetch-tags: true + + - id: setupJava + name: "🔧 Setup Java" + run: | + echo "JAVA_HOME=$(echo $JAVA_HOME_${{ inputs.java }}_X64)" >> "$GITHUB_ENV" + + - id: setupGradle + name: "🔧 Setup Gradle" + uses: gradle/actions/setup-gradle@v4 + with: + gradle-version: wrapper + cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }} + + - id: build + name: "🏗️ Build" + run: ./gradlew --build-cache ${{ inputs.gradle_tasks }} + env: + GITHUB_TOKEN: ${{ github.token }} + GITHUB_REPOSITORY: ${{ github.repository }} + GITHUB_USERNAME: ${{ github.actor }} + crowdinKey: ${{ secrets.CROWDIN_API_KEY }} + MOD_VERSION: ${{ needs.compute-version.outputs.version }} + MOD_VERSION_SUFFIX: rc \ No newline at end of file diff --git a/.github/workflows/gradle.publish.yaml b/.github/workflows/gradle.publish.yaml index cbfd512..82c5ab1 100644 --- a/.github/workflows/gradle.publish.yaml +++ b/.github/workflows/gradle.publish.yaml @@ -5,7 +5,7 @@ on: workflow_call: inputs: java: - description: "The version of Java to use to run Gradle" # Note: Gradle's Java toolchains feature is used for compiling, which is separate from this + description: "The version of Java to use to run Gradle" required: false type: string default: "21" @@ -24,23 +24,19 @@ on: required: false type: number default: 100 - secrets: DISCORD_WEBHOOK: required: true - MAVEN_USER: required: true MAVEN_PASSWORD: required: true - CURSE_API_KEY: required: true - CROWDIN_API_KEY: required: true - GRADLE_ENCRYPTION_KEY: + description: The AES key to enable Gradle cache encryption required: true permissions: @@ -49,39 +45,12 @@ permissions: jobs: compute-version: - name: Compute version - runs-on: ubuntu-latest - outputs: - version: ${{ steps.version.outputs.version }} - version_tag: ${{ steps.version.outputs.version_tag }} - minecraft_version: ${{ steps.minecraftVersion.outputs.minecraft_version }} - steps: - - id: checkout - name: "📦 Checkout" - uses: actions/checkout@v4 - with: - fetch-depth: 0 - fetch-tags: true - - - id: minecraftVersion - name: "📦 Extract Minecraft version" - run: | - cat gradle.properties | grep exactMinecraftVersion | cut -d "=" -f 2 > minecraft_version.txt - echo "Minecraft version: $(cat minecraft_version.txt)" - echo "minecraft_version=$(cat minecraft_version.txt)" >> "$GITHUB_OUTPUT" - - - id: version - name: "🔢 Compute version" - uses: PaulHatch/semantic-version@v5.4.0 - with: - tag_prefix: "v" - search_commit_body: true - debug: true - bump_each_commit: true - version_format: "${major}.${minor}.${patch}-${{ steps.minecraftVersion.outputs.minecraft_version }}-${{ inputs.curse_release_type }}" + uses: ./.github/workflows/gradle.version.yaml + with: + suffix: ${{ inputs.curse_release_type }} notify-build-start: - needs: ["compute-version"] + needs: [ "compute-version" ] name: "🔴 Build notifications (start)" runs-on: ubuntu-latest steps: @@ -104,7 +73,7 @@ jobs: target_url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} gradle: - needs: ["compute-version"] # Make sure we now the version before starting to build + needs: [ "compute-version" ] runs-on: ubuntu-latest steps: - id: checkout @@ -116,8 +85,6 @@ jobs: - id: setupJava name: "🔧 Setup Java" - # https://github.com/actions/runner-images/blob/main/images/linux/Ubuntu2204-Readme.md#java - # language=bash run: | echo "JAVA_HOME=$(echo $JAVA_HOME_${{ inputs.java }}_X64)" >> "$GITHUB_ENV" @@ -146,6 +113,18 @@ jobs: onlyLastTag: true maxIssues: ${{ inputs.changelog_max_issues }} + - id: generate-release-information + name: "Generate release information" + run: | + release_version_suffix = "alpha" + if [[ ${{ inputs.curse_release_type }} == release ]]; then + release_version_suffix = "" + elif [[ ${{ inputs.curse_release_type }} == beta ]]; then + release_version_suffix = "snapshot" + fi + echo "Release version suffix: ${release_version_suffix}" + echo "release_version_suffix=${release_version_suffix}" >> "$GITHUB_ENV" + - id: publish name: "🚀 Publish" run: ./gradlew --build-cache ${{ inputs.gradle_tasks }} @@ -155,7 +134,8 @@ jobs: CURSE_API_KEY: ${{ secrets.CURSE_API_KEY }} CURSE_RELEASE_TYPE: ${{ inputs.curse_release_type }} crowdinKey: ${{ secrets.CROWDIN_API_KEY }} - Version: "${{ needs.compute-version.outputs.version }}" + MOD_VERSION: ${{ needs.compute-version.outputs.version }} + MOD_VERSION_SUFFIX: ${{ steps.generate-release-suffix.outputs.release_version_suffix }} - name: "🚀 Create GitHub release" uses: actions/create-release@v1 @@ -188,4 +168,4 @@ jobs: context: 'Publishing' state: ${{ needs.gradle.result }} description: "Version: ${{ needs.compute-version.outputs.version }}" - target_url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + target_url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} \ No newline at end of file diff --git a/.github/workflows/gradle.version.yaml b/.github/workflows/gradle.version.yaml new file mode 100644 index 0000000..8f66cb6 --- /dev/null +++ b/.github/workflows/gradle.version.yaml @@ -0,0 +1,34 @@ +name: Common Version Determination CI + +on: + workflow_call: + outputs: + version: + description: "The computed version" + value: ${{ jobs.compute-version.outputs.version }} + +permissions: + contents: read + +jobs: + compute-version: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.version.outputs.version }} + steps: + - id: checkout + name: "📦 Checkout" + uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true + + - id: version + name: "🔢 Compute version" + uses: PaulHatch/semantic-version@v5.4.0 + with: + tag_prefix: "v" + search_commit_body: true + debug: true + bump_each_commit: true + version_format: "${major}.${minor}.${patch}" \ No newline at end of file diff --git a/gradle/mod.gradle b/gradle/mod.gradle index 4e1491f..68589a4 100644 --- a/gradle/mod.gradle +++ b/gradle/mod.gradle @@ -269,6 +269,15 @@ if (opc.isFeatureEnabled("GitInformation")) { group = project.modGroup +def versionNumber = opc.hasPropertySet("modVersion") ? opc.getProperty("modVersion") : "0.0.1" +def versionSuffix = opc.hasPropertySet("modVersionSuffix") ? opc.getProperty("modVersionSuffix") : "alpha" +def versionString +if (versionSuffix == "") { + versionString = versionNumber + "-" + project.exactMinecraftVersion +} else { + versionString = versionNumber + "-" + project.exactMinecraftVersion + "-" + versionSuffix +} + if (opc.isFeatureEnabled("MCVersionBasedVersioning") && opc.hasPropertySet("mcVersionElementIndex") && opc.hasPropertySet("sourceVersionElementIndex") @@ -276,16 +285,14 @@ if (opc.isFeatureEnabled("MCVersionBasedVersioning") logger.lifecycle("MC based versioning active") version = opc.buildVersionNumberWithOffset( - (System.getenv().containsKey("Version") ? System.getenv("Version") : project.modVersion), + versionString, project.exactMinecraftVersion, opc.getProperty("sourceVersionName"), opc.getIntProperty("sourceVersionElementIndex"), opc.getIntProperty("mcVersionElementIndex") ) -} -else -{ - version = System.getenv().containsKey("Version") ? System.getenv("Version") : project.modVersion +} else { + version = versionString } archivesBaseName = project.modId project.properties.file = [ @@ -1040,7 +1047,7 @@ if (opc.isFeatureEnabled("curse") && opc.hasPropertySet("curseId") mainArtifactName = opc.getProperty('customCurseFileName') } - mainArtifact.displayName = mainArtifactName + " - " + project.version + " - " + mainArtifact.releaseType + mainArtifact.displayName = mainArtifactName + " - " + versionNumber + " - " + mainArtifact.releaseType } mainArtifact.changelog = project.rootProject.file("changelog.md")