forked from canonical/craft-application
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: generate version for templates usage (canonical#548)
Signed-off-by: Dariusz Duda <[email protected]>
- Loading branch information
1 parent
9a7637a
commit 2bc1acc
Showing
10 changed files
with
522 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser General Public License version 3 as | ||
# published by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""Git repository consts.""" | ||
|
||
from typing import Final | ||
|
||
COMMIT_SHORT_SHA_LEN: Final[int] = 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
import os | ||
import pathlib | ||
import shutil | ||
import subprocess | ||
from dataclasses import dataclass | ||
from importlib import metadata | ||
from typing import TYPE_CHECKING, Any | ||
|
||
|
@@ -27,7 +29,7 @@ | |
import jinja2 | ||
import pydantic | ||
import pytest | ||
from craft_application import application, launchpad, models, services, util | ||
from craft_application import application, git, launchpad, models, services, util | ||
from craft_cli import EmitterMode, emit | ||
from craft_providers import bases | ||
from jinja2 import FileSystemLoader | ||
|
@@ -407,3 +409,76 @@ def new_dir(tmp_path): | |
yield tmp_path | ||
|
||
os.chdir(cwd) | ||
|
||
|
||
@pytest.fixture | ||
def empty_working_directory( | ||
tmp_path: pathlib.Path, | ||
monkeypatch: pytest.MonkeyPatch, | ||
) -> pathlib.Path: | ||
repo_dir = pathlib.Path(tmp_path, "test-repo") | ||
repo_dir.mkdir() | ||
monkeypatch.chdir(repo_dir) | ||
return repo_dir | ||
|
||
|
||
@pytest.fixture | ||
def empty_repository(empty_working_directory: pathlib.Path) -> pathlib.Path: | ||
subprocess.run(["git", "init"], check=True) | ||
return empty_working_directory | ||
|
||
|
||
@dataclass | ||
class RepositoryDefinition: | ||
repository_path: pathlib.Path | ||
commit: str | ||
tag: str | None = None | ||
|
||
@property | ||
def short_commit(self) -> str: | ||
"""Return abbreviated commit.""" | ||
return git.short_commit_sha(self.commit) | ||
|
||
|
||
@pytest.fixture | ||
def repository_with_commit(empty_repository: pathlib.Path) -> RepositoryDefinition: | ||
repo = git.GitRepo(empty_repository) | ||
(empty_repository / "Some file").touch() | ||
repo.add_all() | ||
commit_sha = repo.commit("1") | ||
return RepositoryDefinition( | ||
repository_path=empty_repository, | ||
commit=commit_sha, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def repository_with_annotated_tag( | ||
repository_with_commit: RepositoryDefinition, | ||
) -> RepositoryDefinition: | ||
test_tag = "v3.2.1" | ||
subprocess.run( | ||
["git", "config", "--local", "user.name", "Testcraft", test_tag], check=True | ||
) | ||
subprocess.run( | ||
["git", "config", "--local", "user.email", "[email protected]", test_tag], | ||
check=True, | ||
) | ||
subprocess.run(["git", "tag", "-a", "-m", "testcraft tag", test_tag], check=True) | ||
repository_with_commit.tag = test_tag | ||
return repository_with_commit | ||
|
||
|
||
@pytest.fixture | ||
def repository_with_unannotated_tag( | ||
repository_with_commit: RepositoryDefinition, | ||
) -> RepositoryDefinition: | ||
subprocess.run(["git", "config", "--local", "user.name", "Testcraft"], check=True) | ||
subprocess.run( | ||
["git", "config", "--local", "user.email", "[email protected]"], | ||
check=True, | ||
) | ||
test_tag = "non-annotated" | ||
subprocess.run(["git", "tag", test_tag], check=True) | ||
repository_with_commit.tag = test_tag | ||
return repository_with_commit |
Oops, something went wrong.