Skip to content

Update Version data based upon Properties File #6871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ jobs:
with:
path: megamek

- name: Set short git commit SHA
id: vars
run: |
cd megamek
calculatedSha=$(git rev-parse --short ${{ github.sha }})
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV

- name: "Output branch information to Version file"
run: |
echo "branch=PR-${{ github.event.number }}" >> megamek/megamek/resources/extraVersion.properties
echo "gitHash=${{ env.COMMIT_SHORT_SHA }}" >> megamek/megamek/resources/extraVersion.properties

- name: Set up ${{ matrix.java-distribution }} JDK ${{ matrix.java-version }}
uses: actions/setup-java@v4
with:
Expand Down Expand Up @@ -57,7 +69,7 @@ jobs:

- name: Build with Gradle
working-directory: megamek
run: ./gradlew build -x test
run: ./gradlew build -x test -PextraVersion="PR-${{ github.event.number }}-${{ env.COMMIT_SHORT_SHA }}"

- name: Upload TarGZ Release
uses: actions/upload-artifact@v4
Expand Down
24 changes: 20 additions & 4 deletions .github/workflows/nightly-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ jobs:
with:
path: megamek

- name: "Output branch information to Version file"
run: |
echo "branch=nightly" >> megamek/megamek/resources/extraVersion.properties
echo "gitHash=$(date +'%Y-%m-%d')" >> megamek/megamek/resources/extraVersion.properties

- name: Set up ${{ matrix.java-distribution }} JDK ${{ matrix.java-version }}
uses: actions/setup-java@v4
with:
Expand All @@ -39,16 +44,27 @@ jobs:
build-scan-terms-of-use-url: "https://gradle.com/terms-of-service"
build-scan-terms-of-use-agree: "yes"

- name: Build with Gradle
- name: Testing Nightly
working-directory: megamek
run: ./gradlew clean build --stacktrace --scan
run: ./gradlew test

- name: Upload Test Logs on Failure
uses: actions/upload-artifact@v4
if: failure()
with:
name: ${{ matrix.os }}-${{ matrix.java-distribution }}-jdk${{ matrix.java-version }}-ci-failure-logs
path: megamek/megamek/build/reports/
name: cd-failure-logs
path: ./megamek/megamek/build/reports/

- name: CodeCov.io Coverage Report
uses: codecov/codecov-action@v5
with:
directory: ./megamek/megamek/build/reports/jacoco/test
fail_ci_if_error: false
verbose: true

- name: Build with Gradle
working-directory: megamek
run: ./gradlew build -x test -PextraVersion="nightly-$(date +'%Y-%m-%d')"

- name: Upload TarGZ Release
uses: actions/upload-artifact@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,4 @@ equipment.txt
# Testing Temp Folder
/megamek/testresources/tmp/*
!/megamek/testresources/tmp/.keep
/megamek/resources/extraVersion.properties
10 changes: 9 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@ allprojects {
}

subprojects {
Properties versionProperties = new Properties()
versionProperties.load(rootProject.file("megamek/resources/Version.properties").newDataInputStream())
def processedVersion = String.format("%d.%02d.%02d", Integer.parseInt(versionProperties.getProperty("major")), Integer.parseInt(versionProperties.getProperty("minor")), Integer.parseInt(versionProperties.getProperty("patch")))

if (project.hasProperty("extraVersion")) {
processedVersion = String.format("%s-%s", processedVersion, project.getProperty('extraVersion'))
}

group = 'org.megamek'
version = '0.50.05-SNAPSHOT'
version = processedVersion
}


Expand Down
3 changes: 3 additions & 0 deletions megamek/resources/Version.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
major=0
minor=50
patch=5
108 changes: 35 additions & 73 deletions megamek/src/megamek/MegaMek.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
/*
* MegaMek - Copyright (C) 2005, 2006 Ben Mazur ([email protected])
* Copyright © 2013 Edward Cullen ([email protected])
* Copyright (c) 2014-2024 - The MegaMek Team. All Rights Reserved.
* Copyright (C) 2014-2025 The MegaMek Team. All Rights Reserved.
*
* This file is part of MegaMek.
*
* MegaMek is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* it under the terms of the GNU General Public License (GPL),
* version 3 or (at your option) any later version,
* as published by the Free Software Foundation.
*
* MegaMek is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MegaMek. If not, see <http://www.gnu.org/licenses/>.
* A copy of the GPL should have been included with this project;
* if not, see <https://www.gnu.org/licenses/>.
*
* NOTICE: The MegaMek organization is a non-profit group of volunteers
* creating free software for the BattleTech community.
*
* MechWarrior, BattleMech, `Mech and AeroTech are registered trademarks
* of The Topps Company, Inc. All Rights Reserved.
*
* Catalyst Game Labs and the Catalyst Game Labs logo are trademarks of
* InMediaRes Productions, LLC.
*/
package megamek;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputFilter;
import java.lang.management.ManagementFactory;
import java.net.URL;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.NumberFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -70,7 +74,7 @@ public class MegaMek {

private static final NumberFormat numberFormatter = NumberFormat.getInstance();

private static final MMLogger logger = MMLogger.create(MegaMek.class);
private static final MMLogger LOGGER = MMLogger.create(MegaMek.class);
private static final SanityInputFilter sanityInputFilter = new SanityInputFilter();

public static void main(String... args) {
Expand All @@ -83,7 +87,9 @@ public static void main(String... args) {
options.setEnableExternalConfiguration(true);
options.setDsn("https://[email protected]/8");
options.setEnvironment("production");
options.setTracesSampleRate(0.2);
options.setTracesSampleRate(1.0);
options.setProfilesSampleRate(1.0);
options.setEnableAppStartProfiling(true);
options.setDebug(true);
options.setServerName("MegaMekClient");
options.setRelease(SuiteConstants.VERSION.toString());
Expand All @@ -96,7 +102,7 @@ public static void main(String... args) {
final String name = t.getClass().getName();
final String message = String.format(MMLoggingConstants.UNHANDLED_EXCEPTION, name);
final String title = String.format(MMLoggingConstants.UNHANDLED_EXCEPTION_TITLE, name);
logger.errorDialog(t, message, title);
LOGGER.errorDialog(t, message, title);
});

// Second, let's handle logging
Expand All @@ -109,12 +115,12 @@ public static void main(String... args) {
try {
parser.parse();
} catch (AbstractCommandLineParser.ParseException e) {
logger.fatal(e, String.format(MMLoggingConstants.AP_INCORRECT_ARGUMENTS, e.getMessage(), parser.help()));
LOGGER.fatal(e, String.format(MMLoggingConstants.AP_INCORRECT_ARGUMENTS, e.getMessage(), parser.help()));
System.exit(1);
}

// log jvm parameters
logger.info(ManagementFactory.getRuntimeMXBean().getInputArguments());
LOGGER.info(ManagementFactory.getRuntimeMXBean().getInputArguments());

String[] restArgs = parser.getRestArgs();

Expand Down Expand Up @@ -152,7 +158,7 @@ public static void main(String... args) {
}

public static void initializeLogging(final String originProject) {
logger.info(getUnderlyingInformation(originProject));
LOGGER.info(getUnderlyingInformation(originProject));
}

public static SuitePreferences getMMPreferences() {
Expand All @@ -163,50 +169,6 @@ public static MMOptions getMMOptions() {
return mmOptions;
}

/**
* Calculates the SHA-256 hash of the MegaMek.jar file Used primarily for purposes of checksum comparison when
* connecting a new client.
*
* @return String representing the SHA-256 hash
*/
public static @Nullable String getMegaMekSHA256() {
StringBuilder sb = new StringBuilder();

String filename = "MegaMek.jar";
if (new File("lib/" + filename).exists()) {
filename = "lib/" + filename;
}

if (!new File(filename).exists()) {
logger.warn("MegaMek.jar not found. Returning null checksum.");
return null;
}

MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException e) {
logger.error(e, "SHA-256 Algorithm Can't be Found");
return null;
}

try (InputStream is = new FileInputStream(filename); InputStream dis = new DigestInputStream(is, md)) {
while (0 < dis.read()) {
// Idle Timer...
}

byte[] digest = md.digest();
for (byte d : digest) {
sb.append(String.format("%02x", d));
}
} catch (Exception e) {
logger.error(e, "Error Calculating Hash");
return null;
}

return sb.toString();
}

/**
* This function returns the memory used in the heap (heap memory - free memory).
*
Expand All @@ -225,7 +187,7 @@ public static String getMemoryUsed() {
* @param args the arguments to the dedicated server.
*/
private static void startDedicatedServer(String... args) {
logger.info(MMLoggingConstants.SC_STARTING_DEDICATED_SERVER, Arrays.toString(args));
LOGGER.info(MMLoggingConstants.SC_STARTING_DEDICATED_SERVER, Arrays.toString(args));
DedicatedServer.start(args);
}

Expand All @@ -245,7 +207,7 @@ private static void startHost(String... args) {
final String message = String.format(MMLoggingConstants.AP_INCORRECT_ARGUMENTS,
e.getMessage(),
parser.help());
logger.error(e, message);
LOGGER.error(e, message);
System.exit(1);
}

Expand All @@ -254,7 +216,7 @@ private static void startHost(String... args) {
MMConstants.LOCALHOST,
PreferenceManager.getClientPreferences().getLastPlayerName());

logger.info(MMLoggingConstants.SC_STARTING_HOST_SERVER, Arrays.toString(args));
LOGGER.info(MMLoggingConstants.SC_STARTING_HOST_SERVER, Arrays.toString(args));

SwingUtilities.invokeLater(() -> {
MegaMekGUI mmg = new MegaMekGUI();
Expand Down Expand Up @@ -284,7 +246,7 @@ private static void startQuickLoad(String... args) {
try {
parser.parse();
} catch (AbstractCommandLineParser.ParseException e) {
logger.error(e, String.format(MMLoggingConstants.AP_INCORRECT_ARGUMENTS, e.getMessage(), parser.help()));
LOGGER.error(e, String.format(MMLoggingConstants.AP_INCORRECT_ARGUMENTS, e.getMessage(), parser.help()));
System.exit(1);
}

Expand All @@ -293,7 +255,7 @@ private static void startQuickLoad(String... args) {
MMConstants.LOCALHOST,
PreferenceManager.getClientPreferences().getLastPlayerName());

logger.info(MMLoggingConstants.SC_STARTING_HOST_SERVER, Arrays.toString(args));
LOGGER.info(MMLoggingConstants.SC_STARTING_HOST_SERVER, Arrays.toString(args));

SwingUtilities.invokeLater(() -> {
MegaMekGUI mmg = new MegaMekGUI();
Expand Down Expand Up @@ -324,7 +286,7 @@ private static void startClient(String... args) {
try {
parser.parse();
} catch (AbstractCommandLineParser.ParseException e) {
logger.error(e, String.format(MMLoggingConstants.AP_INCORRECT_ARGUMENTS, e.getMessage(), parser.help()));
LOGGER.error(e, String.format(MMLoggingConstants.AP_INCORRECT_ARGUMENTS, e.getMessage(), parser.help()));
System.exit(1);
}

Expand All @@ -333,7 +295,7 @@ private static void startClient(String... args) {
MMConstants.LOCALHOST,
PreferenceManager.getClientPreferences().getLastPlayerName());

logger.info(MMLoggingConstants.SC_STARTING_CLIENT_SERVER, Arrays.toString(args));
LOGGER.info(MMLoggingConstants.SC_STARTING_CLIENT_SERVER, Arrays.toString(args));

SwingUtilities.invokeLater(() -> {
MegaMekGUI mmg = new MegaMekGUI();
Expand All @@ -346,15 +308,15 @@ private static void startGifWriter(String... args) {
try {
GifWriter.createGifFromGameSummary(args[0]);
} catch (IOException e) {
logger.error(e, "Error creating GIF");
LOGGER.error(e, "Error creating GIF");
}
}

/**
* Starts MegaMek's splash GUI
*/
private static void startGUI() {
logger.info("Starting MegaMekGUI.");
LOGGER.info("Starting MegaMekGUI.");
SwingUtilities.invokeLater(() -> new MegaMekGUI().start(true));
}

Expand Down
Loading