Sloane Hertel 2 weeks ago committed by GitHub
commit 0082b6799f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,8 @@
default_git_branch: main
repo_path: '{{ remote_tmp_dir }}/git_repositories'
git_package: git
git_daemon: git-daemon
repositories: []
shell_commands: []

@ -0,0 +1,14 @@
- name: Check is repo needs to be created
stat:
path: '{{ repo_path }}/{{ repository }}'
register: stat_repo
- name: Initialize bare git repo
shell: 'git init --bare --shared {{ repo_path }}/{{ repository }}'
when: not stat_repo.stat.exists
- name: Add repo as safe
shell: 'git config --add safe.directory .'
args:
chdir: "{{ repo_path }}/{{ repository }}"
when: not stat_repo.stat.exists

@ -0,0 +1,17 @@
- include_tasks:
file: setup.yml
when: started_daemon is undefined
- include_tasks:
file: add_repository.yml
when: "( [repo_path, repository] | path_join) is not is_dir"
loop: "{{ repositories }}"
loop_control:
loop_var: repository
- include_tasks:
file: update_repository.yml
loop_control:
loop_var: repository
loop: "{{ repositories }}"
when: "( shell_commands | length ) > 0"

@ -0,0 +1,35 @@
- include_vars:
file: "{{ ansible_facts['os_family'] }}.yml"
ignore_errors: yes
- name: Create repo path
file:
state: "{{ item }}"
path: "{{ repo_path }}"
loop:
- absent
- directory
- command: "{{ git_package }} --help"
register: found_git
ignore_errors: yes
- command: "{{ git_package }} daemon --help"
register: found_daemon
ignore_errors: yes
- name: install git
package:
name:
- "{{ git_package }}"
- "{{ git_daemon }}"
state: present
update_cache: yes
when: (found_git is failed or found_daemon is failed) and ansible_facts['os_family'] in ['RedHat', 'Debian', 'FreeBSD', 'Suse']
- name: install git (apk)
shell: "apk update && apk add {{ git_package }} {{ git_daemon }} -v -v"
when: (found_git is failed or found_daemon is failed) and ansible_facts['os_family'] == 'Alpine'
- name: start git daemon
shell: "git daemon --reuseaddr --export-all --enable=receive-pack --base-path={{ repo_path }} {{ repo_path }}&"
register: started_daemon

@ -0,0 +1,23 @@
- block:
- name: "Cloning {{ repository }}"
shell: 'git clone git://localhost/{{ repository }} {{ repository }}'
args:
chdir: '{{ remote_tmp_dir }}'
when: '( shell_commands | length ) > 0'
register: cloned_repo
- name: "Running commands in {{ repository }}"
shell: "{{ cmd }}"
args:
chdir: "{{ remote_tmp_dir }}/{{ repository }}"
loop_control:
loop_var: cmd
loop: "{{ shell_commands }}"
register: update
always:
- name: "Removing {{ repository }}"
file:
path: "{{ remote_tmp_dir }}/{{ repository }}"
state: absent
when: cloned_repo is not skipped

@ -1 +1,2 @@
shippable/posix/group1
needs/target/git-daemon

@ -1,3 +1,34 @@
- name: CHANGE-REPO-URL | setup
block:
- name: CHANGE-REPO-URL | setup | start git daemon and create repositories
include_role: name=git-daemon
vars:
label: initial
repositories:
- git-test-old.git
shell_commands:
- 'echo initial > README.md'
- 'git add README.md && git commit -m "Initial commit"'
- 'git push origin {{ git_default_branch }}'
- name: CHANGE-REPO-URL | setup | fork repo
shell: 'cp -pr git-test-old.git git-test-new.git'
args:
chdir: '{{ remote_tmp_dir }}/git_repositories'
- name: CHANGE-REPO-URL | setup | update forked repo
include_role: name=git-daemon
vars:
label: update
repositories:
- git-test-new.git
shell_commands:
- 'echo update > README.md'
- 'git add README.md && git commit -m "second commit"'
- 'echo foo > newfilename'
- 'git add newfilename && git commit -m "create newfile"'
- 'git push origin {{ git_default_branch }}'
# test change of repo url
# see https://github.com/ansible/ansible-modules-core/pull/721

@ -14,6 +14,65 @@
# Repository III for a second submodule (repo_submodule2)
# Has 1 file checked in
- name: SUBMODULES | setup
block:
- name: SUBMODULES | setup | start git daemon and create repositories
include_role: name=git-daemon
vars:
repositories:
- test_submodules_newer.git
- test_submodules_subm1.git
- test_submodules_subm2.git
shell_commands:
- 'echo initial > README.md'
- 'git add README.md && git commit -m "Initial commit"'
- 'git tag v0.1'
- 'git push origin {{ git_default_branch }} --tags'
- name: SUBMODULES | setup | add submodule1
include_role: name=git-daemon
vars:
repositories:
- test_submodules_newer.git
shell_commands:
- 'git submodule add --name submodule1 git://localhost/test_submodules_subm1.git submodule1'
- 'git submodule sync && git submodule update --init'
- 'git add . && git commit -m "Add submodule1"'
- 'git tag v0.2'
- 'git push origin {{ git_default_branch }} --tags'
- name: SUBMODULES | setup | fork submodule1
shell: 'cp -pr test_submodules_subm1.git test_submodules_subm1_newer.git'
args:
chdir: '{{ remote_tmp_dir }}/git_repositories'
- name: SUBMODULES | setup | update forked submodule1
include_role: name=git-daemon
vars:
repositories:
- test_submodules_subm1_newer.git
shell_commands:
- 'echo update > newer_commit'
- 'git add newer_commit && git commit -m "Add an update"'
- 'git tag v0.3'
- 'git push origin {{ git_default_branch }} --tags'
- name: SUBMODULES | setup | add submodule2 and update the url for submodule1
include_role: name=git-daemon
vars:
repositories:
- test_submodules_newer.git
shell_commands:
- 'git submodule add --name submodule2 git://localhost/test_submodules_subm2.git submodule2'
- 'git config -f .gitmodules submodule.submodule1.url git://localhost/test_submodules_subm1_newer.git'
- 'rm -rf submodule1'
- 'rm -rf .git/modules/submodule1'
- 'git submodule sync && git submodule update --init'
- 'cd submodule1; git checkout tags/v0.3'
- 'git add . && git commit -m "Add submodule2 and update submodule1"'
- 'git tag v0.3'
- 'git push origin {{ git_default_branch }} --tags'
- name: SUBMODULES | clear checkout_dir
file:
state: absent
@ -22,7 +81,7 @@
- name: SUBMODULES | Test that clone without recursive does not retrieve submodules
git:
repo: "{{ repo_submodules }}"
version: 45c6c07ef10fd9e453d90207e63da1ce5bd3ae1e
version: v0.2
dest: "{{ checkout_dir }}"
recursive: no
@ -44,7 +103,7 @@
git:
repo: "{{ repo_submodules }}"
dest: "{{ checkout_dir }}"
version: 45c6c07ef10fd9e453d90207e63da1ce5bd3ae1e
version: v0.2
recursive: yes
- name: SUBMODULES | List submodule1
@ -62,7 +121,7 @@
- name: SUBMODULES | Test that update without recursive does not change submodules
git:
repo: "{{ repo_submodules }}"
version: d2974e4bbccdb59368f1d5eff2205f0fa863297e
version: v0.3
dest: "{{ checkout_dir }}"
recursive: no
update: yes
@ -100,7 +159,7 @@
- name: SUBMODULES | Test that update with recursive updated existing submodules
git:
repo: "{{ repo_submodules }}"
version: d2974e4bbccdb59368f1d5eff2205f0fa863297e
version: v0.3
dest: "{{ checkout_dir }}"
update: yes
recursive: yes
@ -133,7 +192,7 @@
git:
repo: "{{ repo_submodules }}"
dest: "{{ checkout_dir }}/test.gitdir"
version: 45c6c07ef10fd9e453d90207e63da1ce5bd3ae1e
version: v0.2
recursive: yes
- name: SUBMODULES | Test that cloning submodule with .git in directory name works

@ -33,11 +33,10 @@ separate_git_dir: '{{ remote_tmp_dir }}/sep_git_dir'
repo_format1: 'https://github.com/jimi-c/test_role'
repo_format2: 'git@github.com:jimi-c/test_role.git'
repo_format3: 'ssh://git@github.com/jimi-c/test_role.git'
repo_submodules: 'https://github.com/abadger/test_submodules_newer.git'
repo_submodule1: 'https://github.com/abadger/test_submodules_subm1.git'
repo_submodule2: 'https://github.com/abadger/test_submodules_subm2.git'
repo_update_url_1: 'https://github.com/ansible-test-robinro/git-test-old'
repo_update_url_2: 'https://github.com/ansible-test-robinro/git-test-new'
repo_submodules: 'git://localhost/test_submodules_newer.git'
repo_submodule1: 'git://localhost/test_submodules_subm1.git'
repo_update_url_1: 'git://localhost/git-test-old'
repo_update_url_2: 'git://localhost/git-test-new'
known_host_files:
- "{{ lookup('env','HOME') }}/.ssh/known_hosts"
- '/etc/ssh/ssh_known_hosts'

Loading…
Cancel
Save