Skip to content

Commit 8353811

Browse files
authored
[CI] Better versioning (#1433)
1 parent 648f522 commit 8353811

8 files changed

Lines changed: 140 additions & 33 deletions

File tree

.github/scripts/version_script.bat

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,65 @@
11
@echo off
2-
set TENSORDICT_BUILD_VERSION=0.10.0
3-
set SETUPTOOLS_SCM_PRETEND_VERSION=0.10.0
2+
3+
set BASE_VERSION=0.10.0
4+
echo Base version: %BASE_VERSION%
5+
6+
REM Only set static version for release branches and release candidate tags
7+
if "%GITHUB_REF_TYPE%"=="branch" (
8+
echo %GITHUB_REF_NAME% | findstr /R "^release/" >nul
9+
if not errorlevel 1 (
10+
echo Setting static version for release branch: %GITHUB_REF_NAME%
11+
set TENSORDICT_BUILD_VERSION=%BASE_VERSION%
12+
set SETUPTOOLS_SCM_PRETEND_VERSION=%TENSORDICT_BUILD_VERSION%
13+
goto setup_build
14+
)
15+
)
16+
17+
if "%GITHUB_REF_TYPE%"=="tag" (
18+
echo %GITHUB_REF_NAME% | findstr /R "^v[0-9]*\.[0-9]*\.[0-9]*-rc[0-9]*$" >nul
19+
if not errorlevel 1 (
20+
echo Setting static version for release candidate tag: %GITHUB_REF_NAME%
21+
set TENSORDICT_BUILD_VERSION=%BASE_VERSION%
22+
set SETUPTOOLS_SCM_PRETEND_VERSION=%TENSORDICT_BUILD_VERSION%
23+
goto setup_build
24+
)
25+
)
26+
27+
echo Setting development version for build: %GITHUB_REF_NAME%
28+
29+
REM Debug: Print available environment variables
30+
echo Debug environment variables:
31+
echo GITHUB_SHA: %GITHUB_SHA%
32+
echo GITHUB_REF_TYPE: %GITHUB_REF_TYPE%
33+
echo GITHUB_REF_NAME: %GITHUB_REF_NAME%
34+
echo GITHUB_RUN_NUMBER: %GITHUB_RUN_NUMBER%
35+
echo GITHUB_RUN_ATTEMPT: %GITHUB_RUN_ATTEMPT%
36+
37+
REM Use environment variables instead of git commands
38+
REM Get first 9 characters of commit hash
39+
set GIT_COMMIT=%GITHUB_SHA:~0,9%
40+
if "%GIT_COMMIT%"=="" set GIT_COMMIT=unknown
41+
42+
REM Use GitHub run number as substitute for commit count
43+
set GIT_COMMIT_COUNT=%GITHUB_RUN_NUMBER%
44+
if "%GIT_COMMIT_COUNT%"=="" set GIT_COMMIT_COUNT=0
45+
46+
REM Get current date in YYYYMMDD format
47+
for /f "tokens=2 delims==" %%i in ('wmic os get localdatetime /value') do (
48+
set datetime=%%i
49+
goto :break
50+
)
51+
:break
52+
set DATE_STR=%datetime:~0,8%
53+
echo Debug: Raw datetime: %datetime%
54+
echo Debug: Parsed date: %DATE_STR%
55+
56+
REM Format: <base_version>.dev<commits>+g<hash>.d<date>
57+
set DEV_VERSION=%BASE_VERSION%.dev%GIT_COMMIT_COUNT%+g%GIT_COMMIT%.d%DATE_STR%
58+
echo Using development version: %DEV_VERSION%
59+
set SETUPTOOLS_SCM_PRETEND_VERSION=%DEV_VERSION%
60+
set TENSORDICT_BUILD_VERSION=%DEV_VERSION%
61+
62+
:setup_build
463
echo TENSORDICT_BUILD_VERSION is set to %TENSORDICT_BUILD_VERSION%
564

665
if "%CONDA_RUN%"=="" (

.github/scripts/version_script.sh

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,63 @@
11
#!/bin/bash
22

3-
export TENSORDICT_BUILD_VERSION=0.10.0
4-
export SETUPTOOLS_SCM_PRETEND_VERSION=$TENSORDICT_BUILD_VERSION
3+
# Read base version from version.txt (explicit absolute path)
4+
# This script is located at: .github/scripts/version_script.sh
5+
# The version.txt file is at: .github/scripts/version.txt
6+
BASE_VERSION=0.10.0
7+
echo "Base version: $BASE_VERSION"
8+
9+
# Only set static version for release branches and release candidate tags
10+
if [[ "$GITHUB_REF_TYPE" == "branch" && "$GITHUB_REF_NAME" == release/* ]] || [[ "$GITHUB_REF_TYPE" == "tag" && "$GITHUB_REF_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]+$ ]]; then
11+
echo "Setting static version for release: $GITHUB_REF_NAME"
12+
export TENSORDICT_BUILD_VERSION=$BASE_VERSION
13+
export SETUPTOOLS_SCM_PRETEND_VERSION=$TENSORDICT_BUILD_VERSION
14+
else
15+
echo "Setting development version for build: $GITHUB_REF_NAME"
16+
17+
# Debug: Print available environment variables
18+
echo "Debug environment variables:"
19+
echo " GITHUB_SHA: ${GITHUB_SHA:-not set}"
20+
echo " GITHUB_REF_TYPE: ${GITHUB_REF_TYPE:-not set}"
21+
echo " GITHUB_REF_NAME: ${GITHUB_REF_NAME:-not set}"
22+
echo " GITHUB_RUN_NUMBER: ${GITHUB_RUN_NUMBER:-not set}"
23+
echo " GITHUB_RUN_ATTEMPT: ${GITHUB_RUN_ATTEMPT:-not set}"
24+
25+
# Use environment variables instead of git commands
26+
GIT_COMMIT="${GITHUB_SHA:0:9}" # First 9 chars of commit hash
27+
if [[ -z "$GIT_COMMIT" ]]; then
28+
GIT_COMMIT="unknown"
29+
fi
30+
31+
# Use GitHub run number as substitute for commit count
32+
GIT_COMMIT_COUNT="${GITHUB_RUN_NUMBER:-0}"
33+
34+
DATE_STR=$(date +%Y%m%d)
35+
36+
# Format: <base_version>.dev<commits>+g<hash>.d<date>
37+
DEV_VERSION="${BASE_VERSION}.dev${GIT_COMMIT_COUNT}+g${GIT_COMMIT}.d${DATE_STR}"
38+
echo "Using development version: $DEV_VERSION"
39+
export SETUPTOOLS_SCM_PRETEND_VERSION=$DEV_VERSION
40+
fi
41+
542
# TODO: consider lower this
643
export MACOSX_DEPLOYMENT_TARGET=14.0
744

8-
${CONDA_RUN} pip install --upgrade pip
45+
# Set CONDA_RUN if not set
46+
if [[ -z "${CONDA_RUN:-}" ]]; then
47+
48+
pip install --upgrade pip
49+
50+
# for orjson
51+
export UNSAFE_PYO3_BUILD_FREE_THREADED=1
52+
53+
pip install "pybind11[global]"
54+
55+
else
56+
57+
${CONDA_RUN} pip install --upgrade pip
958

10-
# for orjson
11-
export UNSAFE_PYO3_BUILD_FREE_THREADED=1
59+
# for orjson
60+
export UNSAFE_PYO3_BUILD_FREE_THREADED=1
1261

13-
${CONDA_RUN} conda install -c conda-forge pybind11 -y
62+
${CONDA_RUN} conda install -c conda-forge pybind11 -y
63+
fi

.github/workflows/docs.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@ jobs:
5757
# Install PyTorch (CPU version for docs)
5858
python -m pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu -U --quiet --root-user-action=ignore
5959
60+
# Set up versioning environment (conditional on release branch/tag)
61+
export GITHUB_REF_TYPE=${{ github.ref_type }}
62+
export GITHUB_REF_NAME=${{ github.ref_name }}
63+
source .github/scripts/version_script.sh
64+
6065
# Install tensordict -- install as develop if not on a release branch
61-
if [[ ${{ github.ref_type }} == branch && ${{ github.ref_name }} == release/* ]]; then
66+
if [[ ${{ github.ref_type }} == branch && ${{ github.ref_name }} == release/* ]] || [[ ${{ github.ref_type }} == tag ]]; then
6267
python -m pip install .
6368
else
6469
python -m pip install -e .

.github/workflows/nightly_build.yml

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,11 @@ jobs:
6969
sudo apt-get update
7070
sudo apt-get install -y cmake
7171
fi
72-
python3 -mpip install "pybind11[global]" poetry
72+
python3 -mpip install "pybind11[global]" uv
7373
sed -i.bak 's/name = "tensordict"/name = "tensordict-nightly"/' pyproject.toml
7474
DATE_VERSION=$(date +%Y.%m.%d)
75-
sed -i.bak '/^version = /s/version = .*/version = "'"$DATE_VERSION"'"/' pyproject.toml
76-
# poetry build
77-
python -m build --wheel
75+
export SETUPTOOLS_SCM_PRETEND_VERSION=$DATE_VERSION
76+
uv build --wheel
7877
rm pyproject.toml.bak
7978
find dist -name '*whl' -exec bash -c ' mv $0 ${0/linux/manylinux1}' {} \;
8079
# pytorch/pytorch binaries are also manylinux_2_17 compliant but they
@@ -220,25 +219,24 @@ jobs:
220219
shell: bash
221220
run: |
222221
python3 -mpip install --pre torch --extra-index-url https://download.pytorch.org/whl/nightly/cpu
222+
- name: Setup CMake
223+
uses: jwlawson/actions-setup-cmake@v2
224+
with:
225+
cmake-version: 'latest'
223226
- name: Build tensordict Nightly
224227
shell: bash
225228
run: |
226229
# Remove the dist directory if it exists
227230
rm -r dist || true
228-
if ! choco -v &> /dev/null; then
229-
powershell -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"
230-
fi
231-
# Install cmake using Chocolatey
232-
choco install cmake -y
233231
# Install necessary Python packages
234232
python -m pip install --upgrade pip
235-
python -m pip install "pybind11[global]" poetry
233+
python -m pip install "pybind11[global]" build
236234
# Modify pyproject.toml to change the package name
237235
sed -i.bak 's/name = "tensordict"/name = "tensordict-nightly"/' pyproject.toml
238236
DATE_VERSION=$(date +%Y.%m.%d)
239-
sed -i.bak '/^version = /s/version = .*/version = "'"$DATE_VERSION"'"/' pyproject.toml
240-
# Build the package with Poetry
241-
poetry build
237+
export SETUPTOOLS_SCM_PRETEND_VERSION=$DATE_VERSION
238+
# Build the package with python -m build (more reliable than uv on Windows)
239+
python -m build --wheel
242240
# Clean up the backup file created by sed
243241
rm pyproject.toml.bak
244242
# Rename the wheel files to match the manylinux1 convention

packaging/pkg_helpers.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ setup_base_build_version() {
169169
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
170170
# version.txt for some reason has `a` character after major.minor.rev
171171
# command below yields 0.10.0 from version.txt containing 0.10.0a0
172-
BUILD_VERSION=$( cut -f 1 -d a "$SCRIPT_DIR/../version.txt" )
172+
BUILD_VERSION=$( cut -f 1 -d a "$SCRIPT_DIR/../.github/scripts/version.txt" )
173173
export BUILD_VERSION
174174
}
175175

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ target-version = ["py39"]
1616

1717
[project]
1818
name = "tensordict"
19-
version = "0.10.0"
19+
dynamic = ["version"]
2020
description = "TensorDict is a pytorch dedicated tensor container."
2121
authors = [
2222
{ name="Vincent Moens", email="vincentmoens@gmail.com" }
@@ -72,8 +72,10 @@ exclude = ["test*", "tutorials*", "packaging*", "gallery*", "docs*", "benchmarks
7272
"tensordict" = ["*.so", "*.pyd", "*.dll"]
7373

7474
[tool.setuptools_scm]
75+
# Use SETUPTOOLS_SCM_PRETEND_VERSION=M.Major.Minor to set the version for stable releases
7576
version_scheme = "post-release"
76-
write_to = "tensordict/_version.py"
77+
local_scheme = "node-and-date"
78+
version_file = "tensordict/_version.py"
7779

7880
[tool.mypy]
7981
files = "tensordict"

setup.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,6 @@ def get_extensions():
9191
return [CMakeExtension("tensordict._C", sourcedir=extensions_dir)]
9292

9393

94-
def version():
95-
return {
96-
"write_to": "tensordict/_version.py", # Specify the path where the version file should be written
97-
}
98-
99-
10094
setup(
10195
ext_modules=get_extensions(),
10296
cmdclass={
@@ -107,5 +101,5 @@ def version():
107101
exclude=("test", "tutorials", "packaging", "gallery", "docs")
108102
),
109103
setup_requires=["setuptools_scm"],
110-
use_scm_version=version(),
104+
use_scm_version=True,
111105
)

version.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)