Skip to content

Commit

Permalink
refactor: Improve project versioning (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
zlataovce committed May 13, 2024
1 parent 4c2b458 commit c369192
Show file tree
Hide file tree
Showing 19 changed files with 188 additions and 249 deletions.
20 changes: 10 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ of a few ways:
This component is used to embed the current version of the software into the documentation. An example of this would be:

```jsx
<SoftwareVersion versionType={"maj-min"}/> // E.g 1.19.2
<SoftwareVersion versionType={"maj"}/> // E.g 1.19
<SoftwareVersion versionType={"max"}/> // E.g 1.20.4
<SoftwareVersion versionType={"maj-min-pat"}/> // e.g. 1.19.2
<SoftwareVersion versionType={"maj-min"}/> // e.g. 1.19
<SoftwareVersion versionType={"maj"}/> // e.g. 1

// You can set the project name to be used for the versioning:
<SoftwareVersion versionType={"maj-min"} project={"velocity"}/> // Project defaults to Paper
// You can set the project name to be used for the versioning (defaults to paper):
<SoftwareVersion versionType={"maj-min-pat"} project={"velocity"}/> // e.g. 3.3.0-SNAPSHOT
```

2. `Javadoc` component
Expand All @@ -137,17 +137,17 @@ of a few ways:
version: '1.0'
main: io.papermc.testplugin.TestPlugin
description: Paper Test Plugin
api-version: '%%_MAJ_MC_%%'
api-version: '%%_MAJ_MIN_PAT_MC_%%'
bootstrapper: io.papermc.testplugin.TestPluginBootstrap
loader: io.papermc.testplugin.TestPluginLoader
```
</VersionFormattedCode>

// The possible placeholders are:
%%_MAJ_MC_%% - Major Paper Version (E.g. 1.20)
%%_MAJ_MIN_MC_%% - Major-Minor Paper Version (E.g. 1.20.4)
%%_MAJ_VEL_%% - Major Velocity Version (E.g. 3.3)
%%_MAJ_MIN_VEL_%% - Major-Minor Velocity Version (E.g. 3.3.0)
%%_MAJ_MIN_MC_%% - Major-Minor Paper Version (E.g. 1.20)
%%_MAJ_MIN_PAT_MC_%% - Major-Minor-Patch Paper Version (E.g. 1.20.4)
%%_MAJ_MIN_VEL_%% - Major Velocity Version (E.g. 3.1.0)
%%_MAJ_MIN_PAT_VEL_%% - Major-Minor-Patch Velocity Version (E.g. 3.1.1-SNAPSHOT)
````

When the major version of the software changes, the docs will still need to have a "snapshot" created to keep documentation
Expand Down
4 changes: 2 additions & 2 deletions config-specs/paper/spigot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ messages:
than the client version.
The message is formatted with legacy "&" style formatting, and "\\n" for
newlines. Additionally, it replaces {0} with "%%_MAJ_MIN_MC_%%" (the current server
newlines. Additionally, it replaces {0} with "%%_MAJ_MIN_PAT_MC_%%" (the current server
version)
outdated-server:
default: "Outdated server! I'm still on {0}"
Expand All @@ -74,7 +74,7 @@ messages:
than the client version.
The message is formatted with legacy "&" style formatting, and "\\n" for
newlines. Additionally, it replaces {0} with "%%_MAJ_MIN_MC_%%" (the current server
newlines. Additionally, it replaces {0} with "%%_MAJ_MIN_PAT_MC_%%" (the current server
version)
restart:
default: Server is restarting
Expand Down
4 changes: 2 additions & 2 deletions docs/misc/downloads-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ This will get the latest available Minecraft version for the given project.
#!/usr/bin/env sh
PROJECT="paper"
MINECRAFT_VERSION="%%_MAJ_MIN_MC_%%"
MINECRAFT_VERSION="%%_MAJ_MIN_PAT_MC_%%"
LATEST_BUILD=$(curl -s https://api.papermc.io/v2/projects/${PROJECT}/versions/${MINECRAFT_VERSION}/builds | \
jq '.builds | map(select(.channel == "default") | .build) | .[-1]')
Expand All @@ -64,7 +64,7 @@ This will get the latest stable build for the given project and Minecraft versio
#!/usr/bin/env sh
PROJECT="paper"
MINECRAFT_VERSION="%%_MAJ_MIN_MC_%%"
MINECRAFT_VERSION="%%_MAJ_MIN_PAT_MC_%%"
LATEST_BUILD=$(curl -s https://api.papermc.io/v2/projects/${PROJECT}/versions/${MINECRAFT_VERSION}/builds | \
jq -r '.builds | map(select(.channel == "default") | .build) | .[-1]')
Expand Down
2 changes: 1 addition & 1 deletion docs/paper/dev/getting-started/paper-plugins.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ name: Paper-Test-Plugin
version: '1.0'
main: io.papermc.testplugin.TestPlugin
description: Paper Test Plugin
api-version: '%%_MAJ_MC_%%'
api-version: '%%_MAJ_MIN_PAT_MC_%%'
bootstrapper: io.papermc.testplugin.TestPluginBootstrap
loader: io.papermc.testplugin.TestPluginLoader
```
Expand Down
6 changes: 3 additions & 3 deletions docs/paper/dev/getting-started/plugin-yml.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ main: io.papermc.testplugin.ExamplePlugin
description: An example plugin
author: PaperMC
website: https://papermc.io
api-version: '%%_MAJ_MC_%%'
api-version: '%%_MAJ_MIN_PAT_MC_%%'
```
</VersionFormattedCode>

Expand Down Expand Up @@ -92,8 +92,8 @@ This will be shown in the plugin info commands.

The version of the Paper API that your plugin is using. This doesn't include the minor version.
Servers with a version lower than the version specified here will refuse to load the plugin.
The valid versions are 1.13 - <SoftwareVersion versionType={"maj-min"}/>.
- <VersionFormattedCode>`api-version: '%%_MAJ_MIN_MC_%%'`</VersionFormattedCode>
The valid versions are 1.13 - <SoftwareVersion versionType={"maj-min-pat"}/>.
- <VersionFormattedCode>`api-version: '%%_MAJ_MIN_PAT_MC_%%'`</VersionFormattedCode>

:::info

Expand Down
2 changes: 1 addition & 1 deletion docs/paper/dev/getting-started/project-setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ repositories {
}
dependencies {
compileOnly("io.papermc.paper:paper-api:%%_MAJ_MIN_MC_%%-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:%%_MAJ_MIN_PAT_MC_%%-R0.1-SNAPSHOT")
}
java {
Expand Down
2 changes: 1 addition & 1 deletion docs/paper/dev/getting-started/userdev.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ file.
```
dependencies {
// Other Dependencies
paperweight.paperDevBundle("%%_MAJ_MIN_MC_%%-R0.1-SNAPSHOT")
paperweight.paperDevBundle("%%_MAJ_MIN_PAT_MC_%%-R0.1-SNAPSHOT")
}
```
</VersionFormattedCode>
Expand Down
2 changes: 1 addition & 1 deletion docs/paper/dev/misc/debugging.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ These will go after the `java` command and before `-jar`. Once you have done thi

<VersionFormattedCode language={"bash"}>
```
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 -jar paper-%%_MAJ_MIN_MC_%%.jar nogui
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 -jar paper-%%_MAJ_MIN_PAT_MC_%%.jar nogui
```
</VersionFormattedCode>

Expand Down
4 changes: 2 additions & 2 deletions docs/paper/dev/misc/internal-code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ with one of the following methods:

<VersionFormattedCode language={"java"}>
```
// Example value: %%_MAJ_MIN_MC_%%
// Example value: %%_MAJ_MIN_PAT_MC_%%
String minecraftVersion = Bukkit.getServer().getMinecraftVersion();
// Example value: %%_MAJ_MIN_MC_%%-R0.1-SNAPSHOT
// Example value: %%_MAJ_MIN_PAT_MC_%%-R0.1-SNAPSHOT
String bukkitVersion = Bukkit.getServer().getBukkitVersion();
// Example value for 1.20.1: 3465
Expand Down
2 changes: 1 addition & 1 deletion docs/velocity/admin/reference/server-compatibility.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ we can.

## Compatible game versions

As of this writing, Velocity is compatible with Minecraft 1.7.2 through <SoftwareVersion versionType={"max"}/>.
As of this writing, Velocity is compatible with Minecraft 1.7.2 through <SoftwareVersion/>.

## Vanilla setups

Expand Down
16 changes: 8 additions & 8 deletions docs/velocity/dev/getting-started/creating-your-first-plugin.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ Now we have created our project, we need configure our build system.

### Dependency

| Group ID | Artifact ID | Version |
|-----------------------|----------------|------------------------------------------------------------------|
| `com.velocitypowered` | `velocity-api` | <VersionFormattedCode>`%%_MAJ_MIN_VEL_%%`</VersionFormattedCode> |
| Group ID | Artifact ID | Version |
|-----------------------|----------------|----------------------------------------------------------------------|
| `com.velocitypowered` | `velocity-api` | <VersionFormattedCode>`%%_MAJ_MIN_PAT_VEL_%%`</VersionFormattedCode> |

### Javadocs

Expand Down Expand Up @@ -77,7 +77,7 @@ system's documentation ([Gradle](https://docs.gradle.org/current/userguide/userg
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>%%_MAJ_MIN_VEL_%%</version>
<version>%%_MAJ_MIN_PAT_VEL_%%</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand All @@ -98,8 +98,8 @@ repositories {
}
dependencies {
compileOnly("com.velocitypowered:velocity-api:%%_MAJ_MIN_VEL_%%")
annotationProcessor("com.velocitypowered:velocity-api:%%_MAJ_MIN_VEL_%%")
compileOnly("com.velocitypowered:velocity-api:%%_MAJ_MIN_PAT_VEL_%%")
annotationProcessor("com.velocitypowered:velocity-api:%%_MAJ_MIN_PAT_VEL_%%")
}
```
</VersionFormattedCode>
Expand All @@ -117,8 +117,8 @@ repositories {
}
dependencies {
compileOnly 'com.velocitypowered:velocity-api:%%_MAJ_MIN_VEL_%%'
annotationProcessor 'com.velocitypowered:velocity-api:%%_MAJ_MIN_VEL_%%'
compileOnly 'com.velocitypowered:velocity-api:%%_MAJ_MIN_PAT_VEL_%%'
annotationProcessor 'com.velocitypowered:velocity-api:%%_MAJ_MIN_PAT_VEL_%%'
}
```
</VersionFormattedCode>
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"@fontsource/jetbrains-mono": "5.0.20",
"@iconify/react": "4.1.1",
"@mdx-js/react": "3.0.1",
"axios": "1.6.8",
"clsx": "2.1.0",
"docusaurus-plugin-sass": "^0.2.5",
"js-yaml": "4.1.0",
Expand Down
42 changes: 0 additions & 42 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 22 additions & 12 deletions src/components/versioning/Javadoc.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
import React, { useEffect, useState } from "react";
import { getProperty } from "../Property";
import SoftwareVersionFetcher from "../../minecraft-versioning/SoftwareVersionFetcher";
import {
getProjectVersion,
VersionType,
type Project,
type DocusaurusVersion,
} from "../../util/versionUtils";
import { useDocsVersion } from "@docusaurus/theme-common/internal";

type TargetResolver = (module?: string) => Promise<string>;
type TargetResolver = (
currentVersion: DocusaurusVersion | null,
module?: string
) => Promise<string>;

const createProjectTarget = (project: string, majorOnly: boolean = false): TargetResolver => {
return async () => {
let version = await SoftwareVersionFetcher.getMajorVersion(project);
if (majorOnly) {
version = version.split(".")[0] + ".0.0";
}
const createProjectTarget = (
project: Project,
versionType: VersionType = VersionType.MajorMinorPatch
): TargetResolver => {
return async (currentVersion) => {
const version = await getProjectVersion(project, currentVersion, versionType);

return `https://jd.papermc.io/${project}/${version}`;
};
};

const targets: { [project: string]: TargetResolver } = {
paper: createProjectTarget("paper"),
velocity: createProjectTarget("velocity", true),
java: async (module) => {
velocity: createProjectTarget("velocity", VersionType.MajorZeroed),
java: async (_, module) => {
const version = getProperty("DOCS_JAVA") ?? "21";

return `https://docs.oracle.com/en/java/javase/${version}/docs/api/${module || "java.base"}`;
Expand All @@ -35,11 +44,12 @@ const formatName = (name: string): string => {
export default function Javadoc({ name, module, project = "paper", children }: JavadocProps) {
const [href, setHref] = useState<string>(null);

const versionMeta = useDocsVersion();
useEffect(() => {
(async () => {
const resolve = targets[project];
if (resolve) {
const target = await resolve(module);
const target = await resolve(versionMeta, module);

setHref(`${target}/${formatName(name)}`);
}
Expand All @@ -52,6 +62,6 @@ export default function Javadoc({ name, module, project = "paper", children }: J
interface JavadocProps {
name: string;
module?: string;
project?: "paper" | "velocity" | "java";
project?: Project | "java";
children: any;
}

0 comments on commit c369192

Please sign in to comment.