Repository: oppia/oppia

Issue:
Incorrect version in package.json
The version number in package.json should be equal to current release version?

Incorrect version in package.json
The version number in package.json should be equal to current release version?



Discussion:
/cc @vojtechjelinek?
This is not really needed, but it might be nice to update it after every release. @ankita240796 should this be part of the release scripts?
/cc @vojtechjelinek?
This is not really needed, but it might be nice to update it after every release. @ankita240796 should this be part of the release scripts?

Resolving patch:
diff --git a/scripts/release_scripts/update_changelog_and_credits.py b/scripts/release_scripts/update_changelog_and_credits.py
--- a/scripts/release_scripts/update_changelog_and_credits.py
+++ b/scripts/release_scripts/update_changelog_and_credits.py
@@ -44,6 +44,7 @@
 AUTHORS_FILEPATH = os.path.join('', 'AUTHORS')
 CHANGELOG_FILEPATH = os.path.join('', 'CHANGELOG')
 CONTRIBUTORS_FILEPATH = os.path.join('', 'CONTRIBUTORS')
+PACKAGE_JSON_PATH = os.path.join('', 'package.json')
 GIT_CMD_CHECKOUT = 'git checkout -- %s %s %s %s' % (
     CHANGELOG_FILEPATH, AUTHORS_FILEPATH, CONTRIBUTORS_FILEPATH,
     ABOUT_PAGE_CONSTANTS_FILEPATH)
@@ -474,6 +475,18 @@ def get_release_summary_lines():
     return release_summary_lines
 
 
+def update_package_json():
+    """Updates version param in package json file to match the current
+    release version.
+    """
+    release_version = common.get_current_release_version_number(
+        common.get_current_branch_name())
+
+    common.inplace_replace_file(
+        PACKAGE_JSON_PATH, '"version": ".*"',
+        '"version": "%s"' % release_version)
+
+
 def main():
     """Collects necessary info and dumps it to disk."""
     branch_name = common.get_current_branch_name()
@@ -557,12 +570,13 @@ def main():
     update_authors(release_summary_lines)
     update_contributors(release_summary_lines)
     update_developer_names(release_summary_lines)
+    update_package_json()
 
     message = (
         'Please check the changes and make updates if required in the '
-        'following files:\n1. %s\n2. %s\n3. %s\n4. %s\n' % (
+        'following files:\n1. %s\n2. %s\n3. %s\n4. %s\n5. %s\n' % (
             CHANGELOG_FILEPATH, AUTHORS_FILEPATH, CONTRIBUTORS_FILEPATH,
-            ABOUT_PAGE_CONSTANTS_FILEPATH))
+            ABOUT_PAGE_CONSTANTS_FILEPATH, PACKAGE_JSON_PATH))
     common.ask_user_to_confirm(message)
 
     create_branch(


Test patch:
diff --git a/core/tests/release_sources/mock_package.json b/core/tests/release_sources/mock_package.json
new file mode 100644
--- /dev/null
+++ b/core/tests/release_sources/mock_package.json
@@ -0,0 +1,12 @@
+{
+  "name": "oppia",
+  "version": "2.8.4",
+  "description": "Oppia enables the creation of interactive online lessons.",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/oppia/oppia.git"
+  },
+}
diff --git a/scripts/release_scripts/update_changelog_and_credits_test.py b/scripts/release_scripts/update_changelog_and_credits_test.py
--- a/scripts/release_scripts/update_changelog_and_credits_test.py
+++ b/scripts/release_scripts/update_changelog_and_credits_test.py
@@ -21,6 +21,7 @@
 
 import getpass
 import os
+import re
 import subprocess
 import sys
 import tempfile
@@ -42,6 +43,7 @@
 MOCK_AUTHORS_FILEPATH = os.path.join(RELEASE_TEST_DIR, 'AUTHORS')
 MOCK_CONTRIBUTORS_FILEPATH = os.path.join(RELEASE_TEST_DIR, 'CONTRIBUTORS')
 MOCK_ABOUT_PAGE_CONSTANTS_FILEPATH = 'about_temp_file.ts'
+MOCK_PACKAGE_JSON_PATH = os.path.join(RELEASE_TEST_DIR, 'mock_package.json')
 
 MOCK_UPDATED_CHANGELOG_FILEPATH = os.path.join(
     RELEASE_TEST_DIR, 'UPDATED_CHANGELOG')
@@ -543,6 +545,25 @@ def mock_open_new_tab_in_browser_if_possible(unused_url):
                     '1.2.3')
         self.assertEqual(check_function_calls, expected_check_function_calls)
 
+    def test_update_package_json(self):
+        package_json_swap = self.swap(
+            update_changelog_and_credits, 'PACKAGE_JSON_PATH',
+            MOCK_PACKAGE_JSON_PATH)
+        package_json_content = python_utils.open_file(
+            MOCK_PACKAGE_JSON_PATH, 'r').read()
+        regex = re.compile('"version": ".*"')
+        expected_package_json_content = regex.sub(
+            '"version": "1.2.3"', package_json_content)
+        try:
+            with self.branch_name_swap, package_json_swap:
+                update_changelog_and_credits.update_package_json()
+            updated_package_json_content = python_utils.open_file(
+                MOCK_PACKAGE_JSON_PATH, 'r').read()
+            self.assertEqual(
+                updated_package_json_content, expected_package_json_content)
+        finally:
+            write_to_file(MOCK_PACKAGE_JSON_PATH, package_json_content)
+
     def test_function_calls(self):
         check_function_calls = {
             'check_blocking_bug_issue_count_gets_called': False,
@@ -554,7 +575,8 @@ def test_function_calls(self):
             'update_developer_names_gets_called': False,
             'get_release_summary_lines_gets_called': False,
             'create_branch_gets_called': False,
-            'open_new_tab_in_browser_if_possible_gets_called': False
+            'open_new_tab_in_browser_if_possible_gets_called': False,
+            'update_package_json_gets_called': False
         }
         expected_check_function_calls = {
             'check_blocking_bug_issue_count_gets_called': True,
@@ -566,7 +588,8 @@ def test_function_calls(self):
             'update_developer_names_gets_called': True,
             'get_release_summary_lines_gets_called': True,
             'create_branch_gets_called': True,
-            'open_new_tab_in_browser_if_possible_gets_called': True
+            'open_new_tab_in_browser_if_possible_gets_called': True,
+            'update_package_json_gets_called': True
         }
         def mock_get_organization(unused_self, unused_name):
             return github.Organization.Organization(
@@ -604,6 +627,8 @@ def mock_get_repo(unused_self, unused_repo_name):
         def mock_open_tab(unused_url):
             check_function_calls[
                 'open_new_tab_in_browser_if_possible_gets_called'] = True
+        def mock_update_package_json():
+            check_function_calls['update_package_json_gets_called'] = True
 
         get_org_swap = self.swap(
             github.Github, 'get_organization', mock_get_organization)
@@ -639,6 +664,9 @@ def mock_open_tab(unused_url):
             github.Organization.Organization, 'get_repo', mock_get_repo)
         open_tab_swap = self.swap(
             common, 'open_new_tab_in_browser_if_possible', mock_open_tab)
+        update_swap = self.swap(
+            update_changelog_and_credits, 'update_package_json',
+            mock_update_package_json)
 
         with self.branch_name_swap, self.release_summary_swap, self.args_swap:
             with self.getpass_swap, input_swap, check_prs_swap:
@@ -647,7 +675,7 @@ def mock_open_tab(unused_url):
                         with update_developer_names_swap, get_lines_swap:
                             with create_branch_swap, get_repo_swap:
                                 with blocking_bug_swap, get_org_swap:
-                                    with get_org_repo_swap:
+                                    with get_org_repo_swap, update_swap:
                                         update_changelog_and_credits.main()
 
         self.assertEqual(check_function_calls, expected_check_function_calls)