From 685883e66f7814369348d72515ed4259941b86ce Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Wed, 27 Dec 2023 00:29:15 +0200 Subject: [PATCH 1/2] Infrastructure for PR publishing --- .github/workflows/build-prs.yml | 3 +++ .github/workflows/publish-prs.yml | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 .github/workflows/publish-prs.yml diff --git a/.github/workflows/build-prs.yml b/.github/workflows/build-prs.yml index a43d5697ed..bef2820791 100644 --- a/.github/workflows/build-prs.yml +++ b/.github/workflows/build-prs.yml @@ -45,3 +45,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..b254d6011e --- /dev/null +++ b/.github/workflows/publish-prs.yml @@ -0,0 +1,27 @@ +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 }} From 735053b321c79c1851c6bc310e4e8f9a6796d7b8 Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Wed, 27 Dec 2023 11:41:48 +0200 Subject: [PATCH 2/2] Add a warning for PR builds --- .../neoforge/common/NeoForgeMod.java | 20 ++++++++++++++++++- .../snapshots/ForgeSnapshotsModClient.java | 5 ++++- .../resources/assets/neoforge/lang/en_us.json | 2 ++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/neoforged/neoforge/common/NeoForgeMod.java b/src/main/java/net/neoforged/neoforge/common/NeoForgeMod.java index 61794f6780..cd280c7e6c 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; @@ -448,7 +452,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 +511,12 @@ 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())) { + ModLoader.get().addWarning(new ModLoadingWarning( + container.getModInfo(), ModLoadingStage.CONSTRUCT, + "loadwarning.neoforge.prbuild")); + } } public void preInit(FMLCommonSetupEvent evt) { @@ -614,4 +624,12 @@ public void registerLootData(RegisterEvent event) { public void registerPermissionNodes(PermissionGatherEvent.Nodes event) { event.addNodes(USE_SELECTORS_PERMISSION); } + + public 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-]+"); + } } 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..617b01ca52 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(neoForgeVersion)) { + graphics.drawCenteredString(font, Component.translatable("loadwarning.neoforge.prbuild"), width / 2, 4, 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..7ec20bc098 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 is coming from a Pull Request and is §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",