Skip to content
Open
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
3 changes: 3 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ on:
required: false
type: boolean
default: false
push:
tags: ['*']

env:
# Force the stdout and stderr streams to be unbuffered
PYTHONUNBUFFERED: 1
GH_TOKEN: ${{ github.token }}
CHECKOUT_REF: ""
DISABLE_CI_CACHE: ${{ github.ref_type == 'tag' && '1' || github.event.inputs.no_cache || '0' }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
CLICKHOUSE_TEST_STAT_URL: ${{ secrets.CLICKHOUSE_TEST_STAT_URL }}
CLICKHOUSE_TEST_STAT_LOGIN: ${{ secrets.CLICKHOUSE_TEST_STAT_LOGIN }}
Expand Down
12 changes: 11 additions & 1 deletion ci/praktika/yaml_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Templates:

on:
workflow_dispatch:
inputs:{DISPATCH_INPUTS}
inputs:{DISPATCH_INPUTS}{TAG_PUSH_TRIGGER}

env:
# Force the stdout and stderr streams to be unbuffered
Expand Down Expand Up @@ -519,13 +519,23 @@ def _all_needs(job_name: str) -> set:
base_template = YamlGenerator.Templates.TEMPLATE_DISPATCH_WORKFLOW
format_kwargs = {
"DISPATCH_INPUTS": dispatch_inputs,
"TAG_PUSH_TRIGGER": (
f"\n push:\n tags: {self.workflow_config.tags}"
if self.workflow_config.tags
else ""
),
"GH_TOKEN_PERMISSIONS": (
YamlGenerator.Templates.TEMPLATE_GH_TOKEN_PERMISSIONS
),
}
ENV_CHECKOUT_REFERENCE = (
YamlGenerator.Templates.TEMPLATE_ENV_CHECKOUT_REF_DEFAULT
)
if self.workflow_config.tags:
ENV_CHECKOUT_REFERENCE += (
"\n DISABLE_CI_CACHE: "
"${{{{ github.ref_type == 'tag' && '1' || github.event.inputs.no_cache || '0' }}}}"
)
elif self.workflow_config.event in (Workflow.Event.MERGE_QUEUE,):
base_template = YamlGenerator.Templates.TEMPLATE_MERGE_QUEUE_0
format_kwargs = {}
Expand Down
24 changes: 23 additions & 1 deletion ci/tests/test_clickhouse_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Tests for `ci.jobs.scripts.clickhouse_version.CHVersion.get_current_version_as_dict`.
Tests for ClickHouse CI version handling.

This branch uses the release version from `cmake/autogenerated_versions.txt`
as-is instead of deriving CI-only version fields from the current checkout.
Expand All @@ -8,9 +8,12 @@
import os
import sys

import pytest

sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../.."))

from ci.jobs.scripts.clickhouse_version import CHVersion
from version_helper import check_tag_version

_RELEASE = {
"major": 99,
Expand Down Expand Up @@ -91,3 +94,22 @@ def test_master_shallow_checkout_uses_release_version_as_is(monkeypatch):
)
version = CHVersion.get_current_version_as_dict()
assert version == _RELEASE


def test_matching_tag(monkeypatch):
monkeypatch.setattr(
"version_helper.read_versions",
lambda _: {"describe": "v1.2.3.4.altinitystable"},
)

check_tag_version("v1.2.3.4.altinitystable")


def test_mismatching_tag(monkeypatch):
monkeypatch.setattr(
"version_helper.read_versions",
lambda _: {"describe": "v1.2.3.4.altinitystable"},
)

with pytest.raises(ValueError, match="does not match VERSION_DESCRIBE"):
check_tag_version("v1.2.3.5.altinitystable")
2 changes: 2 additions & 0 deletions ci/workflows/master.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
workflow = Workflow.Config(
name="MasterCI",
event=Workflow.Event.DISPATCH,
tags=["*"],
inputs=[
Workflow.Config.InputConfig(
name="no_cache",
Expand Down Expand Up @@ -106,6 +107,7 @@
enable_commit_status_on_failure=True,
enable_slack_feed=False,
pre_hooks=[
'[ "$GITHUB_REF_TYPE" != "tag" ] || python3 ./tests/ci/version_helper.py --check-tag',
# "python3 ./ci/jobs/scripts/workflow_hooks/store_data.py", # NOTE (carlosfelipeor): we don't use this in master CI
"python3 ./ci/jobs/scripts/workflow_hooks/version_log.py",
"python3 ./ci/jobs/scripts/workflow_hooks/parse_ci_tags.py",
Expand Down
26 changes: 26 additions & 0 deletions tests/ci/version_helper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import logging
import os
from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser, ArgumentTypeError
from pathlib import Path
from typing import Any, Dict, Iterable, List, Literal, Optional, Set, Tuple, Union
Expand Down Expand Up @@ -297,6 +298,19 @@ def read_versions(versions_path: Union[Path, str] = FILE_WITH_VERSION_PATH) -> V
return versions


def check_tag_version(
tag: str, versions_path: Union[Path, str] = FILE_WITH_VERSION_PATH
) -> None:
expected_tag = read_versions(versions_path)["describe"]
if tag != expected_tag:
raise ValueError(
f"Tag [{tag}] does not match VERSION_DESCRIBE [{expected_tag}] "
f"in {versions_path}"
)

print(f"Tag [{tag}] matches {versions_path}")


def get_version_from_repo(
versions_path: Union[Path, str] = FILE_WITH_VERSION_PATH,
git: Optional[Git] = None,
Expand Down Expand Up @@ -524,12 +538,24 @@ def main():
help=f"update {GENERATED_CONTRIBUTORS} file and exit, "
"doesn't work on shallow repo",
)
parser.add_argument(
"--check-tag",
action="store_true",
help="check that GITHUB_REF_NAME matches VERSION_DESCRIBE and exit",
)
args = parser.parse_args()

if args.update_contributors:
update_contributors()
return

if args.check_tag:
tag = os.getenv("GITHUB_REF_NAME", "")
if not tag:
raise ValueError("GITHUB_REF_NAME is empty")
check_tag_version(tag, args.version_path)
return

version = get_version_from_repo(args.version_path, Git(True))

if args.update_part:
Expand Down
Loading