From 2826de856ce9e9b734f1bbad034aa36a6021bbc4 Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Wed, 22 May 2024 15:01:26 -0400 Subject: [PATCH 1/3] feat: expose APP_VERSION env var with HEAD commit sha --- tubular/scripts/frontend_utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tubular/scripts/frontend_utils.py b/tubular/scripts/frontend_utils.py index 7b8275e5..64d61df5 100755 --- a/tubular/scripts/frontend_utils.py +++ b/tubular/scripts/frontend_utils.py @@ -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 @@ -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: From 8e5fa51bc2c751ab6c97c551ae686b03079d18d3 Mon Sep 17 00:00:00 2001 From: Muhammad Abdullah Waheed Date: Thu, 23 May 2024 20:28:47 +0500 Subject: [PATCH 2/3] fix: fixed failing test --- tubular/tests/test_frontend_build.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tubular/tests/test_frontend_build.py b/tubular/tests/test_frontend_build.py index 07603e5e..5ff56cc0 100644 --- a/tubular/tests/test_frontend_build.py +++ b/tubular/tests/test_frontend_build.py @@ -18,12 +18,13 @@ class TestFrontendBuildConfigHandling(TestCase): Cursory tests for frontend config parsing + marshalling. """ + @mock.patch.object(FrontendBuilder, 'get_version_commit_sha', return_value ='') @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: @@ -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=''" ] 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') From 98fe94e41b1911619d7c88a967aba93b455d0260 Mon Sep 17 00:00:00 2001 From: Muhammad Abdullah Waheed Date: Thu, 23 May 2024 20:41:50 +0500 Subject: [PATCH 3/3] chore: set ci fail flag for codecov to false --- .github/workflows/tox.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 2769d133..81455eac 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -25,4 +25,4 @@ jobs: uses: codecov/codecov-action@v3 with: flags: unittests - fail_ci_if_error: true + fail_ci_if_error: false