diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 8a007f280..6518ed65e 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -1,18 +1,17 @@ name: Build Wheels on: - push: - branches: [main] - pull_request: - branches: [main] workflow_dispatch: inputs: + version: + type: string + required: true + default: YYYY.MM.DDdevN + description: 'The package version' release: type: boolean required: true default: false description: 'Push a release to PyPI' - release: - types: [published] jobs: build_sdist: @@ -29,7 +28,7 @@ jobs: - name: Configure CMake working-directory: '${{github.workspace}}' - run: cmake -G "Unix Makefiles" -B build -DCMAKE_BUILD_TYPE=Release -DSOURCEPP_BUILD_PYTHON_WRAPPERS=ON + run: cmake -G "Unix Makefiles" -B build -DCMAKE_BUILD_TYPE=Release -DSOURCEPP_BUILD_PYTHON_WRAPPERS=ON -DSOURCEPP_PYTHON_VERSION="${{inputs.version}}" - name: Build SDist run: | @@ -47,7 +46,7 @@ jobs: upload_release: name: Upload a Release - if: (github.event_name == 'release' && github.event.action == 'published') || (github.event_name == 'workflow_dispatch' && inputs.release) + if: inputs.release needs: [build_sdist] runs-on: ubuntu-latest environment: diff --git a/.gitignore b/.gitignore index c20ed12da..db20dedde 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,7 @@ wheelhouse/ *.typed *.whl +lang/python/CMakeLists.txt lang/python/pyproject.toml lang/python/src/sourcepp/__init__.py diff --git a/CMakeLists.txt b/CMakeLists.txt index b2323a293..fd24a32cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,7 +102,10 @@ endif() # Python bindings, part 1 if(SOURCEPP_BUILD_PYTHON_WRAPPERS) set(SOURCEPP_PYTHON_NAME "${PROJECT_NAME}_python") - set(SOURCEPP_PYTHON_VERSION "2024.11.5dev2") + if(NOT SOURCEPP_PYTHON_VERSION) + set(SOURCEPP_PYTHON_VERSION "0.0.1dev1") + message(WARNING "SOURCEPP_PYTHON_VERSION is not defined, do not release this build publicly! Defaulting it to ${SOURCEPP_PYTHON_VERSION}...") + endif() find_package(Python REQUIRED COMPONENTS Interpreter Development.Module OPTIONAL_COMPONENTS Development.SABIModule) @@ -114,7 +117,17 @@ if(SOURCEPP_BUILD_PYTHON_WRAPPERS) set(${SOURCEPP_PYTHON_NAME}_SOURCES "") set(${SOURCEPP_PYTHON_NAME}_DEFINES "") - # Set the version here + # Set the version and git commit hash here + find_package(Git REQUIRED) + execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --format=%H + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + OUTPUT_VARIABLE SOURCEPP_GIT_TAG + RESULT_VARIABLE SOURCEPP_GIT_TAG_ERROR + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT SOURCEPP_GIT_TAG) + message(FATAL_ERROR "Failed to retrieve git commit SHA: ${SOURCEPP_GIT_TAG_ERROR}") + endif() + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/lang/python/cfg/CMakeLists.txt" "${CMAKE_CURRENT_SOURCE_DIR}/lang/python/CMakeLists.txt" @ONLY) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/lang/python/cfg/pyproject.toml" "${CMAKE_CURRENT_SOURCE_DIR}/lang/python/pyproject.toml") configure_file("${CMAKE_CURRENT_SOURCE_DIR}/lang/python/cfg/__init__.py" "${CMAKE_CURRENT_SOURCE_DIR}/lang/python/src/sourcepp/__init__.py") diff --git a/lang/python/CMakeLists.txt b/lang/python/cfg/CMakeLists.txt similarity index 94% rename from lang/python/CMakeLists.txt rename to lang/python/cfg/CMakeLists.txt index 069cb3677..533080bc9 100644 --- a/lang/python/CMakeLists.txt +++ b/lang/python/cfg/CMakeLists.txt @@ -34,6 +34,7 @@ include(FetchContent) FetchContent_Declare( sourcepp GIT_REPOSITORY "https://github.com/craftablescience/sourcepp.git" - GIT_TAG "origin/main") + GIT_TAG "@SOURCEPP_GIT_TAG@") set(SOURCEPP_BUILD_PYTHON_WRAPPERS ON CACHE INTERNAL "" FORCE) +set(SOURCEPP_PYTHON_VERSION "@SOURCEPP_PYTHON_VERSION@") FetchContent_MakeAvailable(sourcepp)