Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
87 changes: 87 additions & 0 deletions tests/test_rapids-generate-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import os
import subprocess
from pathlib import Path

import pytest

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


def _generate_version(
tmp_path: Path,
) -> subprocess.CompletedProcess[str]:
environment = os.environ.copy()
environment["RAPIDS_BUILD_TYPE"] = "release-candidate"
return subprocess.run(
[TOOLS_DIRECTORY / "rapids-generate-version"],
cwd=tmp_path,
env=environment,
text=True,
capture_output=True,
check=False,
)


@pytest.mark.parametrize("source_version", ["26.10.00", "0.3.0", "0.52", "00.52", "00.52.01"])
def test_release_candidate_version_returns_source_version(tmp_path, source_version):
tmp_path.joinpath("VERSION").write_text(f"{source_version}\n")

result = _generate_version(tmp_path)

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


@pytest.mark.parametrize("source_version", ["v26.10.00", "26", "26.10.00.1", "26.10.00rc0"])
def test_release_candidate_version_rejects_non_final_formats(tmp_path, source_version):
tmp_path.joinpath("VERSION").write_text(f"{source_version}\n")

result = _generate_version(tmp_path)

assert result.returncode == 1
assert "VERSION file must use a numeric YY.MM or YY.MM.XX format" in result.stderr


def test_release_candidate_version_uses_committed_version_when_output_redirect_truncates_file(tmp_path):
tmp_path.joinpath("VERSION").write_text("26.10.00\n")
subprocess.run(["git", "init"], cwd=tmp_path, check=True, capture_output=True)
subprocess.run(["git", "add", "VERSION"], cwd=tmp_path, check=True, capture_output=True)
subprocess.run(
[
"git",
"-c",
"user.name=Test",
"-c",
"user.email=test@example.com",
"-c",
"commit.gpgsign=false",
"commit",
"-m",
"Add version",
],
cwd=tmp_path,
check=True,
capture_output=True,
)
environment = os.environ.copy()
environment["RAPIDS_BUILD_TYPE"] = "release-candidate"

result = subprocess.run(
["bash", "-c", f'"{TOOLS_DIRECTORY / "rapids-generate-version"}" > VERSION'],
cwd=tmp_path,
env=environment,
text=True,
capture_output=True,
check=False,
)

assert result.returncode == 0
assert tmp_path.joinpath("VERSION").read_text() == "26.10.00"


def test_release_candidate_version_requires_version_file(tmp_path):
result = _generate_version(tmp_path)

assert result.returncode == 1
assert "require a non-empty VERSION file in the working tree or at HEAD" 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
21 changes: 21 additions & 0 deletions tools/rapids-generate-version
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@
set -euo pipefail
export RAPIDS_SCRIPT_NAME="rapids-generate-version"

if [[ "${RAPIDS_BUILD_TYPE:-}" == "release-candidate" ]]; then
if [[ -s VERSION ]]; then
candidate_version="$(head -n 1 VERSION)"
elif git cat-file -e HEAD:VERSION 2>/dev/null; then
# Some build scripts redirect this command's output back to VERSION,
# which truncates the working file before this script starts.
candidate_version="$(git show HEAD:VERSION | sed -n '1p')"
Comment on lines +9 to +12

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 still don't understand how we arrive at this gate, but if it does ever happen, I think the handling here is correct.

else
echo "release-candidate builds require a non-empty VERSION file in the working tree or at HEAD" >&2
exit 1
fi
readonly candidate_version
readonly candidate_version_regex='^[0-9]+\.[0-9]+(\.[0-9]+)?$'
if [[ ! "${candidate_version}" =~ ${candidate_version_regex} ]]; then
echo "VERSION file must use a numeric YY.MM or YY.MM.XX format, got '${candidate_version}'" >&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 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 thread
msarahan marked this conversation as resolved.
RAPIDS_CHANNEL="rapidsai"
fi

Expand Down
Loading