Skip to content

Commit

Permalink
Add build number to version
Browse files Browse the repository at this point in the history
  • Loading branch information
acrylic-style committed Dec 13, 2021
1 parent cdd9067 commit 5705ef0
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Apply patches
run: './blueberry p'
- name: Bake installer
run: './blueberry i'
run: './blueberry i ${{ github.run_number }}'
- name: Retrieve Minecraft version
run: 'echo "::set-output name=version::$(mvn -f pom.xml help:evaluate -Dexpression=minecraft.version -q -DforceStdout)"'
id: retrieveMcVersion
Expand All @@ -37,7 +37,7 @@ jobs:
- name: Release new build
uses: softprops/[email protected]
with:
tag_name: ${{ steps.retrieveMcVersion.outputs.version }}-${{ steps.retrieveApiVersion.outputs.version }}-${{ github.run_number }}
tag_name: ${{ steps.retrieveMcVersion.outputs.version }}-${{ steps.retrieveApiVersion.outputs.version }}.${{ github.run_number }}
files: '*-installer.jar'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .run/[Windows] Run Client (Debug).run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</envs>
<option name="INCLUDE_PROVIDED_SCOPE" value="true" />
<option name="MAIN_CLASS_NAME" value="net.blueberrymc.client.main.ClientMain" />
<module name="blueberry" />
<module name="Blueberry-Parent.blueberry" />
<option name="PROGRAM_PARAMETERS" value="--debug --version=debug --assetIndex=1.18 --versionType=debug --username=&quot;Dev&quot; --userType=mojang --uuid=&quot;dev&quot; --accessToken=abc --assetsDir=&quot;${APPDATA}\.minecraft\assets&quot;" />
<option name="VM_PARAMETERS" value="-Xmx8G -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M -Dmixin.debug=true -Dmixin.debug.strict=true -Dmixin.checks=true" />
<option name="WORKING_DIRECTORY" value="$ProjectFileDir$/work/testClient" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ public static int executeVersionCommand(@NotNull CommandSourceStack source) {
LOGGER.warn("Version checker threw exception when fetching cached result", e);
}
}
source.sendSuccess(new TextComponent("").append(new TextComponent(Util.capitalize(v.getName())).withStyle(ChatFormatting.AQUA, ChatFormatting.BOLD)).append(new TextComponent(" (").withStyle(ChatFormatting.DARK_GRAY)).append(new TextComponent("API " + (Character.isDigit(v.getVersion().charAt(0)) ? "v" : "") + v.getVersion()).withStyle(ChatFormatting.DARK_GREEN)).append(new TextComponent(") (").withStyle(ChatFormatting.DARK_GRAY)).append(new TextComponent("Minecraft " + SharedConstants.getCurrentVersion().getId()).withStyle(ChatFormatting.GRAY)).append(new TextComponent(")").withStyle(ChatFormatting.DARK_GRAY)), false);
source.sendSuccess(new TextComponent("").append(new BlueberryText("blueberry", "blueberry.mod.command.version.built_at").withStyle(ChatFormatting.YELLOW, ChatFormatting.BOLD)).append(new TextComponent(v.getBuiltAt())), false);
source.sendSuccess(new TextComponent("").append(new BlueberryText("blueberry", "blueberry.mod.command.version.commit_hash").withStyle(ChatFormatting.YELLOW, ChatFormatting.BOLD)).append(new TextComponent(v.getShortCommit()).withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent("Click to copy"))).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, v.getCommit())))).append(versionDiff), false);
source.sendSuccess(new TextComponent("").append(new BlueberryText("blueberry", "blueberry.mod.command.version.magmacube_commit_hash").withStyle(ChatFormatting.YELLOW, ChatFormatting.BOLD)).append(new TextComponent(v.getShortMagmaCubeCommit()).withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent("Click to copy"))).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, v.getMagmaCubeCommit())))), false);
source.sendSuccess(new TextComponent(" | ").append(new TextComponent(Util.capitalize(v.getName())).withStyle(ChatFormatting.AQUA, ChatFormatting.BOLD)).append(" ").append(new TextComponent((Character.isDigit(v.getVersion().charAt(0)) ? "v" : "") + v.getVersion() + "." + v.getBuildNumber()).withStyle(ChatFormatting.LIGHT_PURPLE)).append(new TextComponent(" (").withStyle(ChatFormatting.DARK_GRAY)).append(new TextComponent("API " + (Character.isDigit(v.getVersion().charAt(0)) ? "v" : "") + v.getVersion()).withStyle(ChatFormatting.DARK_GREEN)).append(new TextComponent(") (").withStyle(ChatFormatting.DARK_GRAY)).append(new TextComponent("Minecraft " + SharedConstants.getCurrentVersion().getId()).withStyle(ChatFormatting.GRAY)).append(new TextComponent(")").withStyle(ChatFormatting.DARK_GRAY)), false);
source.sendSuccess(new TextComponent(" | ").append(new BlueberryText("blueberry", "blueberry.mod.command.version.built_at").withStyle(ChatFormatting.YELLOW, ChatFormatting.BOLD)).append(new TextComponent(v.getBuiltAt())), false);
source.sendSuccess(new TextComponent(" | ").append(new BlueberryText("blueberry", "blueberry.mod.command.version.commit_hash").withStyle(ChatFormatting.YELLOW, ChatFormatting.BOLD)).append(new TextComponent(v.getShortCommit()).withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent("Click to copy"))).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, v.getCommit())))).append(versionDiff), false);
source.sendSuccess(new TextComponent(" | ").append(new BlueberryText("blueberry", "blueberry.mod.command.version.magmacube_commit_hash").withStyle(ChatFormatting.YELLOW, ChatFormatting.BOLD)).append(new TextComponent(v.getShortMagmaCubeCommit()).withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent("Click to copy"))).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, v.getMagmaCubeCommit())))), false);
if (!cached) {
source.sendSuccess(new TextComponent("").append(new BlueberryText("blueberry", "blueberry.mod.command.version.checking_for_new_version").withStyle(ChatFormatting.YELLOW, ChatFormatting.ITALIC)), false);
VersionChecker.check().thenAccept(result -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@ public class BlueberryVersion {
@NotNull private final String magmaCubeCommit;
@NotNull private final String commit;
@NotNull private final String builtAt;

public BlueberryVersion(@NotNull String name, @NotNull String version, @NotNull String magmaCubeCommit, @NotNull String commit, @NotNull String builtAt) {
private final int buildNumber;

public BlueberryVersion(@NotNull String name,
@NotNull String version,
@NotNull String magmaCubeCommit,
@NotNull String commit,
@NotNull String builtAt,
int buildNumber) {
this.name = name;
this.version = version;
this.magmaCubeCommit = magmaCubeCommit;
this.commit = commit;
this.builtAt = builtAt;
this.buildNumber = buildNumber;
}

/**
Expand Down Expand Up @@ -78,14 +85,22 @@ public String getShortCommit() {

/**
* Returns the build date.
* Example output: 2021-10-30T00:30:44+09:00 (yyyy-mm-ddThh:mm:ss+offset)
* Example output: 2021-10-30T00:30:44+00:00 (yyyy-mm-ddThh:mm:ss+offset)
* @return build date
*/
@NotNull
public String getBuiltAt() {
return builtAt;
}

/**
* Returns the build number for the build. Returns 0 if unknown or build number is 0.
* @return build number
*/
public int getBuildNumber() {
return buildNumber;
}

private String gameVersion = null;

/**
Expand All @@ -101,13 +116,13 @@ public String getGameVersion() {
private String fqv = null;

/**
* Returns the version string of [game version]-[name]-[api version].
* Returns the version string of [game version]-[api version].[build-number].
* @return [game version]-[name]-[api version]
*/
@NotNull
public String getFullyQualifiedVersion() {
if (fqv != null) return fqv;
return fqv = getGameVersion() + "-" + this.name + "-" + this.version;
return fqv = getGameVersion() + "-" + this.version + "." + buildNumber;
}

@Contract(value = "null -> false", pure = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class Versioning {
private static final Logger LOGGER = LogManager.getLogger();
public static final BlueberryVersion UNKNOWN = new BlueberryVersion("blueberry", "unknown", "unknown", "unknown", "unknown");
public static final BlueberryVersion UNKNOWN = new BlueberryVersion("blueberry", "1.0.0", "unknown", "unknown", "9999-12-31T23:59:59+00:00", 0);
// cached version info
private static BlueberryVersion VERSION = null;

Expand All @@ -29,6 +29,7 @@ public static BlueberryVersion getVersion() {
String magmaCubeCommit = "unknown";
String commit = "unknown";
String builtAt = "unknown";
int buildNumber = 0;
if (stream != null) {
try {
properties.load(stream);
Expand All @@ -37,6 +38,11 @@ public static BlueberryVersion getVersion() {
magmaCubeCommit = properties.getProperty("magmaCubeCommit", magmaCubeCommit);
commit = properties.getProperty("commit", commit);
builtAt = properties.getProperty("builtAt", builtAt);
try {
buildNumber = Integer.parseInt(properties.getProperty("buildNumber", "0"));
} catch (NumberFormatException e) {
LOGGER.error("buildNumber is not a number: {}", properties.getProperty("buildNumber", "0"), e);
}
} catch (IOException ex) {
LOGGER.error("Blueberry API version information is corrupt (api-version.properties)", ex);
}
Expand All @@ -51,7 +57,7 @@ public static BlueberryVersion getVersion() {
}
}
}
VERSION = new BlueberryVersion(name, version, magmaCubeCommit, commit, builtAt);
VERSION = new BlueberryVersion(name, version, magmaCubeCommit, commit, builtAt, buildNumber);
return VERSION;
}
}
10 changes: 7 additions & 3 deletions blueberry
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ case "$1" in
(
set -e
cd "$basedir"
scripts/build.sh || exit 1
BN=$2
if [ -z "$BN" ]; then
BN="0"
fi
scripts/build.sh $BN || exit 1
scripts/createPatchFile.sh || exit 1
scripts/createInstaller.sh || exit 1
scripts/createInstaller.sh $BN || exit 1
)
;;
"b" | "build")
Expand All @@ -72,7 +76,7 @@ case "$1" in
echo " * rb, rebuild | Rebuild patches, can be called from anywhere."
echo " * p, patch | Apply all patches to the project without building it."
echo " * prb, patchAndRebuild | Apply all patches to the project and rebuild patches. Useful when you modified the small part of a patch file."
echo " * i, installer | Creates installer. The project must be patched before doing this."
echo " * i, installer [number] | Creates installer. The project must be patched before doing this."
echo " * b, build | Builds the project and creates installer."
;;
esac
5 changes: 5 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash
basedir="."
BN=$1
if [ -z "$BN" ]; then
BN="0"
fi
source ./scripts/functions.sh
apiversion=$(mvn -f Blueberry-API/pom.xml help:evaluate -Dexpression=project.version -q -DforceStdout)
datetime=$(date +%Y-%m-%dT%T%:z)
Expand All @@ -13,6 +17,7 @@ echo "version=$apiversion" >> "$version_prop"
echo "magmaCubeCommit=$magmacubeCommit" >> "$version_prop"
echo "commit=$commit" >> "$version_prop"
echo "builtAt=$datetime" >> "$version_prop"
echo "buildNumber=$BN" >> "$version_prop"
echo "" >> "$version_prop"
echo "api-version.properties:"
cat "$version_prop"
Expand Down
6 changes: 5 additions & 1 deletion scripts/createInstaller.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env bash
basedir="."
BN=$1
if [ -z "$BN" ]; then
BN="0"
fi
source "$basedir/scripts/functions.sh" || exit 1
git="git -c commit.gpgsign=false"
apiversion=$(mvn -f Blueberry-API/pom.xml help:evaluate -Dexpression=project.version -q -DforceStdout)
Expand All @@ -12,7 +16,7 @@ else
$git checkout origin/main || exit 1
cd "$basedir" || exit 1
fi
name="$version-blueberry-$apiversion"
name="blueberry-$version-$apiversion.$BN"
res="$basedir/work/Installer/src/main/resources"
prop="$res/profile.properties"
echo "name=$name" > "$prop"
Expand Down

0 comments on commit 5705ef0

Please sign in to comment.