Merge branch 'feature/auto-release-tests'
@@ -1,16 +1,6 @@
1
# Release pipeline: runs when a version tag is created (e.g. v1.8.0 or 1.8.0).
2
#
3
# Required CI/CD variable:
4
# CI_PUSH_TOKEN — Project Access Token (Maintainer) with scopes:
5
# `write_repository`, `self_rotate` (or `api`), and `api`
6
# (api is required to write the rotated token back to this variable).
7
#
8
# Flow:
9
# 1. validate — reject invalid or non-increasing versions
10
# 2. bump — update version in project files and push commit (ci.skip; tag unchanged)
11
# 3. build — produce BirdCourier-<version>.jar and upload to Package Registry
12
# 4. release — publish a GitLab Release with the jar attached
13
# 5. rotate-token — self-rotate CI_PUSH_TOKEN and update the CI/CD variable
1
# GitLab-backup van de BlueGit-pipeline.
2
# Draait op een tag: test, daarna build en automatische GitLab-release
3
# (geen manual-stap). BlueGit zelf gebruikt blue-ci-cd.yml.
14
4
15
5
workflow:
16
6
rules:
@@ -22,12 +12,19 @@ variables:
22
12
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
23
13
24
14
stages:
15
- test
25
16
- validate
26
17
- bump
27
18
- build
28
19
- release
29
20
- rotate
30
21
22
test:
23
stage: test
24
image: gradle:jdk25
25
script:
26
- gradle --no-daemon test
27
31
28
.validate_image:
32
29
image: alpine:3.20
33
30
before_script:
@@ -38,6 +35,7 @@ stages:
38
35
validate:version:
39
36
extends: .validate_image
40
37
stage: validate
38
needs: [test]
41
39
script:
42
40
- ./scripts/release.sh validate
43
41
artifacts:
@@ -1,16 +1,6 @@1
# Release pipeline: runs when a version tag is created (e.g. v1.8.0 or 1.8.0).1
# GitLab-backup van de BlueGit-pipeline.2
#2
# Draait op een tag: test, daarna build en automatische GitLab-release3
# Required CI/CD variable:3
# (geen manual-stap). BlueGit zelf gebruikt blue-ci-cd.yml.4
# CI_PUSH_TOKEN — Project Access Token (Maintainer) with scopes:5
# `write_repository`, `self_rotate` (or `api`), and `api`6
# (api is required to write the rotated token back to this variable).7
#8
# Flow:9
# 1. validate — reject invalid or non-increasing versions10
# 2. bump — update version in project files and push commit (ci.skip; tag unchanged)11
# 3. build — produce BirdCourier-<version>.jar and upload to Package Registry12
# 4. release — publish a GitLab Release with the jar attached13
# 5. rotate-token — self-rotate CI_PUSH_TOKEN and update the CI/CD variable14
4
15
workflow:5
workflow:16
rules:6
rules:@@ -22,12 +12,19 @@ variables:22
GRADLE_OPTS: "-Dorg.gradle.daemon=false"12
GRADLE_OPTS: "-Dorg.gradle.daemon=false"23
13
24
stages:14
stages:15
- test25
- validate16
- validate26
- bump17
- bump27
- build18
- build28
- release19
- release29
- rotate20
- rotate30
21
22
test:23
stage: test24
image: gradle:jdk2525
script:26
- gradle --no-daemon test27
31
.validate_image:28
.validate_image:32
image: alpine:3.2029
image: alpine:3.2033
before_script:30
before_script:@@ -38,6 +35,7 @@ stages:38
validate:version:35
validate:version:39
extends: .validate_image36
extends: .validate_image40
stage: validate37
stage: validate38
needs: [test]41
script:39
script:42
- ./scripts/release.sh validate40
- ./scripts/release.sh validate43
artifacts:41
artifacts:@@ -64,6 +64,20 @@ gradle build
64
64
65
65
The resulting JAR is `build/libs/BirdCourier-<version>.jar`.
66
66
67
Run the unit tests with:
68
69
```bash
70
gradle test
71
```
72
73
## Releases
74
75
On BlueGit, a master push runs the tests and builds the jar (no manual job).
76
Push a version tag (for example `1.1.4` or `v1.1.4`) to publish a release
77
automatically: the pipeline runs the tests, builds the jar, and attaches
78
`BirdCourier-<version>.jar` to the tag. A leading `v` on the tag is stripped
79
from the version and file name.
80
67
81
## Changelog
68
82
69
83
### 1.1.3
@@ -64,6 +64,20 @@ gradle build64
64
65
The resulting JAR is `build/libs/BirdCourier-<version>.jar`.65
The resulting JAR is `build/libs/BirdCourier-<version>.jar`.66
66
67
Run the unit tests with:68
69
```bash70
gradle test71
```72
73
## Releases74
75
On BlueGit, a master push runs the tests and builds the jar (no manual job).76
Push a version tag (for example `1.1.4` or `v1.1.4`) to publish a release77
automatically: the pipeline runs the tests, builds the jar, and attaches78
`BirdCourier-<version>.jar` to the tag. A leading `v` on the tag is stripped79
from the version and file name.80
67
## Changelog81
## Changelog68
82
69
### 1.1.383
### 1.1.3@@ -1,32 +1,34 @@
1
# BlueGit CI (vertaald uit .gitlab-ci.yml; GitLab is alleen nog backup).
1
# BlueGit CI voor BirdCourier.
2
2
#
3
# Op GitLab startte een nieuwe tag de release (validate, bump-commit terug naar
4
# master met CI_PUSH_TOKEN, build, GitLab-release, token roteren). Op BlueGit
5
# maakt de release-API de tag zelf, dus:
6
# master-push: version (hoogste tag + 1 patch, of RELEASE_VERSION) en build.
7
# Zonder tags blijft de versie die al in de projectbestanden staat (1.1.3).
8
# release: HANDMATIG (zoals op GitLab een bewuste tag), maakt tag + release
9
# met de jar. Nooit automatisch, nooit dubbel.
10
# De versie wordt alleen in de build gezet (zelfde bump als scripts/release.sh),
11
# er wordt geen bump-commit teruggepusht; CI_PUSH_TOKEN is niet meer nodig.
12
# Tag-pushes starten geen pipeline.
3
# master-push: test + build (geen release-job, zodat de pipeline op success
4
# eindigt in plaats van manual).
5
# tag-push: test + build, daarna automatisch release (geen manual-stap).
6
# De release-API voor bestaande tags maakt de tag niet aan of verplaatst die
7
# niet; de zip/jar komt uit dezelfde pipeline. Een leidende v op de tag wordt
8
# in de versie en jar-naam gestript.
13
9
14
10
workflow:
15
11
rules:
16
12
- if: $CI_COMMIT_TAG != ""
17
when: never
18
- if: $CI_COMMIT_BRANCH == "master"
13
- if: $CI_COMMIT_BRANCH != ""
19
14
- if: $CI_PIPELINE_SOURCE == "web"
20
15
- if: $CI_PIPELINE_SOURCE == "api"
21
16
22
17
variables:
23
18
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
24
19
25
stages: [build, release]
20
stages: [test, build, release]
21
22
test:
23
stage: test
24
image: gradle:jdk25
25
script:
26
- gradle --no-daemon test
26
27
27
28
build:artifacts:
28
29
stage: build
29
30
image: gradle:jdk25
31
needs: [test]
30
32
script:
31
33
- bash scripts/ci/build.sh
32
34
artifacts:
@@ -36,11 +38,9 @@ build:artifacts:
36
38
release:
37
39
stage: release
38
40
image: bluegit/base
39
needs: [build:artifacts]
40
when: manual
41
needs: [test, build:artifacts]
41
42
resource_group: release
42
43
rules:
43
- if: $CI_COMMIT_BRANCH == "master"
44
when: manual
44
- if: $CI_COMMIT_TAG != ""
45
45
script:
46
46
- bash scripts/ci/bluegit-release.sh
@@ -1,32 +1,34 @@1
# BlueGit CI (vertaald uit .gitlab-ci.yml; GitLab is alleen nog backup).1
# BlueGit CI voor BirdCourier.2
#2
#3
# Op GitLab startte een nieuwe tag de release (validate, bump-commit terug naar3
# master-push: test + build (geen release-job, zodat de pipeline op success4
# master met CI_PUSH_TOKEN, build, GitLab-release, token roteren). Op BlueGit4
# eindigt in plaats van manual).5
# maakt de release-API de tag zelf, dus:5
# tag-push: test + build, daarna automatisch release (geen manual-stap).6
# master-push: version (hoogste tag + 1 patch, of RELEASE_VERSION) en build.6
# De release-API voor bestaande tags maakt de tag niet aan of verplaatst die7
# Zonder tags blijft de versie die al in de projectbestanden staat (1.1.3).7
# niet; de zip/jar komt uit dezelfde pipeline. Een leidende v op de tag wordt8
# release: HANDMATIG (zoals op GitLab een bewuste tag), maakt tag + release8
# in de versie en jar-naam gestript.9
# met de jar. Nooit automatisch, nooit dubbel.10
# De versie wordt alleen in de build gezet (zelfde bump als scripts/release.sh),11
# er wordt geen bump-commit teruggepusht; CI_PUSH_TOKEN is niet meer nodig.12
# Tag-pushes starten geen pipeline.13
9
14
workflow:10
workflow:15
rules:11
rules:16
- if: $CI_COMMIT_TAG != ""12
- if: $CI_COMMIT_TAG != ""17
when: never13
- if: $CI_COMMIT_BRANCH != ""18
- if: $CI_COMMIT_BRANCH == "master"19
- if: $CI_PIPELINE_SOURCE == "web"14
- if: $CI_PIPELINE_SOURCE == "web"20
- if: $CI_PIPELINE_SOURCE == "api"15
- if: $CI_PIPELINE_SOURCE == "api"21
16
22
variables:17
variables:23
GRADLE_OPTS: "-Dorg.gradle.daemon=false"18
GRADLE_OPTS: "-Dorg.gradle.daemon=false"24
19
25
stages: [build, release]20
stages: [test, build, release]21
22
test:23
stage: test24
image: gradle:jdk2525
script:26
- gradle --no-daemon test26
27
27
build:artifacts:28
build:artifacts:28
stage: build29
stage: build29
image: gradle:jdk2530
image: gradle:jdk2531
needs: [test]30
script:32
script:31
- bash scripts/ci/build.sh33
- bash scripts/ci/build.sh32
artifacts:34
artifacts:@@ -36,11 +38,9 @@ build:artifacts:36
release:38
release:37
stage: release39
stage: release38
image: bluegit/base40
image: bluegit/base39
needs: [build:artifacts]41
needs: [test, build:artifacts]40
when: manual41
resource_group: release42
resource_group: release42
rules:43
rules:43
- if: $CI_COMMIT_BRANCH == "master"44
- if: $CI_COMMIT_TAG != ""44
when: manual45
script:45
script:46
- bash scripts/ci/bluegit-release.sh46
- bash scripts/ci/bluegit-release.sh@@ -15,6 +15,9 @@ repositories {
15
15
16
16
dependencies {
17
17
compileOnly("io.papermc.paper:paper-api:26.2.build.112-stable")
18
testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
19
testImplementation("org.yaml:snakeyaml:2.4")
20
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
18
21
}
19
22
20
23
java {
@@ -25,3 +28,7 @@ tasks.withType<JavaCompile>().configureEach {
25
28
options.encoding = "UTF-8"
26
29
options.release.set(25)
27
30
}
31
32
tasks.test {
33
useJUnitPlatform()
34
}
@@ -15,6 +15,9 @@ repositories {15
15
16
dependencies {16
dependencies {17
compileOnly("io.papermc.paper:paper-api:26.2.build.112-stable")17
compileOnly("io.papermc.paper:paper-api:26.2.build.112-stable")18
testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")19
testImplementation("org.yaml:snakeyaml:2.4")20
testRuntimeOnly("org.junit.platform:junit-platform-launcher")18
}21
}19
22
20
java {23
java {@@ -25,3 +28,7 @@ tasks.withType<JavaCompile>().configureEach {25
options.encoding = "UTF-8"28
options.encoding = "UTF-8"26
options.release.set(25)29
options.release.set(25)27
}30
}31
32
tasks.test {33
useJUnitPlatform()34
}@@ -1,15 +1,26 @@
1
1
#!/usr/bin/env bash
2
# BlueGit: release maken met de jar als asset.
3
# De release-API maakt de tag zelf aan en weigert een bestaande tag, dus een
4
# release kan nooit twee keer ontstaan. Overslaan als HEAD al een tag heeft.
2
# BlueGit: publicatie van een bestaande tag (de tag is al gepusht).
3
# POST .../releases/$TAG/assets maakt de release met de jar als asset en
4
# wijzigt de tag niet. Alleen job-token, alleen in de tag-pipeline.
5
5
set -euo pipefail
6
: "${CI_API_URL:?}" "${CI_JOB_TOKEN:?}" "${CI_COMMIT_SHA:?}" "${CI_PROJECT_PATH:?}"
7
v="$(cat build/version.txt)"
8
git fetch -q --tags origin 2>/dev/null || true
9
if [[ -n "$(git tag --points-at HEAD)" ]]; then echo "Geen release: HEAD heeft al een tag."; exit 0; fi
10
if git rev-parse -q --verify "refs/tags/$v" >/dev/null; then echo "Tag $v bestaat al" >&2; exit 1; fi
11
body="$(printf '{"tag":"%s","commit":"%s","name":"BirdCourier %s","body":"Release %s of BirdCourier.","assets":[{"job":"build:artifacts","path":"build/out/BirdCourier.jar","name":"BirdCourier-%s.jar"}]}' "$v" "$CI_COMMIT_SHA" "$v" "$v" "$v")"
6
: "${CI_API_URL:?}" "${CI_JOB_TOKEN:?}" "${CI_COMMIT_SHA:?}" "${CI_PROJECT_PATH:?}" "${CI_COMMIT_TAG:?}"
7
v="${CI_COMMIT_TAG#v}"
8
path="build/out/BirdCourier.jar"
9
name="BirdCourier-${v}.jar"
10
[[ -f "$path" ]] || { echo "ontbreekt: $path" >&2; ls -la build/out >&2 || true; exit 1; }
11
12
body="$(python3 -c 'import json,sys; print(json.dumps({
13
"commit": sys.argv[1],
14
"name": "BirdCourier "+sys.argv[2],
15
"body": "Release "+sys.argv[2]+" of BirdCourier.",
16
"assets": [{"job": "build:artifacts", "path": sys.argv[3], "name": sys.argv[4]}],
17
}))' "$CI_COMMIT_SHA" "$v" "$path" "$name")"
18
12
19
resp="$(mktemp)"
13
code="$(curl -sS -o "$resp" -w '%{http_code}' -X POST "$CI_API_URL/repos/$CI_PROJECT_PATH/releases" -H "Authorization: Bearer $CI_JOB_TOKEN" -H "Content-Type: application/json" -d "$body")" || code=000
20
code="$(curl -sS -o "$resp" -w '%{http_code}' -X POST \
21
"$CI_API_URL/repos/$CI_PROJECT_PATH/releases/${CI_COMMIT_TAG}/assets" \
22
-H "Authorization: Bearer $CI_JOB_TOKEN" \
23
-H "Content-Type: application/json" \
24
--data-binary "$body")" || code=000
14
25
cat "$resp"; echo
15
26
[[ "$code" == 2* ]] || { echo "Release-API gaf HTTP $code" >&2; exit 1; }
@@ -1,15 +1,26 @@1
#!/usr/bin/env bash1
#!/usr/bin/env bash2
# BlueGit: release maken met de jar als asset.2
# BlueGit: publicatie van een bestaande tag (de tag is al gepusht).3
# De release-API maakt de tag zelf aan en weigert een bestaande tag, dus een3
# POST .../releases/$TAG/assets maakt de release met de jar als asset en4
# release kan nooit twee keer ontstaan. Overslaan als HEAD al een tag heeft.4
# wijzigt de tag niet. Alleen job-token, alleen in de tag-pipeline.5
set -euo pipefail5
set -euo pipefail6
: "${CI_API_URL:?}" "${CI_JOB_TOKEN:?}" "${CI_COMMIT_SHA:?}" "${CI_PROJECT_PATH:?}"6
: "${CI_API_URL:?}" "${CI_JOB_TOKEN:?}" "${CI_COMMIT_SHA:?}" "${CI_PROJECT_PATH:?}" "${CI_COMMIT_TAG:?}"7
v="$(cat build/version.txt)"7
v="${CI_COMMIT_TAG#v}"8
git fetch -q --tags origin 2>/dev/null || true8
path="build/out/BirdCourier.jar"9
if [[ -n "$(git tag --points-at HEAD)" ]]; then echo "Geen release: HEAD heeft al een tag."; exit 0; fi9
name="BirdCourier-${v}.jar"10
if git rev-parse -q --verify "refs/tags/$v" >/dev/null; then echo "Tag $v bestaat al" >&2; exit 1; fi10
[[ -f "$path" ]] || { echo "ontbreekt: $path" >&2; ls -la build/out >&2 || true; exit 1; }11
body="$(printf '{"tag":"%s","commit":"%s","name":"BirdCourier %s","body":"Release %s of BirdCourier.","assets":[{"job":"build:artifacts","path":"build/out/BirdCourier.jar","name":"BirdCourier-%s.jar"}]}' "$v" "$CI_COMMIT_SHA" "$v" "$v" "$v")"11
12
body="$(python3 -c 'import json,sys; print(json.dumps({13
"commit": sys.argv[1],14
"name": "BirdCourier "+sys.argv[2],15
"body": "Release "+sys.argv[2]+" of BirdCourier.",16
"assets": [{"job": "build:artifacts", "path": sys.argv[3], "name": sys.argv[4]}],17
}))' "$CI_COMMIT_SHA" "$v" "$path" "$name")"18
12
resp="$(mktemp)"19
resp="$(mktemp)"13
code="$(curl -sS -o "$resp" -w '%{http_code}' -X POST "$CI_API_URL/repos/$CI_PROJECT_PATH/releases" -H "Authorization: Bearer $CI_JOB_TOKEN" -H "Content-Type: application/json" -d "$body")" || code=00020
code="$(curl -sS -o "$resp" -w '%{http_code}' -X POST \21
"$CI_API_URL/repos/$CI_PROJECT_PATH/releases/${CI_COMMIT_TAG}/assets" \22
-H "Authorization: Bearer $CI_JOB_TOKEN" \23
-H "Content-Type: application/json" \24
--data-binary "$body")" || code=00014
cat "$resp"; echo25
cat "$resp"; echo15
[[ "$code" == 2* ]] || { echo "Release-API gaf HTTP $code" >&2; exit 1; }26
[[ "$code" == 2* ]] || { echo "Release-API gaf HTTP $code" >&2; exit 1; }@@ -1,10 +1,11 @@
1
1
#!/usr/bin/env bash
2
# Versie bepalen (hoogste tag + 1 patch of RELEASE_VERSION), zelfde bump als
3
# scripts/release.sh (alleen lokaal in de build, geen commit), jar bouwen.
4
# Zonder tags: de versie die al in build.gradle.kts staat, zodat de eerste
5
# import van 1.1.3 niet als 0.0.1 wordt gebouwd.
2
# Versie bepalen (tag, RELEASE_VERSION, hoogste tag + 1 patch, of de versie
3
# die al in build.gradle.kts staat), zelfde bump als scripts/release.sh
4
# (alleen lokaal in de build, geen commit), jar bouwen.
6
5
set -euo pipefail
7
if [ -n "${RELEASE_VERSION:-}" ]; then v="${RELEASE_VERSION#v}"; else
6
if [ -n "${RELEASE_VERSION:-}" ]; then v="${RELEASE_VERSION#v}"
7
elif [ -n "${CI_COMMIT_TAG:-}" ]; then v="${CI_COMMIT_TAG#v}"
8
else
8
9
last="$(git tag -l | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+$' | sed 's/^v//' | sort -V | tail -n1 || true)"
9
10
if [ -z "$last" ]; then
10
11
v="$(sed -n 's/^version = "\(.*\)"/\1/p' build.gradle.kts)"
@@ -1,10 +1,11 @@1
#!/usr/bin/env bash1
#!/usr/bin/env bash2
# Versie bepalen (hoogste tag + 1 patch of RELEASE_VERSION), zelfde bump als2
# Versie bepalen (tag, RELEASE_VERSION, hoogste tag + 1 patch, of de versie3
# scripts/release.sh (alleen lokaal in de build, geen commit), jar bouwen.3
# die al in build.gradle.kts staat), zelfde bump als scripts/release.sh4
# Zonder tags: de versie die al in build.gradle.kts staat, zodat de eerste4
# (alleen lokaal in de build, geen commit), jar bouwen.5
# import van 1.1.3 niet als 0.0.1 wordt gebouwd.6
set -euo pipefail5
set -euo pipefail7
if [ -n "${RELEASE_VERSION:-}" ]; then v="${RELEASE_VERSION#v}"; else6
if [ -n "${RELEASE_VERSION:-}" ]; then v="${RELEASE_VERSION#v}"7
elif [ -n "${CI_COMMIT_TAG:-}" ]; then v="${CI_COMMIT_TAG#v}"8
else8
last="$(git tag -l | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+$' | sed 's/^v//' | sort -V | tail -n1 || true)"9
last="$(git tag -l | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+$' | sed 's/^v//' | sort -V | tail -n1 || true)"9
if [ -z "$last" ]; then10
if [ -z "$last" ]; then10
v="$(sed -n 's/^version = "\(.*\)"/\1/p' build.gradle.kts)"11
v="$(sed -n 's/^version = "\(.*\)"/\1/p' build.gradle.kts)"@@ -134,7 +134,7 @@ public final class CleanupPatch {
134
134
} catch (Throwable ignored) { return false; }
135
135
}
136
136
137
private static boolean isCourierTagged(Set<String> tags) {
137
static boolean isCourierTagged(Set<String> tags) {
138
138
for (String tag : tags) if (tag.equals("birdcourier") || tag.equals("bird_courier")
139
139
|| tag.equals("birdcourier-visual") || tag.equals("birdcourier_visual")
140
140
|| tag.startsWith("birdcourier-shipment:") || tag.startsWith("birdcourier_shipment:")
@@ -142,7 +142,7 @@ public final class CleanupPatch {
142
142
return false;
143
143
}
144
144
145
private static Long shipmentId(Set<String> tags) {
145
static Long shipmentId(Set<String> tags) {
146
146
String[] prefixes = {"birdcourier-shipment:", "birdcourier_shipment:", "birdcourier:"};
147
147
for (String tag : tags) for (String prefix : prefixes) if (tag.startsWith(prefix)) {
148
148
try { return Long.parseLong(tag.substring(prefix.length())); }
@@ -134,7 +134,7 @@ public final class CleanupPatch {134
} catch (Throwable ignored) { return false; }134
} catch (Throwable ignored) { return false; }135
}135
}136
136
137
private static boolean isCourierTagged(Set<String> tags) {137
static boolean isCourierTagged(Set<String> tags) {138
for (String tag : tags) if (tag.equals("birdcourier") || tag.equals("bird_courier")138
for (String tag : tags) if (tag.equals("birdcourier") || tag.equals("bird_courier")139
|| tag.equals("birdcourier-visual") || tag.equals("birdcourier_visual")139
|| tag.equals("birdcourier-visual") || tag.equals("birdcourier_visual")140
|| tag.startsWith("birdcourier-shipment:") || tag.startsWith("birdcourier_shipment:")140
|| tag.startsWith("birdcourier-shipment:") || tag.startsWith("birdcourier_shipment:")@@ -142,7 +142,7 @@ public final class CleanupPatch {142
return false;142
return false;143
}143
}144
144
145
private static Long shipmentId(Set<String> tags) {145
static Long shipmentId(Set<String> tags) {146
String[] prefixes = {"birdcourier-shipment:", "birdcourier_shipment:", "birdcourier:"};146
String[] prefixes = {"birdcourier-shipment:", "birdcourier_shipment:", "birdcourier:"};147
for (String tag : tags) for (String prefix : prefixes) if (tag.startsWith(prefix)) {147
for (String tag : tags) for (String prefix : prefixes) if (tag.startsWith(prefix)) {148
try { return Long.parseLong(tag.substring(prefix.length())); }148
try { return Long.parseLong(tag.substring(prefix.length())); }@@ -9,7 +9,7 @@ import java.util.concurrent.atomic.AtomicLong;
9
9
10
10
/** Runtime compatibility layer for per-player courier selection and visual setup. */
11
11
public final class CourierChoicePatch {
12
private static final List<String> ALLOWED = List.of("allay", "bat", "bee", "blaze", "chicken", "baby_chicken", "ghast", "parrot", "vex");
12
static final List<String> ALLOWED = List.of("allay", "bat", "bee", "blaze", "chicken", "baby_chicken", "ghast", "parrot", "vex");
13
13
private static final Map<UUID, String> CHOICES = new HashMap<>();
14
14
private static Path choicesFile;
15
15
@@ -206,8 +206,8 @@ public final class CourierChoicePatch {
206
206
}
207
207
}
208
208
209
private static String storageType(String choice) { if ("ghast".equals(choice)) return "HAPPY_GHAST"; if ("baby_chicken".equals(choice)) return "CHICKEN"; return choice.toUpperCase(Locale.ROOT); }
210
private static String displayChoice(String choice) { if ("ghast".equals(choice)) return "Ghastling"; if ("baby_chicken".equals(choice)) return "Baby Chicken"; return Character.toUpperCase(choice.charAt(0)) + choice.substring(1); }
209
static String storageType(String choice) { if ("ghast".equals(choice)) return "HAPPY_GHAST"; if ("baby_chicken".equals(choice)) return "CHICKEN"; return choice.toUpperCase(Locale.ROOT); }
210
static String displayChoice(String choice) { if ("ghast".equals(choice)) return "Ghastling"; if ("baby_chicken".equals(choice)) return "Baby Chicken"; return Character.toUpperCase(choice.charAt(0)) + choice.substring(1); }
211
211
212
212
private static void loadChoices() {
213
213
CHOICES.clear();
@@ -9,7 +9,7 @@ import java.util.concurrent.atomic.AtomicLong;9
9
10
/** Runtime compatibility layer for per-player courier selection and visual setup. */10
/** Runtime compatibility layer for per-player courier selection and visual setup. */11
public final class CourierChoicePatch {11
public final class CourierChoicePatch {12
private static final List<String> ALLOWED = List.of("allay", "bat", "bee", "blaze", "chicken", "baby_chicken", "ghast", "parrot", "vex");12
static final List<String> ALLOWED = List.of("allay", "bat", "bee", "blaze", "chicken", "baby_chicken", "ghast", "parrot", "vex");13
private static final Map<UUID, String> CHOICES = new HashMap<>();13
private static final Map<UUID, String> CHOICES = new HashMap<>();14
private static Path choicesFile;14
private static Path choicesFile;15
15
@@ -206,8 +206,8 @@ public final class CourierChoicePatch {206
}206
}207
}207
}208
208
209
private static String storageType(String choice) { if ("ghast".equals(choice)) return "HAPPY_GHAST"; if ("baby_chicken".equals(choice)) return "CHICKEN"; return choice.toUpperCase(Locale.ROOT); }209
static String storageType(String choice) { if ("ghast".equals(choice)) return "HAPPY_GHAST"; if ("baby_chicken".equals(choice)) return "CHICKEN"; return choice.toUpperCase(Locale.ROOT); }210
private static String displayChoice(String choice) { if ("ghast".equals(choice)) return "Ghastling"; if ("baby_chicken".equals(choice)) return "Baby Chicken"; return Character.toUpperCase(choice.charAt(0)) + choice.substring(1); }210
static String displayChoice(String choice) { if ("ghast".equals(choice)) return "Ghastling"; if ("baby_chicken".equals(choice)) return "Baby Chicken"; return Character.toUpperCase(choice.charAt(0)) + choice.substring(1); }211
211
212
private static void loadChoices() {212
private static void loadChoices() {213
CHOICES.clear();213
CHOICES.clear();@@ -0,0 +1,36 @@
1
package nl.timfalken.birdcourier;
2
3
import java.util.Set;
4
5
import org.junit.jupiter.api.Test;
6
7
import static org.junit.jupiter.api.Assertions.assertEquals;
8
import static org.junit.jupiter.api.Assertions.assertFalse;
9
import static org.junit.jupiter.api.Assertions.assertNull;
10
import static org.junit.jupiter.api.Assertions.assertTrue;
11
12
class CleanupTagTest {
13
14
@Test
15
void courierTagsAreRecognisedAndOrdinaryTagsAreNot() {
16
assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier")));
17
assertTrue(CleanupPatch.isCourierTagged(Set.of("bird_courier")));
18
assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier-visual")));
19
assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier_visual")));
20
assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier-shipment:7")));
21
assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier_shipment:7")));
22
assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier:7")));
23
assertFalse(CleanupPatch.isCourierTagged(Set.of()));
24
assertFalse(CleanupPatch.isCourierTagged(Set.of("invulnerable", "parrot")));
25
}
26
27
@Test
28
void shipmentIdIsReadFromKnownPrefixesOnly() {
29
assertEquals(42L, CleanupPatch.shipmentId(Set.of("birdcourier-shipment:42")));
30
assertEquals(9L, CleanupPatch.shipmentId(Set.of("other", "birdcourier_shipment:9")));
31
assertEquals(3L, CleanupPatch.shipmentId(Set.of("birdcourier:3")));
32
assertNull(CleanupPatch.shipmentId(Set.of("birdcourier")));
33
assertNull(CleanupPatch.shipmentId(Set.of("birdcourier-shipment:nope")));
34
assertNull(CleanupPatch.shipmentId(Set.of()));
35
}
36
}
@@ -0,0 +1,36 @@1
package nl.timfalken.birdcourier;2
3
import java.util.Set;4
5
import org.junit.jupiter.api.Test;6
7
import static org.junit.jupiter.api.Assertions.assertEquals;8
import static org.junit.jupiter.api.Assertions.assertFalse;9
import static org.junit.jupiter.api.Assertions.assertNull;10
import static org.junit.jupiter.api.Assertions.assertTrue;11
12
class CleanupTagTest {13
14
@Test15
void courierTagsAreRecognisedAndOrdinaryTagsAreNot() {16
assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier")));17
assertTrue(CleanupPatch.isCourierTagged(Set.of("bird_courier")));18
assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier-visual")));19
assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier_visual")));20
assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier-shipment:7")));21
assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier_shipment:7")));22
assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier:7")));23
assertFalse(CleanupPatch.isCourierTagged(Set.of()));24
assertFalse(CleanupPatch.isCourierTagged(Set.of("invulnerable", "parrot")));25
}26
27
@Test28
void shipmentIdIsReadFromKnownPrefixesOnly() {29
assertEquals(42L, CleanupPatch.shipmentId(Set.of("birdcourier-shipment:42")));30
assertEquals(9L, CleanupPatch.shipmentId(Set.of("other", "birdcourier_shipment:9")));31
assertEquals(3L, CleanupPatch.shipmentId(Set.of("birdcourier:3")));32
assertNull(CleanupPatch.shipmentId(Set.of("birdcourier")));33
assertNull(CleanupPatch.shipmentId(Set.of("birdcourier-shipment:nope")));34
assertNull(CleanupPatch.shipmentId(Set.of()));35
}36
}@@ -0,0 +1,52 @@
1
package nl.timfalken.birdcourier;
2
3
import java.util.List;
4
5
import org.junit.jupiter.api.Test;
6
import org.junit.jupiter.params.ParameterizedTest;
7
import org.junit.jupiter.params.provider.CsvSource;
8
9
import static org.junit.jupiter.api.Assertions.assertEquals;
10
import static org.junit.jupiter.api.Assertions.assertFalse;
11
import static org.junit.jupiter.api.Assertions.assertTrue;
12
13
class CourierChoiceTest {
14
15
@Test
16
void allowedTypesMatchThePublicCourierCommand() {
17
assertEquals(
18
List.of("allay", "bat", "bee", "blaze", "chicken", "baby_chicken", "ghast", "parrot", "vex"),
19
CourierChoicePatch.ALLOWED);
20
assertFalse(CourierChoicePatch.ALLOWED.contains("phantom"));
21
}
22
23
@ParameterizedTest
24
@CsvSource({
25
"parrot,PARROT",
26
"allay,ALLAY",
27
"ghast,HAPPY_GHAST",
28
"baby_chicken,CHICKEN",
29
"bat,BAT"
30
})
31
void storageTypeMapsChoiceToEntityType(String choice, String stored) {
32
assertEquals(stored, CourierChoicePatch.storageType(choice));
33
}
34
35
@ParameterizedTest
36
@CsvSource({
37
"parrot,Parrot",
38
"allay,Allay",
39
"ghast,Ghastling",
40
"baby_chicken,Baby Chicken",
41
"vex,Vex"
42
})
43
void displayChoiceUsesFriendlyNames(String choice, String shown) {
44
assertEquals(shown, CourierChoicePatch.displayChoice(choice));
45
}
46
47
@Test
48
void defaultVisualFallbackStaysInTheAllowedList() {
49
String configured = "PARROT".toLowerCase();
50
assertTrue(CourierChoicePatch.ALLOWED.contains(configured));
51
}
52
}
@@ -0,0 +1,52 @@1
package nl.timfalken.birdcourier;2
3
import java.util.List;4
5
import org.junit.jupiter.api.Test;6
import org.junit.jupiter.params.ParameterizedTest;7
import org.junit.jupiter.params.provider.CsvSource;8
9
import static org.junit.jupiter.api.Assertions.assertEquals;10
import static org.junit.jupiter.api.Assertions.assertFalse;11
import static org.junit.jupiter.api.Assertions.assertTrue;12
13
class CourierChoiceTest {14
15
@Test16
void allowedTypesMatchThePublicCourierCommand() {17
assertEquals(18
List.of("allay", "bat", "bee", "blaze", "chicken", "baby_chicken", "ghast", "parrot", "vex"),19
CourierChoicePatch.ALLOWED);20
assertFalse(CourierChoicePatch.ALLOWED.contains("phantom"));21
}22
23
@ParameterizedTest24
@CsvSource({25
"parrot,PARROT",26
"allay,ALLAY",27
"ghast,HAPPY_GHAST",28
"baby_chicken,CHICKEN",29
"bat,BAT"30
})31
void storageTypeMapsChoiceToEntityType(String choice, String stored) {32
assertEquals(stored, CourierChoicePatch.storageType(choice));33
}34
35
@ParameterizedTest36
@CsvSource({37
"parrot,Parrot",38
"allay,Allay",39
"ghast,Ghastling",40
"baby_chicken,Baby Chicken",41
"vex,Vex"42
})43
void displayChoiceUsesFriendlyNames(String choice, String shown) {44
assertEquals(shown, CourierChoicePatch.displayChoice(choice));45
}46
47
@Test48
void defaultVisualFallbackStaysInTheAllowedList() {49
String configured = "PARROT".toLowerCase();50
assertTrue(CourierChoicePatch.ALLOWED.contains(configured));51
}52
}@@ -0,0 +1,93 @@
1
package nl.timfalken.birdcourier;
2
3
import java.io.IOException;
4
import java.io.InputStream;
5
import java.nio.charset.StandardCharsets;
6
import java.nio.file.Files;
7
import java.nio.file.Path;
8
import java.util.Map;
9
import java.util.Set;
10
11
import org.junit.jupiter.api.Test;
12
import org.yaml.snakeyaml.Yaml;
13
14
import static org.junit.jupiter.api.Assertions.assertEquals;
15
import static org.junit.jupiter.api.Assertions.assertFalse;
16
import static org.junit.jupiter.api.Assertions.assertNotNull;
17
import static org.junit.jupiter.api.Assertions.assertTrue;
18
19
class PluginConfigTest {
20
21
@Test
22
@SuppressWarnings("unchecked")
23
void pluginYmlDeclaresCommandsAndPermissions() throws IOException {
24
Map<String, Object> yaml = loadYaml("plugin.yml");
25
assertEquals("BirdCourier", yaml.get("name"));
26
assertEquals("nl.timfalken.birdcourier.BirdCourierPlugin", yaml.get("main"));
27
assertEquals("26.2", String.valueOf(yaml.get("api-version")).replace("'", ""));
28
assertEquals(gradleVersion(), String.valueOf(yaml.get("version")));
29
30
Map<String, Object> commands = (Map<String, Object>) yaml.get("commands");
31
assertNotNull(commands);
32
assertEquals(Set.of("send", "courier", "birdcourier"), commands.keySet());
33
assertEquals("birdcourier.send", ((Map<String, Object>) commands.get("send")).get("permission"));
34
assertEquals("birdcourier.courier", ((Map<String, Object>) commands.get("courier")).get("permission"));
35
assertEquals("birdcourier.admin", ((Map<String, Object>) commands.get("birdcourier")).get("permission"));
36
37
Map<String, Object> permissions = (Map<String, Object>) yaml.get("permissions");
38
assertNotNull(permissions);
39
assertEquals(true, ((Map<String, Object>) permissions.get("birdcourier.send")).get("default"));
40
assertEquals(true, ((Map<String, Object>) permissions.get("birdcourier.courier")).get("default"));
41
assertEquals("op", ((Map<String, Object>) permissions.get("birdcourier.admin")).get("default"));
42
}
43
44
@Test
45
@SuppressWarnings("unchecked")
46
void configYmlHasFlightVisualAndCleanupDefaults() throws IOException {
47
Map<String, Object> yaml = loadYaml("config.yml");
48
49
Map<String, Object> visual = (Map<String, Object>) yaml.get("visual");
50
assertEquals("PARROT", visual.get("entity-type"));
51
52
Map<String, Object> flight = (Map<String, Object>) yaml.get("flight");
53
assertEquals(10.0, ((Number) flight.get("speed-blocks-per-second")).doubleValue(), 0.001);
54
assertEquals(5.0, ((Number) flight.get("unloaded-speed-multiplier")).doubleValue(), 0.001);
55
assertEquals(10, ((Number) flight.get("preferred-height-above-ground")).intValue());
56
57
Map<String, Object> messages = (Map<String, Object>) yaml.get("messages");
58
assertTrue(messages.containsKey("sent"));
59
assertTrue(messages.containsKey("delivered"));
60
assertTrue(messages.containsKey("target-offline"));
61
62
Map<String, Object> cleanup = (Map<String, Object>) yaml.get("cleanup");
63
assertEquals(true, cleanup.get("remove-all-ai-disabled-configured-type"));
64
assertEquals(false, cleanup.get("remove-configured-type-with-any-courier-flag"));
65
assertEquals(false, cleanup.get("remove-untagged-courier-like-entities"));
66
}
67
68
private static Map<String, Object> loadYaml(String name) throws IOException {
69
try (InputStream in = PluginConfigTest.class.getClassLoader().getResourceAsStream(name)) {
70
assertNotNull(in, name + " missing on the test classpath");
71
Object loaded = new Yaml().load(in);
72
assertTrue(loaded instanceof Map, name + " should be a mapping");
73
@SuppressWarnings("unchecked")
74
Map<String, Object> map = (Map<String, Object>) loaded;
75
assertFalse(map.isEmpty());
76
return map;
77
}
78
}
79
80
private static String gradleVersion() throws IOException {
81
Path gradle = Path.of("build.gradle.kts");
82
if (!Files.isRegularFile(gradle)) {
83
gradle = Path.of("..", "build.gradle.kts");
84
}
85
for (String line : Files.readAllLines(gradle, StandardCharsets.UTF_8)) {
86
line = line.trim();
87
if (line.startsWith("version = \"")) {
88
return line.substring("version = \"".length(), line.length() - 1);
89
}
90
}
91
throw new IOException("version not found in build.gradle.kts");
92
}
93
}
@@ -0,0 +1,93 @@1
package nl.timfalken.birdcourier;2
3
import java.io.IOException;4
import java.io.InputStream;5
import java.nio.charset.StandardCharsets;6
import java.nio.file.Files;7
import java.nio.file.Path;8
import java.util.Map;9
import java.util.Set;10
11
import org.junit.jupiter.api.Test;12
import org.yaml.snakeyaml.Yaml;13
14
import static org.junit.jupiter.api.Assertions.assertEquals;15
import static org.junit.jupiter.api.Assertions.assertFalse;16
import static org.junit.jupiter.api.Assertions.assertNotNull;17
import static org.junit.jupiter.api.Assertions.assertTrue;18
19
class PluginConfigTest {20
21
@Test22
@SuppressWarnings("unchecked")23
void pluginYmlDeclaresCommandsAndPermissions() throws IOException {24
Map<String, Object> yaml = loadYaml("plugin.yml");25
assertEquals("BirdCourier", yaml.get("name"));26
assertEquals("nl.timfalken.birdcourier.BirdCourierPlugin", yaml.get("main"));27
assertEquals("26.2", String.valueOf(yaml.get("api-version")).replace("'", ""));28
assertEquals(gradleVersion(), String.valueOf(yaml.get("version")));29
30
Map<String, Object> commands = (Map<String, Object>) yaml.get("commands");31
assertNotNull(commands);32
assertEquals(Set.of("send", "courier", "birdcourier"), commands.keySet());33
assertEquals("birdcourier.send", ((Map<String, Object>) commands.get("send")).get("permission"));34
assertEquals("birdcourier.courier", ((Map<String, Object>) commands.get("courier")).get("permission"));35
assertEquals("birdcourier.admin", ((Map<String, Object>) commands.get("birdcourier")).get("permission"));36
37
Map<String, Object> permissions = (Map<String, Object>) yaml.get("permissions");38
assertNotNull(permissions);39
assertEquals(true, ((Map<String, Object>) permissions.get("birdcourier.send")).get("default"));40
assertEquals(true, ((Map<String, Object>) permissions.get("birdcourier.courier")).get("default"));41
assertEquals("op", ((Map<String, Object>) permissions.get("birdcourier.admin")).get("default"));42
}43
44
@Test45
@SuppressWarnings("unchecked")46
void configYmlHasFlightVisualAndCleanupDefaults() throws IOException {47
Map<String, Object> yaml = loadYaml("config.yml");48
49
Map<String, Object> visual = (Map<String, Object>) yaml.get("visual");50
assertEquals("PARROT", visual.get("entity-type"));51
52
Map<String, Object> flight = (Map<String, Object>) yaml.get("flight");53
assertEquals(10.0, ((Number) flight.get("speed-blocks-per-second")).doubleValue(), 0.001);54
assertEquals(5.0, ((Number) flight.get("unloaded-speed-multiplier")).doubleValue(), 0.001);55
assertEquals(10, ((Number) flight.get("preferred-height-above-ground")).intValue());56
57
Map<String, Object> messages = (Map<String, Object>) yaml.get("messages");58
assertTrue(messages.containsKey("sent"));59
assertTrue(messages.containsKey("delivered"));60
assertTrue(messages.containsKey("target-offline"));61
62
Map<String, Object> cleanup = (Map<String, Object>) yaml.get("cleanup");63
assertEquals(true, cleanup.get("remove-all-ai-disabled-configured-type"));64
assertEquals(false, cleanup.get("remove-configured-type-with-any-courier-flag"));65
assertEquals(false, cleanup.get("remove-untagged-courier-like-entities"));66
}67
68
private static Map<String, Object> loadYaml(String name) throws IOException {69
try (InputStream in = PluginConfigTest.class.getClassLoader().getResourceAsStream(name)) {70
assertNotNull(in, name + " missing on the test classpath");71
Object loaded = new Yaml().load(in);72
assertTrue(loaded instanceof Map, name + " should be a mapping");73
@SuppressWarnings("unchecked")74
Map<String, Object> map = (Map<String, Object>) loaded;75
assertFalse(map.isEmpty());76
return map;77
}78
}79
80
private static String gradleVersion() throws IOException {81
Path gradle = Path.of("build.gradle.kts");82
if (!Files.isRegularFile(gradle)) {83
gradle = Path.of("..", "build.gradle.kts");84
}85
for (String line : Files.readAllLines(gradle, StandardCharsets.UTF_8)) {86
line = line.trim();87
if (line.startsWith("version = \"")) {88
return line.substring("version = \"".length(), line.length() - 1);89
}90
}91
throw new IOException("version not found in build.gradle.kts");92
}93
}