From cfc5bc26078a53666cffac79929e1fdedae64cd2 Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Fri, 17 Apr 2020 13:51:33 +0200 Subject: [PATCH] Update tobiko-deploy role Change-Id: If4e5a74dcc90b18d060c4f8bf4f0a170d881d9d1 --- roles/plugin.spec | 8 +++++ roles/tobiko-common/defaults/main.yaml | 3 ++ roles/tobiko-deploy/defaults/main.yaml | 2 ++ roles/tobiko-deploy/tasks/deploy-dir.yaml | 39 +++++++++++++---------- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/roles/plugin.spec b/roles/plugin.spec index 6b8ee4a35..f2fa2ea33 100644 --- a/roles/plugin.spec +++ b/roles/plugin.spec @@ -49,6 +49,10 @@ subparsers: type: Value help: Git version to be used for checking out test scripts ansible_variable: test_git_version + test-remote: + type: Value + help: Git remote name to be used for checking out test scripts + ansible_variable: test_git_remote test-refspec: type: Value help: Git refspect to be used for checking out test scripts @@ -69,6 +73,10 @@ subparsers: type: Value help: Git version to be used for checking out Tobiko scripts ansible_variable: tobiko_git_version + tobiko-remote: + type: Value + help: Git remote name to be used for checking out test scripts + ansible_variable: tobiko_git_remote tobiko-refspec: type: Value help: Git refspect to be used for checking out Tobiko scripts diff --git a/roles/tobiko-common/defaults/main.yaml b/roles/tobiko-common/defaults/main.yaml index 2ef73bccb..a6f5af050 100644 --- a/roles/tobiko-common/defaults/main.yaml +++ b/roles/tobiko-common/defaults/main.yaml @@ -16,9 +16,11 @@ test_project: "{{ test_git_repo | urlsplit('path') | regex_replace('^\\/|\\/$', '') | splitext | first }}" test_git_repo: '{{ git_base }}/x/tobiko.git' test_git_refspec: '' +test_git_remote: 'origin' test_git_version: 'master' test_src_dir: '' + # NOTE: if test_dir and tobiko_dir variables endup being the same actual # directory then test_src and test_git_* variables will be overriden # tobiko_src and tobiko_git_* variables @@ -28,6 +30,7 @@ tobiko_project: "{{ tobiko_git_repo | urlsplit('path') | regex_replace('^\\/|\\/$', '') | splitext | first }}" tobiko_git_repo: '{{ git_base }}/x/tobiko.git' tobiko_git_refspec: '' +tobiko_git_remote: 'origin' tobiko_git_version: 'master' tobiko_src_dir: '' diff --git a/roles/tobiko-deploy/defaults/main.yaml b/roles/tobiko-deploy/defaults/main.yaml index bcc8cc6d4..958ccfbc7 100644 --- a/roles/tobiko-deploy/defaults/main.yaml +++ b/roles/tobiko-deploy/defaults/main.yaml @@ -10,6 +10,7 @@ test_deploy_dirs: dest_dir: '{{ test_dir }}' git_repo: '{{ test_git_repo }}' git_refspec: '{{ test_git_refspec }}' + git_remote: '{{ test_git_remote }}' git_version: '{{ test_git_version }}' src_dir: '{{ test_src_dir }}' @@ -18,6 +19,7 @@ test_deploy_dirs: dest_dir: '{{ tobiko_dir }}' git_repo: '{{ tobiko_git_repo }}' git_refspec: '{{ tobiko_git_refspec }}' + git_remote: '{{ tobiko_git_remote }}' git_version: '{{ tobiko_git_version }}' src_dir: '{{ tobiko_src_dir }}' diff --git a/roles/tobiko-deploy/tasks/deploy-dir.yaml b/roles/tobiko-deploy/tasks/deploy-dir.yaml index cd91b4c03..d9f5f7041 100644 --- a/roles/tobiko-deploy/tasks/deploy-dir.yaml +++ b/roles/tobiko-deploy/tasks/deploy-dir.yaml @@ -14,13 +14,32 @@ state: absent when: - clean_dir | bool - - (src_dir | length) == 0 - name: "create directory '{{ dest_dir }}'" file: path: "{{ dest_dir | realpath }}" state: directory + register: create_dest_dir + + +- name: "override git_version and src_dir because git_refspec is '{{ git_refspec }}'" + set_fact: + git_version: 'FETCH_HEAD' + src_dir: '' + when: '(git_refspec | length) > 0' + + +- name: "checkout files from '{{ git_repo }}[{{ git_refspec or git_version }}]' to '{{ dest_dir }}'" + git: + dest: '{{ dest_dir }}' + repo: '{{ git_repo }}' + refspec: '{{ git_refspec }}' + version: '{{ git_version }}' + remote: '{{ git_remote }}' + force: yes + register: checkout_files + when: '((src_dir | length) == 0) or (create_dest_dir is changed)' - name: "copy '{{ src_dir }}' to '{{ dest_dir }}'" @@ -31,21 +50,9 @@ recursive: yes delete: "{{ clean_dir | bool }}" rsync_opts: - - "--exclude-from={{ src_dir | realpath }}/.gitignore" - register: copied_dir - when: - - (src_dir | length) > 0 - - -- name: "checkout test cases from '{{ git_repo }}[{{ git_refspec or git_version }}]' to '{{ dest_dir }}'" - git: - dest: '{{ dest_dir }}' - repo: '{{ git_repo }}' - refspec: '{{ git_refspec }}' - version: '{%if (git_refspec | length) %}FETCH_HEAD{% elif (git_version | length) %}{{ git_version }}{% else %}master{% endif %}' - force: yes - when: - - copied_dir is not defined + - '--exclude-from={{ src_dir | realpath }}/.gitignore' + register: copy_src_dir + when: '(src_dir | length) > 0' - name: "get last change details for '{{ dest_dir }}'" # noqa 303