diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml new file mode 100644 index 00000000..8ecd872b --- /dev/null +++ b/.github/workflows/publish-release.yml @@ -0,0 +1,168 @@ +name: Publish Release + +on: + release: + types: [published] +jobs: + Get-Properties: + runs-on: ubuntu-latest + outputs: + release-type: ${{ steps.type.outputs.release-type }} + carpet-version: ${{ steps.properties.outputs.mod_version }} + minecraft-version: ${{ steps.properties.outputs.minecraft_version }} + curse-versions: ${{ steps.properties.outputs.release-curse-versions }} + matrix-exclude-branch: ${{ steps.processmatrix.outputs.matrix-to-exclude }} + extra-branch-name: ${{ steps.properties.outputs.release-extra-branch-name }} + extra-branch-curse-version: ${{ steps.properties.outputs.release-extra-curse-version }} + steps: + - name: Checkout the sources + uses: actions/checkout@v2 + - name: Determine release type + id: type + run: | + if ${{ github.event.release.prerelease }}; then + echo "::set-output name=release-type::beta" + else + echo "::set-output name=release-type::release" + fi + - name: Read relevant fields from gradle.properties + id: properties + run: | # From christian-draeger/read-properties, using the action makes it extremely messy until christian-draeger/read-properties#2 + path='./gradle.properties' + for property in mod_version minecraft_version release-curse-versions release-extra-branch release-extra-branch-name release-extra-curse-version + do + result=$(sed -n "/^[[:space:]]*$property[[:space:]]*=[[:space:]]*/s/^[[:space:]]*$property[[:space:]]*=[[:space:]]*//p" "$path") + echo "$property: $result" + echo ::set-output name=$property::"$result" + done + - name: Process property for matrix + id: processmatrix + run: | + if ! ${{ steps.properties.outputs.release-extra-branch }}; then + echo "::set-output name=matrix-to-exclude::Snapshots" + fi + Build-And-Publish: + runs-on: ubuntu-latest + needs: [Get-Properties] + strategy: + matrix: + branch: [Release, Snapshots] + exclude: + - branch: ${{ needs.Get-Properties.outputs.matrix-exclude-branch }} + steps: + - name: Get info from branch to run + id: getbranchinfo + run: | + if ${{ matrix.branch == 'Snapshots'}}; then + echo "::set-output name=branchname::${{ needs.Get-Properties.outputs.extra-branch-name }}" + echo "::set-output name=version::${{ needs.Get-Properties.outputs.extra-branch-curse-version }}" + echo "::set-output name=curse-versions::${{ needs.Get-Properties.outputs.extra-branch-curse-version }}" + else + echo "::set-output name=version::${{ needs.Get-Properties.outputs.minecraft-version }}" + echo "::set-output name=curse-versions::${{ needs.Get-Properties.outputs.curse-versions }}" + fi + - name: Checkout the sources + uses: actions/checkout@v2 + with: + ref: ${{ steps.getbranchinfo.outputs.branchname }} + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Cache Gradle packages + uses: actions/cache@v2 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + restore-keys: ${{ runner.os }}-gradle + - name: Grant execute permission to gradlew + run: chmod +x gradlew + - name: Build with Gradle + run: ./gradlew build + - name: Find correct JAR + id: findjar + run: | + output="$(find build/libs/ ! -name "*-dev.jar" ! -name "*-sources.jar" -type f -printf "%f\n")" + echo "::set-output name=jarname::$output" + - name: Save build artifacts in the action + uses: actions/upload-artifact@v2 + with: + name: Artifacts for ${{ matrix.branch }} + path: build/libs + - name: Upload to the Github release + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: build/libs/${{ steps.findjar.outputs.jarname }} + asset_name: ${{ steps.findjar.outputs.jarname }} + asset_content_type: application/java-archive + - name: Upload to Curseforge + uses: itsmeow/curseforge-upload@v3 + with: + token: ${{ secrets.CF_API_TOKEN }} + project_id: 349240 + game_endpoint: minecraft + file_path: build/libs/${{ steps.findjar.outputs.jarname }} + changelog_type: markdown + changelog: ${{ github.event.release.body }} + display_name: Carpet Extra v${{ needs.Get-Properties.outputs.carpet-version }} for ${{ steps.getbranchinfo.outputs.version }} + game_versions: 7499,4458,${{ steps.getbranchinfo.outputs.curse-versions }} #Fabric,Java 8,[version (s) for the branch] + relations: carpet:requiredDependency + release_type: ${{ needs.Get-Properties.outputs.release-type }} + Update-Rules-to-Readme: + runs-on: ubuntu-latest + steps: + - name: Checkout Carpet extra sources + uses: actions/checkout@v2 + with: + ref: master + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Cache Gradle packages + uses: actions/cache@v2 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + restore-keys: ${{ runner.os }}-gradle + - name: Replace fabric.mod.json + run: | + cd src/main/resources + rm fabric.mod.json + echo ' + { + "schemaVersion": 1, + "id": "carpetextra", + "version": "1.4.11", + "entrypoints": { + "main": [ "carpetextra.utils.RulePrinter" ], + "preLaunch": [ "carpet.utils.CarpetRulePrinter" ] + } + }' > fabric.mod.json + cd ../../../ + - name: Run solution + run: | + chmod +x gradlew + ./gradlew runServer > settings-toProccess.txt + - name: Proccess Gradle log into a pretty readme page + run: | + cat README-header.md > README.md + from1="# Carpet Mod Settings"; + File=settings-toProccess.txt + if grep -q "Deprecated Gradle features" "$File"; then # Happens after update to Gradle 6 + to2="Deprecated Gradle features"; + else + to2="BUILD SUCCESSFUL" + fi + a="$(cat settings-toProccess.txt)";a="$(echo "${a#*"$from1"}")"; echo "${a%%"$to2"*}" >> README.md + - name: Commit updated Readme page + continue-on-error: true + run: | + git add README.md + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git commit -m "Update Readme for '${{ github.event.release.name }}'" || exit 0 + git push diff --git a/.github/workflows/rules-to-readme.yml b/.github/workflows/rules-to-readme.yml deleted file mode 100644 index c0055bc0..00000000 --- a/.github/workflows/rules-to-readme.yml +++ /dev/null @@ -1,83 +0,0 @@ - -name: Update Readme -on: - push: - branches: - - master - paths: - - "src/main/java/carpetextra/CarpetExtraSettings.java" - - "README-header.md" -jobs: - Rules: - runs-on: ubuntu-latest - steps: - - name: Checkout Carpet extra sources - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - name: Cache Gradle packages - uses: actions/cache@v2 - with: - path: ~/.gradle/caches - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} - restore-keys: ${{ runner.os }}-gradle - - name: Generate RulePrinter class - run: | - cd src/main/java/carpetextra/utils - echo " - package carpetextra.utils; - import carpetextra.CarpetExtraServer; - import carpet.CarpetServer; - import carpet.settings.SettingsManager; - import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; - import java.lang.System; - public class RulePrinter implements PreLaunchEntrypoint { - @Override - public void onPreLaunch() { - CarpetExtraServer.noop(); - CarpetServer.onGameStarted(); - CarpetServer.settingsManager.printAllRulesToLog(\"extras\"); - System.exit(0); - } - } - " > RulePrinter.java - cd ../../../../../ - - name: Replace fabric.mod.json - run: | - cd src/main/resources - rm fabric.mod.json - echo ' - { - "schemaVersion": 1, - "id": "carpetextra", - "version": "1.4.11", - "entrypoints": { - "preLaunch": [ "carpetextra.utils.RulePrinter" ] - } - }' > fabric.mod.json - cd ../../../ - - name: Run solution - run: | - chmod +x gradlew - ./gradlew runServer > settings-toProccess.txt - - name: Proccess Gradle log into a pretty readme page - run: | - cat README-header.md > README.md - from1="# Carpet Mod Settings"; - File=settings-toProccess.txt - if grep -q "Deprecated Gradle features" "$File"; then # Happens after update to Gradle 6 - to2="Deprecated Gradle features"; - else - to2="BUILD SUCCESSFUL" - fi - a="$(cat settings-toProccess.txt)";a="$(echo "${a#*"$from1"}")"; echo "${a%%"$to2"*}" >> README.md - - name: Commit updated Readme page - continue-on-error: true - run: | - git add README.md - git config --global user.name 'github-actions[bot]' - git config --global user.email 'github-actions[bot]@users.noreply.github.com' - git commit -m "Update Readme for '${{ github.event.head_commit.message }}'" - git push diff --git a/gradle.properties b/gradle.properties index 64b5eab1..af6cb20a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ org.gradle.jvmargs=-Xmx1G yarn_mappings=1.16.5+build.1 loader_version=0.11.0 # check available versions on maven for the given minecraft version you are using - carpet_core_version=1.4.23+v210115 + carpet_core_version=1.4.26+v210210 # Mod Properties mod_version = 1.4.23 @@ -17,3 +17,17 @@ org.gradle.jvmargs=-Xmx1G # Dependencies # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api # fabric_version=0.3.0+build.207 + +# Release Action properties for Curseforge and Snapshots + # The Curseforge versions "names" or ids for the main branch (comma separated: 1.16.4,1.16.5) + # This is needed because CF uses too vague names for prereleases and release candidates + # Can also be the version ID directly coming from https://minecraft.curseforge.com/api/game/versions?token=[API_TOKEN] + release-curse-versions = 1.16.4,1.16.5 + # Whether or not to build another branch on release + release-extra-branch = true + # The name of the second branch to release + release-extra-branch-name = 1.17 + # The "name" or id of the Curseforge version for the secondary branch + # This is needed because CF uses too vague names for snapshots + # Can also be the version ID directly coming from https://minecraft.curseforge.com/api/game/versions?token=[API_TOKEN] + release-extra-curse-version = 1.17 diff --git a/src/main/java/carpetextra/utils/RulePrinter.java b/src/main/java/carpetextra/utils/RulePrinter.java new file mode 100644 index 00000000..eba42eef --- /dev/null +++ b/src/main/java/carpetextra/utils/RulePrinter.java @@ -0,0 +1,18 @@ +package carpetextra.utils; + +import carpetextra.CarpetExtraServer; +import carpet.CarpetServer; +import carpet.utils.CarpetRulePrinter; +import net.fabricmc.api.ModInitializer; +import java.lang.System; + +public class RulePrinter implements ModInitializer { + @Override + public void onInitialize() { + System.setOut(CarpetRulePrinter.OLD_OUT); + CarpetExtraServer.noop(); + CarpetServer.onGameStarted(); + CarpetServer.settingsManager.printAllRulesToLog("extras"); + System.exit(0); + } +}