Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
refactor ansible-changelog-fragment check
Browse files Browse the repository at this point in the history
* Look for add of a changelog fragment in the whole PR rather than the
  last commit.
* Also look for changes/removal of existing files and for add of a new
  plugin. Use results to mitigate the need of a changelog fragment.
  • Loading branch information
quidame committed Mar 25, 2021
1 parent 1c506fa commit 323650e
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions playbooks/ansible-changelog-fragment/run.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
---
# 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
tasks:
- name: Check for changelog fragments
args:
- 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-only --exit-code --diff-filter=MD"
register: pr_modified_files
failed_when: pr_modified_files.rc > 1

- name: Look for new plugin
command:
chdir: "{{ zuul.executor.src_root }}/{{ zuul.project.canonical_name }}"
shell: git show --name-status --exit-code --oneline --diff-filter=A | grep changelogs/fragments/
register: r
failed_when: r.rc > 1

- name: Changelog fragment failed
fail:
msg: "Your pull-request is missing a changelog fragment, please add one. It should explain to end users the reason for your change."
when: r.rc
cmd: "git diff {{ zuul.project.default-branch }} --name-only --exit-code --diff-filter=A -- plugins/"
register: pr_new_plugin
failed_when: pr_new_plugin.rc > 1

- name: Look for changelog fragment
command:
chdir: "{{ zuul.executor.src_root }}/{{ zuul.project.canonical_name }}"
cmd: "git diff {{ zuul.project.default-branch }} --name-only --exit-code --diff-filter=A -- changelogs/fragments/"
register: pr_changelog_fragment
failed_when: pr_changelog_fragment.rc > 1


- name: Assert that a new changelog fragment is present if required
assert:
that:
- pr_changelog_fragment.rc == 1 or
pr_modified_files.rc < pr_new_plugin.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."

0 comments on commit 323650e

Please sign in to comment.