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

feat: expose APP_VERSION env var with HEAD commit sha #2

Merged
merged 3 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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: 6 additions & 1 deletion tubular/scripts/frontend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def get_app_config(self):
""" Combines the common and environment configs APP_CONFIG data """
app_config = self.common_cfg.get('APP_CONFIG', {})
app_config.update(self.env_cfg.get('APP_CONFIG', {}))
app_config['APP_VERSION'] = self.get_version_commit_sha()
if not app_config:
self.LOG('Config variables do not exist for app {}.'.format(self.app_name))
return app_config
Expand Down Expand Up @@ -139,12 +140,16 @@ def build_app(self, env_vars, fail_msg):
if build_return_code != 0:
self.FAIL(1, fail_msg)

def get_version_commit_sha(self):
""" Returns the commit SHA of the current HEAD """
return LocalGitAPI(Repo(self.app_name)).get_head_sha()

def create_version_file(self):
""" Creates a version.json file to be deployed with frontend """
# Add version.json file to build.
version = {
'repo': self.app_name,
'commit': LocalGitAPI(Repo(self.app_name)).get_head_sha(),
'commit': self.get_version_commit_sha(),
'created': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
}
try:
Expand Down
5 changes: 4 additions & 1 deletion tubular/tests/test_frontend_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ class TestFrontendBuildConfigHandling(TestCase):
Cursory tests for frontend config parsing + marshalling.
"""

@mock.patch.object(FrontendBuilder, 'get_version_commit_sha', return_value ='<COMMIT_HASH>')
@mock.patch('tubular.scripts.frontend_utils.shutil.copyfile')
@mock.patch.object(FrontendBuilder, 'create_version_file')
@mock.patch.object(FrontendBuilder, 'build_app')
@mock.patch.object(FrontendBuilder, 'install_requirements')
def test_frontend_build_config_handling(
self, mock_install, mock_build, mock_create_version, mock_shutil_copyfile
self, mock_install, mock_build, mock_create_version, mock_shutil_copyfile, mock_get_version_commit
):
exit_code = None
try:
Expand Down Expand Up @@ -65,8 +66,10 @@ def test_frontend_build_config_handling(
"NONE='None'",
"NONE_WITH_QUOTES='None'",
"JS_CONFIG_FILEPATH='dummy/file/path/env.stage.config.jsx'",
"APP_VERSION='<COMMIT_HASH>'"
]
assert mock_create_version.call_count == 1
assert mock_shutil_copyfile.call_count == 1
assert mock_get_version_commit.call_count == 1
# Verify that source is correct and destination is rightly formatted
mock_shutil_copyfile.assert_called_with('dummy/file/path/env.stage.config.jsx', 'coolfrontend/env.config.jsx')
Loading