Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions tests/test_rapids-generate-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import os
import subprocess
from pathlib import Path

import pytest

TOOLS_DIRECTORY = Path(__file__).resolve().parents[1] / "tools"


def _generate_version(
tmp_path: Path,
candidate_version: str | None,
source_version: str | None = None,
) -> subprocess.CompletedProcess[str]:
environment = os.environ.copy()
environment.pop("RAPIDS_RELEASE_CANDIDATE_SOURCE_VERSION", None)
if candidate_version is None:
environment.pop("RAPIDS_RELEASE_CANDIDATE_VERSION", None)
else:
environment["RAPIDS_RELEASE_CANDIDATE_VERSION"] = candidate_version
if source_version is not None:
environment["RAPIDS_RELEASE_CANDIDATE_SOURCE_VERSION"] = source_version
return subprocess.run(
[TOOLS_DIRECTORY / "rapids-generate-version"],
cwd=tmp_path,
env=environment,
text=True,
capture_output=True,
check=False,
)


def test_release_candidate_version_returns_exact_final_version_without_git_tag(tmp_path):
tmp_path.joinpath("VERSION").write_text("26.10.00\n")

result = _generate_version(tmp_path, "26.10.00")

assert result.returncode == 0
assert result.stdout == "26.10.00"
assert result.stderr == ""


@pytest.mark.parametrize("candidate_version", ["v26.10.00", "26.10", "26.10.00rc0"])
def test_release_candidate_version_rejects_non_final_formats(tmp_path, candidate_version):
tmp_path.joinpath("VERSION").write_text("26.10.00\n")

result = _generate_version(tmp_path, candidate_version)

assert result.returncode == 1
assert "must use a three-component numeric format" in result.stderr


def test_release_candidate_version_supports_independently_versioned_repository(tmp_path):
tmp_path.joinpath("VERSION").write_text("0.3.0\n")

result = _generate_version(tmp_path, "0.3.0")

assert result.returncode == 0
assert result.stdout == "0.3.0"


def test_release_candidate_version_rejects_different_source_major_minor(tmp_path):
tmp_path.joinpath("VERSION").write_text("26.12.00a0\n")

result = _generate_version(tmp_path, "26.10.00")

assert result.returncode == 1
assert "does not match source major/minor '26.12'" in result.stderr


def test_release_candidate_version_uses_preserved_source_after_output_truncation(tmp_path):
tmp_path.joinpath("VERSION").write_text("")

result = _generate_version(tmp_path, "26.10.00", source_version="26.10.00")

assert result.returncode == 0
assert result.stdout == "26.10.00"


def test_release_candidate_version_requires_version_file(tmp_path):
result = _generate_version(tmp_path, "26.10.00")

assert result.returncode == 1
assert "requires a VERSION file" in result.stderr
44 changes: 44 additions & 0 deletions tests/test_release_candidate_build_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os
import subprocess
from pathlib import Path

TOOLS_DIRECTORY = Path(__file__).resolve().parents[1] / "tools"


def _environment(**updates: str) -> dict[str, str]:
environment = os.environ.copy()
environment["PATH"] = f"{TOOLS_DIRECTORY}:{environment['PATH']}"
environment.update(updates)
return environment


def test_release_candidate_is_a_release_build():
result = subprocess.run(
[TOOLS_DIRECTORY / "rapids-is-release-build"],
env=_environment(RAPIDS_BUILD_TYPE="release-candidate", GITHUB_REF="refs/heads/main"),
text=True,
capture_output=True,
check=False,
)

assert result.returncode == 0
assert "is release build" in result.stderr


def test_release_candidate_rattler_channels_exclude_public_rapids_channels():
command = f'source "{TOOLS_DIRECTORY / "rapids-rattler-channel-string"}"; printf "%s\\n" "${{RATTLER_CHANNELS[*]}}"'
result = subprocess.run(
["bash", "-c", command],
env=_environment(
RAPIDS_BUILD_TYPE="release-candidate",
GITHUB_REF="refs/heads/main",
RAPIDS_CONDA_BLD_OUTPUT_DIR="/tmp/conda-output",
),
text=True,
capture_output=True,
check=False,
)

assert result.returncode == 0
assert result.stdout.splitlines()[-1] == "--channel conda-forge"
assert "rapidsai" not in result.stdout
31 changes: 31 additions & 0 deletions tools/rapids-generate-version
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,37 @@
set -euo pipefail
export RAPIDS_SCRIPT_NAME="rapids-generate-version"

if [[ -n "${RAPIDS_RELEASE_CANDIDATE_VERSION:-}" ]]; then
readonly candidate_version="${RAPIDS_RELEASE_CANDIDATE_VERSION}"
readonly candidate_version_regex='^[0-9]+\.[0-9]+\.[0-9]+$'
if [[ ! "${candidate_version}" =~ ${candidate_version_regex} ]]; then
echo "RAPIDS_RELEASE_CANDIDATE_VERSION must use a three-component numeric format, got '${candidate_version}'" >&2

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is going to handle UCXX versioning.

And maybe the error message should include a template like YY.MM.XX?

exit 1
fi
source_version="${RAPIDS_RELEASE_CANDIDATE_SOURCE_VERSION:-}"
if [[ -z "${source_version}" ]]; then
if [[ ! -f VERSION ]]; then
echo "RAPIDS_RELEASE_CANDIDATE_VERSION requires a VERSION file or RAPIDS_RELEASE_CANDIDATE_SOURCE_VERSION" >&2
exit 1
fi
source_version="$(head -n 1 VERSION)"
fi
readonly source_version
readonly source_version_regex='^([0-9]+)\.([0-9]+)(\.|$)'
if [[ ! "${source_version}" =~ ${source_version_regex} ]]; then
echo "source version must begin with two numeric components, got '${source_version}'" >&2
exit 1
fi
readonly source_major_minor="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this merits a comment on BASH_REMATCH semantics, because I always have to look it up

readonly candidate_major_minor="${candidate_version%.*}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this up to line 13 so it's closer to where candidate_version is defined
scratch that, let's just define this inline in the comparison in line 29 -- this doesn't need to be a variable if we never use it again.

if [[ "${source_major_minor}" != "${candidate_major_minor}" ]]; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if [[ "${source_major_minor}" != "${candidate_major_minor}" ]]; then
if [[ "${source_major_minor}" != "${candidate_version%.*}" ]]; then

This also makes the error message more consistent with the comparison

echo "release-candidate version '${candidate_version}' does not match source major/minor '${source_major_minor}'" >&2
exit 1
fi
echo -n "${candidate_version}"
exit 0
fi

if rapids-is-release-build; then
dunamai_version=$(python -m dunamai from git --format "{base}")
else
Expand Down
4 changes: 2 additions & 2 deletions tools/rapids-github-run-id
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ else
workflow_that_produced_artifacts="pr.yaml"
workflow_that_produced_artifacts_regex="\\.github/workflows/pr\\.yaml"
;;
branch|nightly)
branch|nightly|release-candidate)
workflow_that_produced_artifacts="build.yaml"
workflow_that_produced_artifacts_regex="\\.github/workflows/build\\.yaml"
;;
*)
rapids-echo-stderr "RAPIDS_BUILD_TYPE must be one of [branch, nightly, pull-request]"
rapids-echo-stderr "RAPIDS_BUILD_TYPE must be one of [branch, nightly, pull-request, release-candidate]"
exit 1
;;
esac
Expand Down
7 changes: 4 additions & 3 deletions tools/rapids-is-release-build
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/bin/bash
# A utility script that examines environment variables provided by
# GitHub Actions to determine whether the current build is a "release" build.
# A "release" build occurs when the GITHUB_REF environment variable matches
# the pattern "refs/tags/vYY.MM.PP".
# A "release" build occurs when the workflow explicitly identifies a release
# candidate or when GITHUB_REF matches the pattern "refs/tags/vYY.MM.PP".

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

identifies works here semantically in both the active and the passive form, which makes the meaning unclear.

Suggested change
# A "release" build occurs when the workflow explicitly identifies a release
# candidate or when GITHUB_REF matches the pattern "refs/tags/vYY.MM.PP".
# A "release" build occurs when the workflow explicitly specifies a release
# candidate or when GITHUB_REF matches the pattern "refs/tags/vYY.MM.PP".

# Example:
# if rapids-is-release-build; then echo "hi"; fi
set -e
export RAPIDS_SCRIPT_NAME="rapids-is-release-build"

if [[ "${GITHUB_REF}" =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
if [[ "${RAPIDS_BUILD_TYPE:-}" == "release-candidate" ]] ||
[[ "${GITHUB_REF:-}" =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
rapids-echo-stderr "is release build"
exit 0
fi
Expand Down
5 changes: 3 additions & 2 deletions tools/rapids-prompt-local-repo-config
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#
# Variables:
#
# * RAPIDS_BUILD_TYPE = One of "branch", "nightly", or "pull-request".
# * RAPIDS_BUILD_TYPE = One of "branch", "nightly", "pull-request", or
# "release-candidate".
# * RAPIDS_NIGHTLY_DATE = Date in YYYY-MM-DD format, used to organize nightly uploads.
# If not provided, the current system time is used.
# Only used when `RAPIDS_BUILD_TYPE` is "nightly".
Expand All @@ -24,7 +25,7 @@ if [ "${CI:-false}" = "false" ]; then
if [ -z "${RAPIDS_BUILD_TYPE:-}" ]; then
{
echo ""
read -r -p "Enter workflow type (one of: pull-request|branch|nightly): " RAPIDS_BUILD_TYPE
read -r -p "Enter workflow type (one of: pull-request|branch|nightly|release-candidate): " RAPIDS_BUILD_TYPE
export RAPIDS_BUILD_TYPE
echo ""
echo "Suppress this prompt in the future by setting the 'RAPIDS_BUILD_TYPE' environment variable:"
Expand Down
7 changes: 5 additions & 2 deletions tools/rapids-rattler-channel-string
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@

RAPIDS_CHANNEL="rapidsai-nightly"

# Replace dev/nightly channels if build is a release build
if rapids-is-release-build; then
# Candidate dependencies come only from the frozen local candidate channel and
# conda-forge. They must not resolve from either public RAPIDS channel.
if [[ "${RAPIDS_BUILD_TYPE:-}" == "release-candidate" ]]; then
RAPIDS_CHANNEL=""
elif rapids-is-release-build; then
Comment on lines +38 to +42

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for nearly all of rapids, but cucim still uses conda-build and their configuration script is vendored in the cucim ci/ directory, so these changes will need to be made there, too.

RAPIDS_CHANNEL="rapidsai"
fi

Expand Down
Loading