From 1360014e0f28e938e51e753f73e72e0a47f344e9 Mon Sep 17 00:00:00 2001 From: Matyrobbrt <65940752+Matyrobbrt@users.noreply.github.com> Date: Thu, 28 Dec 2023 10:42:48 +0200 Subject: [PATCH] Infrastructure for PR publishing (#429) Adds the ability to publish PRs to GitHub Packages for testing purposes. --- .github/workflows/build-prs.yml | 6 ++++ .github/workflows/publish-prs.yml | 30 +++++++++++++++++++ .github/workflows/release.yml | 4 +++ build.gradle | 2 +- .../neoforge/common/NeoForgeMod.java | 27 ++++++++++++++++- .../snapshots/ForgeSnapshotsModClient.java | 5 +++- .../resources/assets/neoforge/lang/en_us.json | 2 ++ 7 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/publish-prs.yml diff --git a/.github/workflows/build-prs.yml b/.github/workflows/build-prs.yml index a43d5697ed..2f45445e36 100644 --- a/.github/workflows/build-prs.yml +++ b/.github/workflows/build-prs.yml @@ -1,3 +1,6 @@ +# File generated by the GradleUtils `setupGitHubActionsWorkflows` task, avoid modifying it directly +# The template can be found at https://github.com/neoforged/GradleUtils/blob/44d9e09cfa2c6032b84ac40495ea5ab7d64fe521/src/actionsTemplate/resources/.github/workflows/build-prs.yml + name: Build PRs on: @@ -45,3 +48,6 @@ jobs: with: arguments: build cache-read-only: false + + - name: Publish artifacts + uses: neoforged/action-pr-publishing/upload@v1 diff --git a/.github/workflows/publish-prs.yml b/.github/workflows/publish-prs.yml new file mode 100644 index 0000000000..470973fdda --- /dev/null +++ b/.github/workflows/publish-prs.yml @@ -0,0 +1,30 @@ +# File generated by the GradleUtils `setupGitHubActionsWorkflows` task, avoid modifying it directly +# The template can be found at https://github.com/neoforged/GradleUtils/blob/44d9e09cfa2c6032b84ac40495ea5ab7d64fe521/src/actionsTemplate/resources/.github/workflows/publish-prs.yml + +name: Publish PRs to GitHub Packages + +on: + workflow_run: + workflows: [Build PRs] + types: + - completed + issue_comment: + types: + - edited + pull_request_target: + types: + - opened + +permissions: + packages: write + +jobs: + publish-prs: + if: true + uses: neoforged/actions/.github/workflows/publish-prs.yml@main + with: + artifact_base_path: net/neoforged/neoforge/ + uploader_workflow_name: Build PRs + secrets: + PR_PUBLISHING_GH_APP_ID: ${{ secrets.PR_PUBLISHING_GH_APP_ID }} + PR_PUBLISHING_GH_APP_KEY: ${{ secrets.PR_PUBLISHING_GH_APP_KEY }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5f879c00b6..a11beb444e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,3 +1,6 @@ +# File generated by the GradleUtils `setupGitHubActionsWorkflows` task, avoid modifying it directly +# The template can be found at https://github.com/neoforged/GradleUtils/blob/44d9e09cfa2c6032b84ac40495ea5ab7d64fe521/src/actionsTemplate/resources/.github/workflows/release.yml + name: Release on: @@ -27,3 +30,4 @@ jobs: GPG_SUBKEY: ${{ secrets.GPG_SUBKEY }} GPG_SUBKEY_ID: ${{ secrets.GPG_SUBKEY_ID }} GPG_SUBKEY_PASSWORD: ${{ secrets.GPG_SUBKEY_PASSWORD }} + \ No newline at end of file diff --git a/build.gradle b/build.gradle index ec7517b1c0..7dfc0f03c1 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'net.neoforged.gradleutils' version '3.0.0-alpha.8' apply false + id 'net.neoforged.gradleutils' version '3.0.0-alpha.10' apply false id 'com.diffplug.spotless' version '6.22.0' apply false id 'net.neoforged.licenser' version '0.7.2' apply false } diff --git a/src/main/java/net/neoforged/neoforge/common/NeoForgeMod.java b/src/main/java/net/neoforged/neoforge/common/NeoForgeMod.java index 61794f6780..5d016bfbb9 100644 --- a/src/main/java/net/neoforged/neoforge/common/NeoForgeMod.java +++ b/src/main/java/net/neoforged/neoforge/common/NeoForgeMod.java @@ -73,7 +73,11 @@ import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.CrashReportCallables; import net.neoforged.fml.IExtensionPoint; +import net.neoforged.fml.ModContainer; +import net.neoforged.fml.ModLoader; import net.neoforged.fml.ModLoadingContext; +import net.neoforged.fml.ModLoadingStage; +import net.neoforged.fml.ModLoadingWarning; import net.neoforged.fml.StartupMessageManager; import net.neoforged.fml.VersionChecker; import net.neoforged.fml.common.Mod; @@ -159,6 +163,8 @@ public class NeoForgeMod { private static final Logger LOGGER = LogManager.getLogger(); private static final Marker NEOFORGEMOD = MarkerManager.getMarker("NEOFORGE-MOD"); + private static boolean isPRBuild; + private static final DeferredRegister ATTRIBUTES = DeferredRegister.create(Registries.ATTRIBUTE, "neoforge"); private static final DeferredRegister> COMMAND_ARGUMENT_TYPES = DeferredRegister.create(Registries.COMMAND_ARGUMENT_TYPE, "neoforge"); private static final DeferredRegister> BIOME_MODIFIER_SERIALIZERS = DeferredRegister.create(NeoForgeRegistries.Keys.BIOME_MODIFIER_SERIALIZERS, "neoforge"); @@ -448,7 +454,7 @@ public static void enableMilkFluid() { enableMilkFluid = true; } - public NeoForgeMod(IEventBus modEventBus, Dist dist) { + public NeoForgeMod(IEventBus modEventBus, Dist dist, ModContainer container) { LOGGER.info(NEOFORGEMOD, "NeoForge mod loading, version {}, for MC {} with MCP {}", NeoForgeVersion.getVersion(), NeoFormVersion.getMCVersion(), NeoFormVersion.getMCPVersion()); ForgeSnapshotsMod.logStartupWarning(); @@ -507,6 +513,13 @@ public NeoForgeMod(IEventBus modEventBus, Dist dist) { NeoForge.EVENT_BUS.addListener(CapabilityHooks::invalidateCapsOnChunkLoad); NeoForge.EVENT_BUS.addListener(CapabilityHooks::invalidateCapsOnChunkUnload); NeoForge.EVENT_BUS.addListener(CapabilityHooks::cleanCapabilityListenerReferencesOnTick); + + if (isPRBuild(container.getModInfo().getVersion().toString())) { + isPRBuild = true; + ModLoader.get().addWarning(new ModLoadingWarning( + container.getModInfo(), ModLoadingStage.CONSTRUCT, + "loadwarning.neoforge.prbuild")); + } } public void preInit(FMLCommonSetupEvent evt) { @@ -614,4 +627,16 @@ public void registerLootData(RegisterEvent event) { public void registerPermissionNodes(PermissionGatherEvent.Nodes event) { event.addNodes(USE_SELECTORS_PERMISSION); } + + private static boolean isPRBuild(String neoVersion) { + // The -pr- being inside the actual version and a branch name is important. + // Since we checkout PRs on a branch named `pr--`, this assures that + // the regex will match PR builds published to Packages, but that it will not match local PR branches + // since those usually have the name `pr|pull/` + return neoVersion.matches("\\d+\\.\\d+\\.\\d+(-beta)?-pr-\\d+-[\\w-]+"); + } + + public static boolean isPRBuild() { + return isPRBuild; + } } diff --git a/src/main/java/net/neoforged/neoforge/forge/snapshots/ForgeSnapshotsModClient.java b/src/main/java/net/neoforged/neoforge/forge/snapshots/ForgeSnapshotsModClient.java index 6b9ed5dca5..115b417782 100644 --- a/src/main/java/net/neoforged/neoforge/forge/snapshots/ForgeSnapshotsModClient.java +++ b/src/main/java/net/neoforged/neoforge/forge/snapshots/ForgeSnapshotsModClient.java @@ -9,10 +9,13 @@ import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; +import net.neoforged.neoforge.common.NeoForgeMod; public class ForgeSnapshotsModClient { public static void renderMainMenuWarning(String neoForgeVersion, GuiGraphics graphics, Font font, int width, int height, int alpha) { - if (neoForgeVersion.contains("-beta")) { + if (NeoForgeMod.isPRBuild()) { + graphics.drawCenteredString(font, Component.translatable("loadwarning.neoforge.prbuild"), width / 2, 4 + (font.lineHeight + 1) / 2, 0xFFFFFF | alpha); + } else if (neoForgeVersion.contains("-beta")) { // Render a warning at the top of the screen Component line = Component.translatable("neoforge.update.beta.1", ChatFormatting.RED, ChatFormatting.RESET).withStyle(ChatFormatting.RED); graphics.drawCenteredString(font, line, width / 2, 4 + (0 * (font.lineHeight + 1)), 0xFFFFFF | alpha); diff --git a/src/main/resources/assets/neoforge/lang/en_us.json b/src/main/resources/assets/neoforge/lang/en_us.json index 12dffffe5f..036d13c85c 100644 --- a/src/main/resources/assets/neoforge/lang/en_us.json +++ b/src/main/resources/assets/neoforge/lang/en_us.json @@ -106,6 +106,8 @@ "fml.messages.version.restriction.bounded.lowerexclusive":"above {0}, and {1} or below", "fml.messages.version.restriction.bounded.upperexclusive":"{0} or above, and below {1}", + "loadwarning.neoforge.prbuild": "This build of NeoForge was created by a community member and is thus §c§lUNSUPPORTED§r", + "commands.neoforge.arguments.enum.invalid": "Enum constant must be one of {0}, found {1}", "commands.neoforge.dimensions.list": "Currently registered dimensions by type:", "commands.neoforge.entity.list.invalid": "Invalid filter, does not match any entities. Use /neoforge entity list for a proper list",