-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/HHS/simpler-grants-gov into…
… 1928/analytics-local-setup
- Loading branch information
Showing
8 changed files
with
198 additions
and
7 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
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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import re | ||
import typing | ||
from datetime import datetime | ||
|
||
from pydantic_settings import SettingsConfigDict | ||
|
||
import src.util.datetime_util as datetime_util | ||
from src.util.env_config import PydanticBaseEnvConfig | ||
|
||
# We expect release notes to be formatted as: | ||
# YYYY-MM-DD-# | ||
# However we don't always put leading zeroes, so all of the following | ||
# would be valid release versions: | ||
# 2024.11.27-1 | ||
# 2024.11.5-1 | ||
# 2024.4.30-1 | ||
RELEASE_NOTE_REGEX = re.compile( | ||
r""" | ||
^[0-9]{4} # Exactly 4 leading digits | ||
(?:\.[0-9]{1,2}) # Period followed by 1-2 digits | ||
(?:\.[0-9]{1,2}) # Period followed by 1-2 digits | ||
(?:\-[0-9]{1,2})$ # Ends with a dash and 1-2 digits | ||
""", | ||
re.ASCII | re.VERBOSE, | ||
) | ||
|
||
|
||
class DeployMetadataConfig(PydanticBaseEnvConfig): | ||
model_config = SettingsConfigDict(extra="allow") | ||
|
||
deploy_github_ref: str # DEPLOY_GITHUB_REF | ||
deploy_github_sha: str # DEPLOY_GITHUB_SHA | ||
deploy_timestamp: datetime # DEPLOY_TIMESTAMP | ||
|
||
def model_post_init(self, _context: typing.Any) -> None: | ||
"""Run after __init__ sets above values from env vars""" | ||
|
||
if RELEASE_NOTE_REGEX.match(self.deploy_github_ref): | ||
self.release_notes = ( | ||
f"https://github.com/HHS/simpler-grants-gov/releases/tag/{self.deploy_github_ref}" | ||
) | ||
else: | ||
self.release_notes = "https://github.com/HHS/simpler-grants-gov/releases" | ||
|
||
self.deploy_commit = ( | ||
f"https://github.com/HHS/simpler-grants-gov/commit/{self.deploy_github_sha}" | ||
) | ||
|
||
self.deploy_datetime_est = datetime_util.adjust_timezone( | ||
self.deploy_timestamp, "US/Eastern" | ||
) | ||
|
||
|
||
_deploy_metadata_config: DeployMetadataConfig | None = None | ||
|
||
|
||
def get_deploy_metadata_config() -> DeployMetadataConfig: | ||
global _deploy_metadata_config | ||
if _deploy_metadata_config is None: | ||
_deploy_metadata_config = DeployMetadataConfig() | ||
|
||
return _deploy_metadata_config |
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,32 @@ | ||
from src.util.deploy_metadata import DeployMetadataConfig | ||
|
||
|
||
def test_deploy_metadata_with_release_ref(monkeypatch): | ||
ref = "2024.11.27-1" | ||
sha = "44b954e85c4ca7e3714f9f988a919fae40ec3c98" | ||
|
||
monkeypatch.setenv("DEPLOY_GITHUB_REF", ref) | ||
monkeypatch.setenv("DEPLOY_GITHUB_SHA", sha) | ||
monkeypatch.setenv("DEPLOY_TIMESTAMP", "2024-12-02T21:25:18Z") | ||
|
||
config = DeployMetadataConfig() | ||
|
||
# Verify the calculated values are there | ||
assert config.release_notes == f"https://github.com/HHS/simpler-grants-gov/releases/tag/{ref}" | ||
assert config.deploy_commit == f"https://github.com/HHS/simpler-grants-gov/commit/{sha}" | ||
assert config.deploy_datetime_est.isoformat() == "2024-12-02T16:25:18-05:00" | ||
|
||
|
||
def test_deploy_metadata_with_non_release_ref(monkeypatch): | ||
sha = "44b954e85c4ca7e3714f9f988a919fae40ec3c98" | ||
|
||
monkeypatch.setenv("DEPLOY_GITHUB_REF", "main") | ||
monkeypatch.setenv("DEPLOY_GITHUB_SHA", sha) | ||
monkeypatch.setenv("DEPLOY_TIMESTAMP", "2024-06-01T03:13:11Z") | ||
|
||
config = DeployMetadataConfig() | ||
|
||
# Verify the calculated values are there | ||
assert config.release_notes == "https://github.com/HHS/simpler-grants-gov/releases" | ||
assert config.deploy_commit == f"https://github.com/HHS/simpler-grants-gov/commit/{sha}" | ||
assert config.deploy_datetime_est.isoformat() == "2024-05-31T23:13:11-04:00" |