Skip to content

Commit 7b781df

Browse files
wu-vincentclaude
andcommitted
Make plugin version single source of truth in CMakeLists.txt
Define VERSION in project() and pass it to C++ via configure_file with version.h.in. The release workflow now updates CMakeLists.txt and commits the version bump alongside the changelog update. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c08cc4c commit 7b781df

File tree

6 files changed

+31
-9
lines changed

6 files changed

+31
-9
lines changed

.github/workflows/release.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,19 @@ jobs:
5959
echo "Tag: v$VERSION"
6060
echo "Date: $DATE"
6161
echo ""
62+
echo "=== CMakeLists.txt version (current) ==="
63+
grep 'project(' CMakeLists.txt
64+
echo "=== CMakeLists.txt version (after update) ==="
65+
echo "project(cpp_example VERSION $VERSION LANGUAGES CXX)"
66+
echo ""
6267
echo "=== Release Body ==="
6368
cat /tmp/release_body.md
6469
70+
- name: Update version in CMakeLists.txt
71+
if: ${{ !inputs.dry_run }}
72+
run: |
73+
sed -i "s/\(project(cpp_example VERSION \)[0-9]\+\.[0-9]\+\.[0-9]\+/\1$VERSION/" CMakeLists.txt
74+
6575
- name: Update CHANGELOG.md
6676
if: ${{ !inputs.dry_run }}
6777
run: |
@@ -73,7 +83,7 @@ jobs:
7383
run: |
7484
git config user.name "github-actions[bot]"
7585
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
76-
git add CHANGELOG.md
86+
git add CMakeLists.txt CHANGELOG.md
7787
git commit -m "Release $VERSION"
7888
git tag "v$VERSION"
7989

AGENTS.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Use CMake with FetchContent to pull in the Endstone SDK:
1515

1616
```cmake
1717
cmake_minimum_required(VERSION 3.15)
18-
project(my_plugin CXX)
18+
project(my_plugin VERSION 0.1.0 LANGUAGES CXX)
1919
2020
set(CMAKE_CXX_STANDARD 20)
2121
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -28,8 +28,11 @@ FetchContent_Declare(
2828
)
2929
FetchContent_MakeAvailable(endstone)
3030
31+
string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER)
32+
configure_file(include/version.h.in include/version.h)
33+
3134
endstone_add_plugin(${PROJECT_NAME} src/plugin.cpp)
32-
target_include_directories(${PROJECT_NAME} PRIVATE include)
35+
target_include_directories(${PROJECT_NAME} PRIVATE include ${CMAKE_CURRENT_BINARY_DIR}/include)
3336
```
3437

3538
## Plugin Class
@@ -68,7 +71,8 @@ Declared in a .cpp file:
6871
```cpp
6972
#include "plugin.h"
7073

71-
ENDSTONE_PLUGIN("my_plugin", "0.1.0", MyPlugin)
74+
// MY_PLUGIN_VERSION is defined in version.h, generated by CMake from project(... VERSION ...)
75+
ENDSTONE_PLUGIN("my_plugin", MY_PLUGIN_VERSION, MyPlugin)
7276
{
7377
prefix = "MyPlugin";
7478
description = "My Endstone plugin";

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.15)
22

3-
project(cpp_example CXX)
3+
project(cpp_example VERSION 0.5.0 LANGUAGES CXX)
44

55
set(CMAKE_CXX_STANDARD 20)
66
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -16,5 +16,8 @@ FetchContent_Declare(
1616
)
1717
FetchContent_MakeAvailable(endstone)
1818

19+
string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER)
20+
configure_file(include/version.h.in include/version.h)
21+
1922
endstone_add_plugin(${PROJECT_NAME} src/plugin.cpp)
20-
target_include_directories(${PROJECT_NAME} PRIVATE include)
23+
target_include_directories(${PROJECT_NAME} PRIVATE include ${CMAKE_CURRENT_BINARY_DIR}/include)

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ and permissions.
1414

1515
| What | Where | Example |
1616
|------|-------|---------|
17-
| Project name | `CMakeLists.txt` `project(...)` | `project(my_plugin CXX)` |
18-
| Plugin metadata | `src/plugin.cpp` `ENDSTONE_PLUGIN(...)` | `"my_plugin", "0.1.0", MyPlugin` |
17+
| Project name | `CMakeLists.txt` `project(...)` | `project(my_plugin VERSION 0.1.0 LANGUAGES CXX)` |
18+
| Plugin version | `CMakeLists.txt` `project(... VERSION ...)` | `0.1.0` |
19+
| Plugin metadata | `src/plugin.cpp` `ENDSTONE_PLUGIN(...)` | `"my_plugin", MY_PLUGIN_VERSION, MyPlugin` |
1920
| Plugin class | `include/plugin.h` class name | `MyPlugin` |
2021
| Prefix | `src/plugin.cpp` `prefix = ...` | `"MyPlugin"` |
2122
| Permission prefix | `src/plugin.cpp` permission names | `my_plugin.command.*` |

include/version.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
#define @PROJECT_NAME_UPPER@_VERSION "@PROJECT_VERSION@"

src/plugin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#include "plugin.h"
2+
#include "version.h"
23

34
// The ENDSTONE_PLUGIN macro defines the metadata for the plugin.
45
// This is where you set the plugin name, version, and main class,
56
// and declare commands and permissions.
6-
ENDSTONE_PLUGIN(/*name=*/"cpp_example", /*version=*/"0.1.0", /*main_class=*/ExamplePlugin)
7+
ENDSTONE_PLUGIN(/*name=*/"cpp_example", /*version=*/CPP_EXAMPLE_VERSION, /*main_class=*/ExamplePlugin)
78
{
89
prefix = "ExamplePlugin";
910
description = "C++ example plugin for Endstone servers";

0 commit comments

Comments
 (0)