Skip to content

Commit

Permalink
Merge pull request #2 from edx/ags/datadog-version-envvar
Browse files Browse the repository at this point in the history
feat: expose APP_VERSION env var with HEAD commit sha
  • Loading branch information
abdullahwaheed authored May 24, 2024
2 parents d034d2f + 98fe94e commit 4f58d4a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
uses: codecov/codecov-action@v3
with:
flags: unittests
fail_ci_if_error: true
fail_ci_if_error: false
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')

0 comments on commit 4f58d4a

Please sign in to comment.