-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add version properties to jar and use it for /poseidon (#122)
* Add version properties to jar * Improve build and test * Remove invalid step 9 * Additional version info * Remove unnecessary GitHub action fields * fix typo * Improve Poseidon version command * Dynamically get application name for forks * Update Poseidon name in pom * Fix version.properties not including all fields
- Loading branch information
Showing
7 changed files
with
208 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,25 +15,85 @@ jobs: | |
runs-on: ubuntu-latest | ||
|
||
steps: | ||
# Step 1: Checkout the repository | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
# Step 2: Set up JDK 1.8 | ||
- name: Set up JDK 1.8 | ||
uses: actions/setup-java@v2 | ||
with: | ||
distribution: 'temurin' | ||
java-version: 8 | ||
|
||
# Step 3: Get the version from pom.xml | ||
- name: Get the version from pom.xml | ||
id: get_version | ||
run: echo "PROJECT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV | ||
|
||
# Step 4: Generate custom release version | ||
- name: Generate Release Version | ||
id: release_version | ||
run: | | ||
DATE=$(date +'%y%m%d-%H%M') | ||
SHA=$(echo $GITHUB_SHA | cut -c1-7) | ||
RELEASE_VERSION="${PROJECT_VERSION}-${DATE}-${SHA}" | ||
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV | ||
# Step 5: Create version.properties file | ||
- name: Create version.properties file | ||
run: | | ||
mkdir -p src/main/resources | ||
# Application Information | ||
APP_NAME=$(mvn help:evaluate -Dexpression=project.name -q -DforceStdout) | ||
# Core Metadata | ||
echo "version=${{ env.RELEASE_VERSION }}" >> src/main/resources/version.properties | ||
echo "build_timestamp=$(date --utc +'%Y-%m-%dT%H:%M:%SZ')" >> src/main/resources/version.properties | ||
echo "git_branch=${{ github.ref_name }}" >> src/main/resources/version.properties | ||
echo "git_commit=${GITHUB_SHA}" >> src/main/resources/version.properties | ||
echo "app_name=${APP_NAME}" >> src/main/resources/version.properties | ||
echo "release_version=${{ env.RELEASE_VERSION }}" >> src/main/resources/version.properties | ||
echo "maven_version=${{ env.PROJECT_VERSION }}" >> src/main/resources/version.properties | ||
# Build Type | ||
if [[ "${{ github.ref }}" == "refs/heads/master" || "${{ github.ref }}" == "refs/heads/main" ]]; then | ||
BUILD_TYPE="production" | ||
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then | ||
BUILD_TYPE="pull_request" | ||
else | ||
BUILD_TYPE="development" | ||
fi | ||
echo "build_type=${BUILD_TYPE}" >> src/main/resources/version.properties | ||
# CI/CD Metadata | ||
echo "workflow_name=${{ github.workflow }}" >> src/main/resources/version.properties | ||
echo "workflow_run_id=${{ github.run_id }}" >> src/main/resources/version.properties | ||
echo "workflow_run_number=${{ github.run_number }}" >> src/main/resources/version.properties | ||
# Team or Author Information | ||
echo "build_author=${{ github.actor }}" >> src/main/resources/version.properties | ||
- name: Set up Maven | ||
uses: stCarolas/[email protected] | ||
with: | ||
maven-version: 3.9.1 | ||
|
||
- name: build application | ||
# Step 6: Build application | ||
- name: Build Application | ||
shell: bash | ||
run: | | ||
mvn clean install | ||
# Step 7: Run Tests | ||
- name: Run Tests | ||
shell: bash | ||
run: | | ||
mvn test | ||
# Step 8: Upload artifact | ||
- name: Upload artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: build-and-test-lts | ||
name: Java-Compatibility | ||
on: | ||
pull_request: | ||
types: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/main/java/com/legacyminecraft/poseidon/commands/PoseidonCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.legacyminecraft.poseidon.commands; | ||
|
||
import com.projectposeidon.api.PoseidonUUID; | ||
import com.projectposeidon.api.UUIDType; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Arrays; | ||
import java.util.Properties; | ||
import java.util.UUID; | ||
|
||
public class PoseidonCommand extends Command { | ||
|
||
private final Properties versionProperties = new Properties(); | ||
|
||
public PoseidonCommand(String name) { | ||
super(name); | ||
this.description = "Show data regarding the server's version of Project Poseidon"; | ||
this.usageMessage = "/poseidon"; | ||
this.setAliases(Arrays.asList("projectposeidon")); | ||
loadVersionProperties(); | ||
} | ||
|
||
private void loadVersionProperties() { | ||
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("version.properties")) { | ||
if (inputStream != null) { | ||
versionProperties.load(inputStream); | ||
} | ||
} catch (IOException e) { | ||
Bukkit.getLogger().warning("Failed to load version.properties: " + e.getMessage()); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean execute(CommandSender sender, String currentAlias, String[] args) { | ||
if (args.length == 0) { | ||
String appName = versionProperties.getProperty("app_name", "Unknown"); | ||
String releaseVersion = versionProperties.getProperty("release_version", "Unknown"); | ||
String mavenVersion = versionProperties.getProperty("maven_version", "Unknown"); | ||
String buildTimestamp = versionProperties.getProperty("build_timestamp", "Unknown"); | ||
String gitCommit = versionProperties.getProperty("git_commit", "Unknown"); | ||
String buildType = versionProperties.getProperty("build_type", "Unknown"); | ||
|
||
// Shorten the git commit hash to 7 characters | ||
if (gitCommit.length() > 7) { | ||
gitCommit = gitCommit.substring(0, 7); | ||
} | ||
|
||
if ("Unknown".equals(releaseVersion)) { | ||
sender.sendMessage(ChatColor.RED + "Warning: version.properties not found. This is a local or unconfigured build."); | ||
} else { | ||
sender.sendMessage(ChatColor.GRAY + "This server is running " + ChatColor.AQUA + appName + ChatColor.GRAY + ":"); | ||
sender.sendMessage(ChatColor.GRAY + " - Version: " + ChatColor.YELLOW + releaseVersion); | ||
sender.sendMessage(ChatColor.GRAY + " - Built at: " + ChatColor.YELLOW + buildTimestamp); | ||
sender.sendMessage(ChatColor.GRAY + " - Git SHA: " + ChatColor.YELLOW + gitCommit); | ||
|
||
if ("production".equalsIgnoreCase(buildType)) { | ||
sender.sendMessage(ChatColor.GREEN + "This is a release build."); | ||
} else if ("pull_request".equalsIgnoreCase(buildType)) { | ||
sender.sendMessage(ChatColor.BLUE + "This is a pull request build."); | ||
} else { | ||
sender.sendMessage(ChatColor.GRAY + "This is a development build."); | ||
} | ||
} | ||
} else if (args.length == 1) { | ||
if (args[0].equalsIgnoreCase("uuid")) { | ||
sender.sendMessage(ChatColor.GRAY + "Please specify a user /poseidon uuid (username)"); | ||
} else { | ||
sender.sendMessage(ChatColor.GRAY + "Unknown sub command."); | ||
} | ||
} else { | ||
if (!args[0].equalsIgnoreCase("uuid")) { | ||
sender.sendMessage(ChatColor.GRAY + "Unknown sub command."); | ||
} else { | ||
UUID uuid = PoseidonUUID.getPlayerUUIDFromCache(args[1], true); | ||
if (uuid == null) { | ||
uuid = PoseidonUUID.getPlayerUUIDFromCache(args[1], false); | ||
} | ||
|
||
if (uuid == null) { | ||
sender.sendMessage(ChatColor.GRAY + "Unable to locate the UUID of the player called: " + ChatColor.WHITE + args[1] + ChatColor.GRAY + ". Please remember usernames are cap sensitive"); | ||
} else { | ||
sender.sendMessage(ChatColor.GRAY + "Username: " + args[1]); | ||
sender.sendMessage(ChatColor.GRAY + "UUID: " + uuid.toString()); | ||
UUIDType uuidType = PoseidonUUID.getPlayerUUIDCacheStatus(args[1]); | ||
if (uuidType.equals(UUIDType.ONLINE)) { | ||
sender.sendMessage(ChatColor.GRAY + "UUID Type: " + ChatColor.GREEN + "Online"); | ||
} else if (uuidType.equals(UUIDType.OFFLINE)) { | ||
sender.sendMessage(ChatColor.GRAY + "UUID Type: " + ChatColor.RED + "Offline"); | ||
} else { | ||
sender.sendMessage(ChatColor.GRAY + "UUID Type: " + ChatColor.DARK_RED + "UNKNOWN"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 0 additions & 62 deletions
62
src/main/java/org/bukkit/command/defaults/PoseidonCommand.java
This file was deleted.
Oops, something went wrong.