Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use current time as commit timestamp #42

Merged
merged 5 commits into from
Feb 6, 2024
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
7 changes: 5 additions & 2 deletions softpack_core/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class Artifacts:
users_folder_name = "users"
groups_folder_name = "groups"
credentials_callback = None
signature = None

@dataclass
class Object:
Expand Down Expand Up @@ -204,7 +203,11 @@ def __init__(self) -> None:
]
)

self.signature = pygit2.Signature(
@property
def signature(self) -> pygit2.Signature:
"""Get current pygit2 commit signature: author/committer/timestamp."""
# creating one of these implicitly looks up the current time.
return pygit2.Signature(
self.settings.artifacts.repo.author,
self.settings.artifacts.repo.email,
)
Expand Down
10 changes: 10 additions & 0 deletions tests/integration/test_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import shutil
import threading
import time
from pathlib import Path

import pygit2
Expand Down Expand Up @@ -74,6 +75,15 @@ def test_commit_and_push() -> None:

assert file_in_remote(file_path)

time.sleep(1)

newer_commit_oid = artifacts.commit_and_push(new_tree, "new timestamp")

assert (
artifacts.repo.get(new_commit_oid).commit_time
!= artifacts.repo.get(newer_commit_oid).commit_time
)


def add_test_file_to_repo(artifacts: Artifacts) -> tuple[pygit2.Oid, Path]:
new_file_name = "new_file.txt"
Expand Down
13 changes: 10 additions & 3 deletions tests/integration/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@


def test_create(httpx_post, testable_env_input: EnvironmentInput) -> None:
orig_input_name = testable_env_input.name
result = Environment.create(testable_env_input)
testable_env_input.name = orig_input_name
assert isinstance(result, CreateEnvironmentSuccess)
httpx_post.assert_called_once()
builder_called_correctly(httpx_post, testable_env_input)
Expand Down Expand Up @@ -84,6 +86,7 @@ def test_create(httpx_post, testable_env_input: EnvironmentInput) -> None:
assert yaml.safe_load(ymlFile.data.decode()) == expected_yaml

result = Environment.create(testable_env_input)
testable_env_input.name = orig_input_name
assert isinstance(result, CreateEnvironmentSuccess)

path = Path(
Expand Down Expand Up @@ -137,7 +140,7 @@ def test_create_cleans_up_after_builder_failure(
dir = Path(
Environment.artifacts.environments_root,
testable_env_input.path,
testable_env_input.name + "-1",
testable_env_input.name,
)
builtPath = dir / Environment.artifacts.built_by_softpack_file
ymlPath = dir / Environment.artifacts.environments_file
Expand Down Expand Up @@ -183,13 +186,13 @@ def test_delete(httpx_post, testable_env_input) -> None:
path = Path(
Environment.artifacts.environments_root,
testable_env_input.path,
testable_env_input.name + "-1",
testable_env_input.name,
Artifacts.built_by_softpack_file,
)
assert file_in_remote(path)

result = Environment.delete(
testable_env_input.name + "-1", testable_env_input.path
testable_env_input.name, testable_env_input.path
)
assert isinstance(result, DeleteEnvironmentSuccess)

Expand All @@ -207,7 +210,9 @@ async def test_write_artifact(httpx_post, testable_env_input):
)
assert isinstance(result, InvalidInputError)

orig_name = testable_env_input.name
result = Environment.create(testable_env_input)
testable_env_input.name = orig_name
assert isinstance(result, CreateEnvironmentSuccess)
httpx_post.assert_called_once()

Expand Down Expand Up @@ -241,7 +246,9 @@ def test_iter(testable_env_input):

@pytest.mark.asyncio
async def test_states(httpx_post, testable_env_input):
orig_name = testable_env_input.name
result = Environment.create(testable_env_input)
testable_env_input.name = orig_name
assert isinstance(result, CreateEnvironmentSuccess)
httpx_post.assert_called_once()

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ allowlist_externals =
mypy
commands =
flake8 softpack_core
flake8 tests --ignore=D101,D102,D103,D107
flake8 tests --ignore=D101,D102,D103,D107,E203,E266,W503
mypy softpack_core

[testenv:build]
Expand Down
Loading