Skip to content

Commit c314435

Browse files
committed
write_to_release_id_file
1 parent 96e054d commit c314435

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

src/gardenlinux/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,5 @@
145145
OCI_ANNOTATION_SIGNATURE_KEY = "io.gardenlinux.oci.signature"
146146
OCI_ANNOTATION_SIGNED_STRING_KEY = "io.gardenlinux.oci.signed-string"
147147
OCI_IMAGE_INDEX_MEDIA_TYPE = "application/vnd.oci.image.index.v1+json"
148+
149+
RELEASE_ID_FILE = ".github_release_id"

src/gardenlinux/github/release/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import json
22
import os
3+
import sys
34

45
import requests
56

7+
from gardenlinux.constants import RELEASE_ID_FILE
68
from gardenlinux.logger import LoggerSetup
79

810
LOGGER = LoggerSetup.get_logger("gardenlinux.github", "INFO")
@@ -47,6 +49,16 @@ def create_github_release(owner, repo, tag, commitish, latest, body):
4749
response.raise_for_status()
4850

4951

52+
def write_to_release_id_file(release_id):
53+
try:
54+
with open(RELEASE_ID_FILE, "w") as file:
55+
file.write(release_id)
56+
LOGGER.info(f"Created {RELEASE_ID_FILE} successfully.")
57+
except IOError as e:
58+
LOGGER.error(f"Could not create {RELEASE_ID_FILE} file: {e}")
59+
sys.exit(1)
60+
61+
5062
def upload_to_github_release_page(
5163
github_owner, github_repo, gardenlinux_release_id, file_to_upload, dry_run
5264
):

tests/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@
2727
TEST_GARDENLINUX_RELEASE = "1877.3"
2828
TEST_GARDENLINUX_COMMIT = "75df9f401a842914563f312899ec3ce34b24515c"
2929

30+
RELEASE_ID_FILE = ".github_release_id"
31+
3032
S3_DOWNLOADS_DIR = Path(os.path.dirname(__file__)) / ".." / "s3_downloads"

tests/github/conftest.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import os
22
import shutil
3+
from pathlib import Path
34

45
import pytest
56

6-
from ..constants import S3_DOWNLOADS_DIR
7+
from ..constants import RELEASE_ID_FILE, S3_DOWNLOADS_DIR
78

89

910
@pytest.fixture
@@ -26,3 +27,10 @@ def artifact_for_upload(downloads_dir):
2627
artifact.touch()
2728
yield artifact
2829
artifact.unlink()
30+
31+
32+
@pytest.fixture
33+
def release_id_file():
34+
f = Path(RELEASE_ID_FILE)
35+
yield f
36+
f.unlink()

tests/github/test_create_github_release.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import requests
33
import requests_mock
44

5-
from gardenlinux.github.release import create_github_release
5+
from gardenlinux.github.release import create_github_release, write_to_release_id_file
66

77
from ..constants import TEST_GARDENLINUX_COMMIT, TEST_GARDENLINUX_RELEASE
88

@@ -54,3 +54,16 @@ def test_create_github_release(caplog, github_token):
5454
False,
5555
"") == 101
5656
assert any("Release created successfully" in record.message for record in caplog.records), "Expected a success log record"
57+
58+
59+
def test_write_to_release_id_file(release_id_file):
60+
write_to_release_id_file(TEST_GARDENLINUX_RELEASE)
61+
assert release_id_file.read_text() == TEST_GARDENLINUX_RELEASE
62+
63+
64+
def test_write_to_release_id_file_broken_file_permissions(release_id_file, caplog):
65+
release_id_file.touch(0) # this will make the file unwritable
66+
67+
with pytest.raises(SystemExit):
68+
write_to_release_id_file(TEST_GARDENLINUX_RELEASE)
69+
assert any("Could not create" in record.message for record in caplog.records), "Expected a failure log record"

0 commit comments

Comments
 (0)