Skip to content

Commit

Permalink
Infrastructure for PR publishing (#429)
Browse files Browse the repository at this point in the history
Adds the ability to publish PRs to GitHub Packages for testing purposes.
  • Loading branch information
Matyrobbrt authored Dec 28, 2023
1 parent 97e83fa commit 1360014
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build-prs.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -45,3 +48,6 @@ jobs:
with:
arguments: build
cache-read-only: false

- name: Publish artifacts
uses: neoforged/action-pr-publishing/upload@v1
30 changes: 30 additions & 0 deletions .github/workflows/publish-prs.yml
Original file line number Diff line number Diff line change
@@ -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 }}
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -27,3 +30,4 @@ jobs:
GPG_SUBKEY: ${{ secrets.GPG_SUBKEY }}
GPG_SUBKEY_ID: ${{ secrets.GPG_SUBKEY_ID }}
GPG_SUBKEY_PASSWORD: ${{ secrets.GPG_SUBKEY_PASSWORD }}

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down
27 changes: 26 additions & 1 deletion src/main/java/net/neoforged/neoforge/common/NeoForgeMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Attribute> ATTRIBUTES = DeferredRegister.create(Registries.ATTRIBUTE, "neoforge");
private static final DeferredRegister<ArgumentTypeInfo<?, ?>> COMMAND_ARGUMENT_TYPES = DeferredRegister.create(Registries.COMMAND_ARGUMENT_TYPE, "neoforge");
private static final DeferredRegister<Codec<? extends BiomeModifier>> BIOME_MODIFIER_SERIALIZERS = DeferredRegister.create(NeoForgeRegistries.Keys.BIOME_MODIFIER_SERIALIZERS, "neoforge");
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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-<number>-<headname>`, 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/<number>`
return neoVersion.matches("\\d+\\.\\d+\\.\\d+(-beta)?-pr-\\d+-[\\w-]+");
}

public static boolean isPRBuild() {
return isPRBuild;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/neoforge/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 1360014

Please sign in to comment.