Skip to content

Commit

Permalink
fix: multine >- doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
xNok committed Jul 21, 2024
1 parent 09da11d commit 37a16b7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
tags:
- skip_ansible_lint

- name: Debug branch output
debug:
msg: "{{ branch.stdout }}"

- name: Register the git diff
ansible.builtin.command: git diff --name-only {{ default_branch }}..{{ branch.stdout }} .
ansible.builtin.command: git diff --name-only origin/{{ default_branch }}..origin/{{ branch.stdout }} .
when: branch.stdout != default_branch
register: diff
tags:
Expand All @@ -26,25 +30,24 @@

- name: Extract folders from the diff
set_fact:
changed_folders: >-
"{{ diff.stdout_lines
| map('regex_replace', '^(.*/).*$' , '\\1')
changed_folders: "{{ diff.stdout_lines
| map('regex_replace', '^(.*/).*$' , '\\1')
| unique }}"
when: branch.stdout != default_branch

- name: Filter folders within the roles directory
set_fact:
roles_with_changes: >-
"{{ changed_folders
| select('match', '^' + roles_folder + '/')
| map('regex_replace', '^' + roles_folder + '/([^/]+)/.*$', '\\1')
roles_with_changes: "{{ changed_folders
| select('match', '^' + roles_folder + '/')
| map('regex_replace', '^' + roles_folder + '/([^/]+)/.*$', '\\1')
| unique }}"
when: branch.stdout != default_branch

- name: Set all roles to run if on default branch
set_fact:
roles_with_changes: >-
"{{ lookup('fileglob', roles_folder + '/*')
| map('basename')
| list }}"
roles_with_changes: "{{ lookup('fileglob', roles_folder + '/*')
| map('basename')
| list }}"
when: branch.stdout == default_branch

- name: Debug roles_with_changes output
debug:
msg: "{{ roles_with_changes }}"
7 changes: 7 additions & 0 deletions .articles/6_ansible_pr_helper/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Speeding up Ansible Pull Request by only running affected roles

From the root folder execute

```
ansible-playbook ./.articles/6_ansible_pr_helper/pull-request-helper.yml
```
2 changes: 0 additions & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ tasks:
pip install pre-commit
pre-commit install --install-hooks
exit 0
23 changes: 10 additions & 13 deletions ansible/roles/affected_roles/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,24 @@

- name: Extract folders from the diff
set_fact:
changed_folders: >-
"{{ diff.stdout_lines
| map('regex_replace', '^(.*/).*$' , '\\1')
| unique }}"
changed_folders: "{{ diff.stdout_lines
| map('regex_replace', '^(.*/).*$' , '\\1')
| unique }}"
when: branch.stdout != default_branch

- name: Filter folders within the roles directory
set_fact:
roles_with_changes: >-
"{{ changed_folders
| select('match', '^' + roles_folder + '/')
| map('regex_replace', '^' + roles_folder + '/([^/]+)/.*$', '\\1')
| unique }}"
roles_with_changes: "{{ changed_folders
| select('match', '^' + roles_folder + '/')
| map('regex_replace', '^' + roles_folder + '/([^/]+)/.*$', '\\1')
| unique }}"
when: branch.stdout != default_branch

- name: Set all roles to run if on default branch
set_fact:
roles_with_changes: >-
"{{ lookup('fileglob', roles_folder + '/*')
| map('basename')
| list }}"
roles_with_changes: "{{ lookup('fileglob', roles_folder + '/*')
| map('basename')
| list }}"
when: branch.stdout == default_branch

- name: Debug roles_with_changes output
Expand Down

0 comments on commit 37a16b7

Please sign in to comment.