From c6eb7da68dc8340d81655af6af52295518e0fe1b Mon Sep 17 00:00:00 2001 From: mazhead Date: Wed, 3 Feb 2021 11:52:43 +0100 Subject: [PATCH 1/7] Adding the scm_track_submodules option which should fix the https://github.com/ansible/awx/issues/7846 Signed-off-by: mazhead --- awx/api/serializers.py | 3 +- .../migrations/0136_scm_track_submodules.py | 37 +++++++++++++++++++ awx/main/models/projects.py | 4 ++ awx/main/tasks.py | 1 + awx/playbooks/project_update.yml | 2 + .../PromptDetail/PromptProjectDetail.jsx | 7 ++++ .../components/PromptDetail/data.project.json | 3 +- .../Project/ProjectAdd/ProjectAdd.test.jsx | 1 + .../Project/ProjectDetail/ProjectDetail.jsx | 7 ++++ .../ProjectDetail/ProjectDetail.test.jsx | 2 + .../Project/ProjectEdit/ProjectEdit.test.jsx | 1 + .../src/screens/Project/data.project.json | 3 +- .../screens/Project/shared/ProjectForm.jsx | 3 ++ .../Project/shared/ProjectForm.test.jsx | 1 + .../shared/ProjectSubForms/SharedFields.jsx | 13 +++++++ awx/ui_next/src/types.js | 1 + .../plugins/modules/tower_project.py | 8 ++++ awxkit/awxkit/api/pages/projects.py | 1 + 18 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 awx/main/migrations/0136_scm_track_submodules.py diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 93793a90f2..57090f7c7e 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -1350,6 +1350,7 @@ class ProjectOptionsSerializer(BaseSerializer): 'scm_branch', 'scm_refspec', 'scm_clean', + 'scm_track_submodules', 'scm_delete_on_update', 'credential', 'timeout', @@ -1497,7 +1498,7 @@ class ProjectSerializer(UnifiedJobTemplateSerializer, ProjectOptionsSerializer): ) if get_field_from_model_or_attrs('scm_type') == '': - for fd in ('scm_update_on_launch', 'scm_delete_on_update', 'scm_clean'): + for fd in ('scm_update_on_launch', 'scm_delete_on_update', 'scm_track_submodules', 'scm_clean'): if get_field_from_model_or_attrs(fd): raise serializers.ValidationError({fd: _('Update options must be set to false for manual projects.')}) return super(ProjectSerializer, self).validate(attrs) diff --git a/awx/main/migrations/0136_scm_track_submodules.py b/awx/main/migrations/0136_scm_track_submodules.py new file mode 100644 index 0000000000..132dc63636 --- /dev/null +++ b/awx/main/migrations/0136_scm_track_submodules.py @@ -0,0 +1,37 @@ +# Generated by Django 2.2.16 on 2021-02-02 14:41 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ +<<<<<<< HEAD:awx/main/migrations/0136_scm_track_submodules.py + ('main', '0135_schedule_sort_fallback_to_id'), +======= + ('main', '0131_undo_org_polymorphic_ee'), +>>>>>>> Update and rename 0124_scm_track_submodules.py to 0132_scm_track_submodules.py:awx/main/migrations/0132_scm_track_submodules.py + ] + + operations = [ + migrations.AddField( + model_name='Project', + name='scm_track_submodules', + field=models.BooleanField(help_text='Track submodule latest commit on specified branch.'), + ), + migrations.AddField( + model_name='ProjectUpdate', + name='scm_track_submodules', + field=models.BooleanField(help_text='Track submodule latest commit on specified branch.'), + ), + migrations.AlterField( + model_name='project', + name='scm_track_submodules', + field=models.BooleanField(default=False, help_text='Track submodules latest commits on defined branch.'), + ), + migrations.AlterField( + model_name='projectupdate', + name='scm_track_submodules', + field=models.BooleanField(default=False, help_text='Track submodules latest commits on defined branch.'), + ), + ] diff --git a/awx/main/models/projects.py b/awx/main/models/projects.py index b510a1b020..2125080bfb 100644 --- a/awx/main/models/projects.py +++ b/awx/main/models/projects.py @@ -115,6 +115,10 @@ class ProjectOptions(models.Model): default=False, help_text=_('Delete the project before syncing.'), ) + scm_track_submodules = models.BooleanField( + default=False, + help_text=_('Track submodules latest commits on defined branch.'), + ) credential = models.ForeignKey( 'Credential', related_name='%(class)ss', diff --git a/awx/main/tasks.py b/awx/main/tasks.py index a154f222da..d23499abab 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -2026,6 +2026,7 @@ class RunProjectUpdate(BaseTask): 'scm_url': scm_url, 'scm_branch': scm_branch, 'scm_clean': project_update.scm_clean, + 'scm_track_submodules': project_update.scm_track_submodules, 'roles_enabled': galaxy_creds_are_defined and settings.AWX_ROLES_ENABLED, 'collections_enabled': galaxy_creds_are_defined and settings.AWX_COLLECTIONS_ENABLED, } diff --git a/awx/playbooks/project_update.yml b/awx/playbooks/project_update.yml index e00bed4249..092cfd0467 100644 --- a/awx/playbooks/project_update.yml +++ b/awx/playbooks/project_update.yml @@ -12,6 +12,7 @@ # scm_password: password (only for svn/insights) # scm_accept_hostkey: true/false (only for git, set automatically) # scm_refspec: a refspec to fetch in addition to obtaining version +# scm_track_submodules: true/false # roles_enabled: Value of the global setting to enable roles downloading # collections_enabled: Value of the global setting to enable collections downloading # awx_version: Current running version of the awx or tower as a string @@ -36,6 +37,7 @@ version: "{{scm_branch|quote}}" refspec: "{{scm_refspec|default(omit)}}" force: "{{scm_clean}}" + track_submodules: "{{scm_track_submodules|default(omit)}}" accept_hostkey: "{{scm_accept_hostkey|default(omit)}}" register: git_result diff --git a/awx/ui_next/src/components/PromptDetail/PromptProjectDetail.jsx b/awx/ui_next/src/components/PromptDetail/PromptProjectDetail.jsx index 0ab2d6d31f..f47045aee3 100644 --- a/awx/ui_next/src/components/PromptDetail/PromptProjectDetail.jsx +++ b/awx/ui_next/src/components/PromptDetail/PromptProjectDetail.jsx @@ -18,6 +18,7 @@ function PromptProjectDetail({ i18n, resource }) { scm_branch, scm_clean, scm_delete_on_update, + scm_track_submodules, scm_refspec, scm_type, scm_update_on_launch, @@ -30,6 +31,7 @@ function PromptProjectDetail({ i18n, resource }) { if ( scm_clean || scm_delete_on_update || + scm_track_submodules || scm_update_on_launch || allow_override ) { @@ -39,6 +41,11 @@ function PromptProjectDetail({ i18n, resource }) { {scm_delete_on_update && ( {i18n._(t`Delete on Update`)} )} + {scm_track_submodules && ( + + {i18n._(t`Track submodules latest commit on branch`)} + + )} {scm_update_on_launch && ( {i18n._(t`Update Revision on Launch`)} )} diff --git a/awx/ui_next/src/components/PromptDetail/data.project.json b/awx/ui_next/src/components/PromptDetail/data.project.json index 24ed7ff1a6..371cc1d088 100644 --- a/awx/ui_next/src/components/PromptDetail/data.project.json +++ b/awx/ui_next/src/components/PromptDetail/data.project.json @@ -96,6 +96,7 @@ "scm_refspec":"refs/", "scm_clean":true, "scm_delete_on_update":true, + "scm_track_submodules":false, "credential":9, "timeout":0, "scm_revision":"", @@ -111,4 +112,4 @@ "last_update_failed":false, "last_updated":"2020-03-11T20:18:14Z", "default_environment": 1 -} \ No newline at end of file +} diff --git a/awx/ui_next/src/screens/Project/ProjectAdd/ProjectAdd.test.jsx b/awx/ui_next/src/screens/Project/ProjectAdd/ProjectAdd.test.jsx index 76bfd49256..2d7975e149 100644 --- a/awx/ui_next/src/screens/Project/ProjectAdd/ProjectAdd.test.jsx +++ b/awx/ui_next/src/screens/Project/ProjectAdd/ProjectAdd.test.jsx @@ -18,6 +18,7 @@ describe('', () => { scm_type: 'git', scm_url: 'https://foo.bar', scm_clean: true, + scm_track_submodules: false, credential: 100, local_path: '', organization: { id: 2, name: 'Bar' }, diff --git a/awx/ui_next/src/screens/Project/ProjectDetail/ProjectDetail.jsx b/awx/ui_next/src/screens/Project/ProjectDetail/ProjectDetail.jsx index f8bcd351b7..f6b1f8d3ad 100644 --- a/awx/ui_next/src/screens/Project/ProjectDetail/ProjectDetail.jsx +++ b/awx/ui_next/src/screens/Project/ProjectDetail/ProjectDetail.jsx @@ -36,6 +36,7 @@ function ProjectDetail({ project, i18n }) { scm_branch, scm_clean, scm_delete_on_update, + scm_track_submodules, scm_refspec, scm_type, scm_update_on_launch, @@ -61,6 +62,7 @@ function ProjectDetail({ project, i18n }) { if ( scm_clean || scm_delete_on_update || + scm_track_submodules || scm_update_on_launch || allow_override ) { @@ -70,6 +72,11 @@ function ProjectDetail({ project, i18n }) { {scm_delete_on_update && ( {i18n._(t`Delete on Update`)} )} + {scm_track_submodules && ( + + {i18n._(t`Track submodules latest commit on branch`)} + + )} {scm_update_on_launch && ( {i18n._(t`Update Revision on Launch`)} )} diff --git a/awx/ui_next/src/screens/Project/ProjectDetail/ProjectDetail.test.jsx b/awx/ui_next/src/screens/Project/ProjectDetail/ProjectDetail.test.jsx index 6f65e6b7f7..34ef0d6beb 100644 --- a/awx/ui_next/src/screens/Project/ProjectDetail/ProjectDetail.test.jsx +++ b/awx/ui_next/src/screens/Project/ProjectDetail/ProjectDetail.test.jsx @@ -70,6 +70,7 @@ describe('', () => { scm_refspec: 'refs/remotes/*', scm_clean: true, scm_delete_on_update: true, + scm_track_submodules: false, credential: 100, status: 'successful', organization: 10, @@ -141,6 +142,7 @@ describe('', () => { scm_type: '', scm_clean: false, scm_delete_on_update: false, + scm_track_submodules: false, scm_update_on_launch: false, allow_override: false, created: '', diff --git a/awx/ui_next/src/screens/Project/ProjectEdit/ProjectEdit.test.jsx b/awx/ui_next/src/screens/Project/ProjectEdit/ProjectEdit.test.jsx index 1a62a3f2f0..6e7b4b22f1 100644 --- a/awx/ui_next/src/screens/Project/ProjectEdit/ProjectEdit.test.jsx +++ b/awx/ui_next/src/screens/Project/ProjectEdit/ProjectEdit.test.jsx @@ -19,6 +19,7 @@ describe('', () => { scm_type: 'git', scm_url: 'https://foo.bar', scm_clean: true, + scm_track_submodules: false, credential: 100, local_path: 'bar', organization: 2, diff --git a/awx/ui_next/src/screens/Project/data.project.json b/awx/ui_next/src/screens/Project/data.project.json index 69ee22a34e..9f58e5243b 100644 --- a/awx/ui_next/src/screens/Project/data.project.json +++ b/awx/ui_next/src/screens/Project/data.project.json @@ -104,6 +104,7 @@ "scm_refspec": "", "scm_clean": false, "scm_delete_on_update": false, + "scm_track_submodules": false, "credential": null, "timeout": 0, "scm_revision": "f5de82382e756b87143f3511c7c6c006d941830d", @@ -119,4 +120,4 @@ "last_update_failed": false, "last_updated": "2019-09-30T18:06:34.713654Z", "execution_environment": 1 -} \ No newline at end of file +} diff --git a/awx/ui_next/src/screens/Project/shared/ProjectForm.jsx b/awx/ui_next/src/screens/Project/shared/ProjectForm.jsx index 9ce8aa555b..f880724469 100644 --- a/awx/ui_next/src/screens/Project/shared/ProjectForm.jsx +++ b/awx/ui_next/src/screens/Project/shared/ProjectForm.jsx @@ -84,6 +84,7 @@ function ProjectFormFields({ credential: '', scm_clean: false, scm_delete_on_update: false, + scm_track_submodules: false, scm_update_on_launch: false, allow_override: false, scm_update_cache_timeout: 0, @@ -308,6 +309,7 @@ function ProjectForm({ i18n, project, submitError, ...props }) { credential: '', scm_clean: false, scm_delete_on_update: false, + scm_track_submodules: false, scm_update_on_launch: false, allow_override: false, scm_update_cache_timeout: 0, @@ -365,6 +367,7 @@ function ProjectForm({ i18n, project, submitError, ...props }) { scm_branch: project.scm_branch || '', scm_clean: project.scm_clean || false, scm_delete_on_update: project.scm_delete_on_update || false, + scm_track_submodules: project.scm_track_submodules || false, scm_refspec: project.scm_refspec || '', scm_type: project.scm_type === '' diff --git a/awx/ui_next/src/screens/Project/shared/ProjectForm.test.jsx b/awx/ui_next/src/screens/Project/shared/ProjectForm.test.jsx index 33c528c45c..0a34bde6ea 100644 --- a/awx/ui_next/src/screens/Project/shared/ProjectForm.test.jsx +++ b/awx/ui_next/src/screens/Project/shared/ProjectForm.test.jsx @@ -17,6 +17,7 @@ describe('', () => { scm_type: 'git', scm_url: 'https://foo.bar', scm_clean: true, + scm_track_submodules: false, credential: 100, organization: 2, scm_update_on_launch: true, diff --git a/awx/ui_next/src/screens/Project/shared/ProjectSubForms/SharedFields.jsx b/awx/ui_next/src/screens/Project/shared/ProjectSubForms/SharedFields.jsx index 6fc0fb1c0e..784bed00d4 100644 --- a/awx/ui_next/src/screens/Project/shared/ProjectSubForms/SharedFields.jsx +++ b/awx/ui_next/src/screens/Project/shared/ProjectSubForms/SharedFields.jsx @@ -84,6 +84,19 @@ export const ScmTypeOptions = withI18n()( of time required to complete an update.` )} /> + Date: Mon, 12 Apr 2021 16:47:44 +0200 Subject: [PATCH 2/7] Fix merge issue Signed-off-by: mazhead --- awx/main/migrations/0136_scm_track_submodules.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/awx/main/migrations/0136_scm_track_submodules.py b/awx/main/migrations/0136_scm_track_submodules.py index 132dc63636..7a561708b1 100644 --- a/awx/main/migrations/0136_scm_track_submodules.py +++ b/awx/main/migrations/0136_scm_track_submodules.py @@ -6,11 +6,7 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ -<<<<<<< HEAD:awx/main/migrations/0136_scm_track_submodules.py ('main', '0135_schedule_sort_fallback_to_id'), -======= - ('main', '0131_undo_org_polymorphic_ee'), ->>>>>>> Update and rename 0124_scm_track_submodules.py to 0132_scm_track_submodules.py:awx/main/migrations/0132_scm_track_submodules.py ] operations = [ From f1a987793c3edd10e5b487eecec4fae52c54eaa9 Mon Sep 17 00:00:00 2001 From: mazhead Date: Mon, 12 Apr 2021 16:58:28 +0200 Subject: [PATCH 3/7] Black fix Signed-off-by: mazhead --- awx_collection/plugins/modules/tower_project.py | 1 - 1 file changed, 1 deletion(-) diff --git a/awx_collection/plugins/modules/tower_project.py b/awx_collection/plugins/modules/tower_project.py index 1cca40ffe0..f4f740897e 100644 --- a/awx_collection/plugins/modules/tower_project.py +++ b/awx_collection/plugins/modules/tower_project.py @@ -387,4 +387,3 @@ def main(): if __name__ == '__main__': main() - From 9f68ffc1cc414d5f60a9eb5d75feca36ea80b776 Mon Sep 17 00:00:00 2001 From: mazhead Date: Mon, 12 Apr 2021 18:27:16 +0200 Subject: [PATCH 4/7] Update default Signed-off-by: mazhead --- awx/main/migrations/0136_scm_track_submodules.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/awx/main/migrations/0136_scm_track_submodules.py b/awx/main/migrations/0136_scm_track_submodules.py index 7a561708b1..fcceb93cbc 100644 --- a/awx/main/migrations/0136_scm_track_submodules.py +++ b/awx/main/migrations/0136_scm_track_submodules.py @@ -13,12 +13,12 @@ class Migration(migrations.Migration): migrations.AddField( model_name='Project', name='scm_track_submodules', - field=models.BooleanField(help_text='Track submodule latest commit on specified branch.'), + field=models.BooleanField(default=False, help_text='Track submodule latest commit on specified branch.'), ), migrations.AddField( model_name='ProjectUpdate', name='scm_track_submodules', - field=models.BooleanField(help_text='Track submodule latest commit on specified branch.'), + field=models.BooleanField(default=False, help_text='Track submodule latest commit on specified branch.'), ), migrations.AlterField( model_name='project', From 5f93ba76903a91eba244d7f826e5852d1771ab59 Mon Sep 17 00:00:00 2001 From: mazhead Date: Mon, 12 Apr 2021 19:02:51 +0200 Subject: [PATCH 5/7] Update awx/ui_next/src/screens/Project/shared/ProjectSubForms/SharedFields.jsx Accept suggestion Co-authored-by: Shane McDonald --- .../src/screens/Project/shared/ProjectSubForms/SharedFields.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/ui_next/src/screens/Project/shared/ProjectSubForms/SharedFields.jsx b/awx/ui_next/src/screens/Project/shared/ProjectSubForms/SharedFields.jsx index 784bed00d4..a2e9082f4e 100644 --- a/awx/ui_next/src/screens/Project/shared/ProjectSubForms/SharedFields.jsx +++ b/awx/ui_next/src/screens/Project/shared/ProjectSubForms/SharedFields.jsx @@ -89,7 +89,7 @@ export const ScmTypeOptions = withI18n()( name="scm_track_submodules" label={i18n._(t`Track submodules`)} tooltip={i18n._( - t`if yes, submodules will track the latest commit on + t`If yes, submodules will track the latest commit on their master branch (or other branch specified in .gitmodules). If no, submodules will be kept at the revision specified by the main project. From 83d340ab1f235eee8881b2bf858f422a96b213bb Mon Sep 17 00:00:00 2001 From: mazhead Date: Tue, 13 Apr 2021 21:39:24 +0200 Subject: [PATCH 6/7] Updated migration + serializers as suggested Signed-off-by: mazhead --- awx/api/serializers.py | 2 ++ awx/main/migrations/0136_scm_track_submodules.py | 14 ++------------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 57090f7c7e..93075a5e52 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -1385,6 +1385,8 @@ class ProjectOptionsSerializer(BaseSerializer): errors['scm_branch'] = _('SCM branch cannot be used with archive projects.') if attrs.get('scm_refspec') and scm_type != 'git': errors['scm_refspec'] = _('SCM refspec can only be used with git projects.') + if attrs.get('scm_track_submodules') and scm_type != 'git': + errors['scm_track_submodules'] = _('SCM track_submodules can only be used with git projects.') if errors: raise serializers.ValidationError(errors) diff --git a/awx/main/migrations/0136_scm_track_submodules.py b/awx/main/migrations/0136_scm_track_submodules.py index fcceb93cbc..b2977906ea 100644 --- a/awx/main/migrations/0136_scm_track_submodules.py +++ b/awx/main/migrations/0136_scm_track_submodules.py @@ -1,4 +1,4 @@ -# Generated by Django 2.2.16 on 2021-02-02 14:41 +# Generated by Django 2.2.16 on 2021-04-13 19:21 from django.db import migrations, models @@ -11,21 +11,11 @@ class Migration(migrations.Migration): operations = [ migrations.AddField( - model_name='Project', - name='scm_track_submodules', - field=models.BooleanField(default=False, help_text='Track submodule latest commit on specified branch.'), - ), - migrations.AddField( - model_name='ProjectUpdate', - name='scm_track_submodules', - field=models.BooleanField(default=False, help_text='Track submodule latest commit on specified branch.'), - ), - migrations.AlterField( model_name='project', name='scm_track_submodules', field=models.BooleanField(default=False, help_text='Track submodules latest commits on defined branch.'), ), - migrations.AlterField( + migrations.AddField( model_name='projectupdate', name='scm_track_submodules', field=models.BooleanField(default=False, help_text='Track submodules latest commits on defined branch.'), From 5bb93e1f5da9cf2715235e1ff3b7c6849f49dee4 Mon Sep 17 00:00:00 2001 From: mazhead Date: Thu, 15 Apr 2021 15:23:05 +0200 Subject: [PATCH 7/7] Update SharedFields.jsx --- .../src/screens/Project/shared/ProjectSubForms/SharedFields.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/ui_next/src/screens/Project/shared/ProjectSubForms/SharedFields.jsx b/awx/ui_next/src/screens/Project/shared/ProjectSubForms/SharedFields.jsx index a2e9082f4e..8393f32fa4 100644 --- a/awx/ui_next/src/screens/Project/shared/ProjectSubForms/SharedFields.jsx +++ b/awx/ui_next/src/screens/Project/shared/ProjectSubForms/SharedFields.jsx @@ -89,7 +89,7 @@ export const ScmTypeOptions = withI18n()( name="scm_track_submodules" label={i18n._(t`Track submodules`)} tooltip={i18n._( - t`If yes, submodules will track the latest commit on + t`Submodules will track the latest commit on their master branch (or other branch specified in .gitmodules). If no, submodules will be kept at the revision specified by the main project.