This repository has been archived by the owner on Jan 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move all tasks from playbook to a dedicated role
* add a 'git rebase' before 'git diff' queries
- Loading branch information
Showing
3 changed files
with
79 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,10 @@ | ||
--- | ||
# There is a new changelog fragment, OR: there is a new plugin and no changes | ||
# of existing files. Fail otherwise. | ||
|
||
- hosts: localhost | ||
gather_facts: false | ||
vars: | ||
check_changelog_fragment__git_directory: "{{ zuul.executor.src_root }}/{{ zuul.project.canonical_name }}" | ||
check_changelog_fragment__target_branch: "{{ zuul.project.default-branch }}" | ||
tasks: | ||
- name: Look for changelog fragment | ||
command: | ||
chdir: "{{ zuul.executor.src_root }}/{{ zuul.project.canonical_name }}" | ||
cmd: "git diff {{ zuul.project.default-branch }} --name-status --exit-code --diff-filter=A -- changelogs/fragments/" | ||
register: pr_changelog_fragment | ||
failed_when: pr_changelog_fragment.rc > 1 | ||
|
||
- name: Look for new plugin | ||
command: | ||
chdir: "{{ zuul.executor.src_root }}/{{ zuul.project.canonical_name }}" | ||
cmd: "git diff {{ zuul.project.default-branch }} --name-status --exit-code --diff-filter=A -- plugins/" | ||
register: pr_new_plugin | ||
failed_when: pr_new_plugin.rc > 1 | ||
|
||
- name: Look for modified and deleted files | ||
command: | ||
chdir: "{{ zuul.executor.src_root }}/{{ zuul.project.canonical_name }}" | ||
cmd: "git diff {{ zuul.project.default-branch }} --name-status --exit-code --diff-filter=MD" | ||
register: pr_modified_files | ||
failed_when: pr_modified_files.rc > 1 | ||
|
||
- name: Assert that a new changelog fragment is present if required | ||
assert: | ||
that: | ||
- pr_changelog_fragment.rc == 1 or | ||
pr_new_plugin.rc > pr_modified_files.rc | ||
success_msg: "Your pull-request contains a new {{ pr_changelog_fragment.rc | bool | ternary('changelog fragment', 'plugin') }}." | ||
fail_msg: "Your pull-request is missing a changelog fragment, please add one. It should explain to end users the reason for your change." | ||
- name: Run check_changelog_fragment role | ||
include_role: | ||
name: check_changelog_fragment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
# The root directory of the project | ||
check_changelog_fragment__git_directory: "." | ||
|
||
# The target branch of the pull-request | ||
check_changelog_fragment__target_branch: "main" | ||
|
||
# Option '--exit-code' makes 'git diff' behaves as 'diff': | ||
# - diff output is empty: rc = 0 | ||
# - diff output is not empty: rc = 1 | ||
check_changelog_fragment__git_command: "git diff {{ check_changelog_fragment__target_branch }} --name-status --exit-code" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
--- | ||
# RULES | ||
# * a pull-request needs a new changelog fragment | ||
# * unless: | ||
# * it is a "New plugin" pull-request | ||
# * unless: | ||
# * the PR modifies existing file(s) | ||
# * the PR deletes existing file(s) | ||
# * the PR renames existing file(s) | ||
|
||
|
||
# Rebasing ensures diffs are related to the PR, and only to the PR. If the task | ||
# fails, this is because of conflicts, i.e. the PR is not ready for merging (or | ||
# one of git_directory or target_branch is incorrect). | ||
- name: Rebase the PR branch on the top of the target branch | ||
command: | ||
chdir: "{{ check_changelog_fragment__git_directory }}" | ||
cmd: "git rebase {{ check_changelog_fragment__target_branch }}" | ||
register: check_changelog_fragment__rebase | ||
changed_when: check_changelog_fragment__rebase.stdout_lines | length > 1 | ||
|
||
|
||
- name: Look for a new changelog fragment | ||
command: | ||
cmd: "{{ check_changelog_fragment__git_command }} --diff-filter=A -- changelogs/fragments/" | ||
chdir: "{{ check_changelog_fragment__git_directory }}" | ||
register: check_changelog_fragment__new_fragment | ||
failed_when: check_changelog_fragment__new_fragment.rc > 1 | ||
changed_when: false | ||
|
||
|
||
- name: Look for a new plugin | ||
command: | ||
cmd: "{{ check_changelog_fragment__git_command }} --diff-filter=A -- plugins/" | ||
chdir: "{{ check_changelog_fragment__git_directory }}" | ||
register: check_changelog_fragment__new_plugin | ||
failed_when: check_changelog_fragment__new_plugin.rc > 1 | ||
changed_when: false | ||
|
||
|
||
- name: Look for changes of existing files (modified, deleted, renamed) | ||
command: | ||
cmd: "{{ check_changelog_fragment__git_command }} --diff-filter=MDR" | ||
chdir: "{{ check_changelog_fragment__git_directory }}" | ||
register: check_changelog_fragment__changed_files | ||
failed_when: check_changelog_fragment__changed_files.rc > 1 | ||
changed_when: false | ||
|
||
|
||
# There is a new changelog fragment (rc=1) OR: there is a new plugin (rc=1) AND | ||
# no changes of existing files (rc=0). | ||
- name: Assert that a new changelog fragment is present if required | ||
assert: | ||
that: | ||
- check_changelog_fragment__new_fragment.rc == 1 or | ||
check_changelog_fragment__new_plugin.rc > check_changelog_fragment__changed_files.rc | ||
success_msg: >- | ||
Your pull-request contains a new {{ 'changelog fragment' if | ||
check_changelog_fragment__new_fragment.rc | bool else 'plugin' }}. | ||
fail_msg: >- | ||
Your pull-request is missing a changelog fragment, please add one. | ||
It should explain to end users the reason for your change. |