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

look for add of a changelog fragment in the whole PR rather than the last commit #772

Conversation

quidame
Copy link
Contributor

@quidame quidame commented Mar 21, 2021

Fixes #771

RATIONALE

The current ansible-changelog-fragment check leads to many false positives:

  • When a new commit is added and is not squashed with the one adding the changelog fragment.
  • When the pull-request contains a new plugin (module, filter, lookup...) and no changes of existing files.

This PR is a refactor of the whole check to look for add of a changelog fragment in the entire PR rather that just the last commit, and to not fail when a changelog fragment is not required.

@quidame quidame force-pushed the fix/check_ansible-changelog-fragment_against_whole_pr branch 3 times, most recently from 323650e to 7e5fb52 Compare March 27, 2021 18:25
@quidame
Copy link
Contributor Author

quidame commented Apr 13, 2021

@pabelanger could you take a look, please ?

@Akasurde
Copy link
Member

@justjais @goneri @pabelanger Change looks good to me. Can you please review and merge? Thanks in advance.

@goneri
Copy link
Collaborator

goneri commented Apr 14, 2021

Thank you @quidame for the change. May I ask you to move the logic in a new role. e.g ensure_changelog_fragment and ensure we don't use any zuul variables in the role.

include_role:
    name: ensure_changelog_fragment
vars:
   ensure_changelog_fragment_dir: "{{ zuul.executor.src_root }}/{{ zuul.project.canonical_name }}"
   ensure_changelog_fragment_default_branch: "{{ zuul.project.default-branch }}" 

This way it will be way easier to test any future change and maybe, integrate that in the CI.

* 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.
@quidame quidame force-pushed the fix/check_ansible-changelog-fragment_against_whole_pr branch from 7e5fb52 to 97cddcd Compare April 15, 2021 16:35
Copy link
Collaborator

@goneri goneri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I use the main branch, I still get the "Your pull-request is missing a changelog fragment, please add one. It should explain to end users the reason for your change." error.

We should not have any error in this case IMO.

* add a 'git rebase' before 'git diff' queries
@quidame quidame force-pushed the fix/check_ansible-changelog-fragment_against_whole_pr branch from 97cddcd to e1ec70a Compare April 15, 2021 17:14
@quidame
Copy link
Contributor Author

quidame commented Apr 15, 2021

If I use the main branch, I still get the "Your pull-request is missing a changelog fragment, please add one. It should explain to end users the reason for your change." error.

Where ?

@goneri
Copy link
Collaborator

goneri commented Apr 15, 2021

If I use the main branch, I still get the "Your pull-request is missing a changelog fragment, please add one. It should explain to end users the reason for your change." error.

Whe1re ?

I did this:

  tasks:
    - include_role:
        name: check_changelog_fragment
      vars:
        check_changelog_fragment__git_directory: /home/goneri/.ansible/collections/ansible_collections/amazon/aws

/home/goneri/.ansible/collections/ansible_collections/amazon/aws is an up to date git clone of amazon.aws and it's on the main branch.


- 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."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the url is not expected to change for a couple of years, yes, I agree

- name: Check for changelog fragments
args:
chdir: "{{ zuul.executor.src_root }}/{{ zuul.project.canonical_name }}"
shell: git show --name-status --exit-code --oneline --diff-filter=A | grep changelogs/fragments/
Copy link
Contributor

@pabelanger pabelanger Apr 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a pretty large refactor, I think you could just change this too

git show HEAD...origin/{{ zuul.branch }} --name-status --exit-code --oneline --diff-filter=A | grep changelogs/fragments/

And it will work as expected

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not cover this:

You do not have to add a changelog fragment for PRs that add new modules and plugins, because our tooling does that for you automatically.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is fine for now, the original purpose of this check was to enforce each commit to specific folders had the fragment. There shouldn't be harm for a user adding it in the same commit as a new module.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, a commit that only changes tests/ should not require a changelog fragment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, a commit that only changes tests/ should not require a changelog fragment.

That is managed via https://github.com/ansible/project-config/blob/master/zuul.d/jobs.yaml#L76 if a project doesn't want them on tests, I would say create a new job, and parent to ansible-changelog-fragment updating the file matcher. In the case of network collections, changelogs for tests are still fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There shouldn't be harm for a user adding it in the same commit as a new module.

You're right, and in fact there is no harm for a user adding it in the same commit as a new module. But there shouldn't be harm for a user NOT adding it in the same PR/commit as a new module.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my feelings here are, that could be an optimization we make in a follow up patch. Even have a discussion on how we want to enhance this job. Your original issue was 'don't only check the last commit', which I think we can land now and test.

@quidame
Copy link
Contributor Author

quidame commented Apr 15, 2021

@goneri I don't understand your testcase. Do you play check_changelog_fragment against a repo where there is nothing to compare (main vs. main) ? What I understand is that the playbook fails because there is no changelog fragment, that is expected. The only reason why it would not complain about that is to have a new file in plugins directory... and 2 branches to get some diff between them.

@goneri
Copy link
Collaborator

goneri commented Apr 15, 2021

@goneri I don't understand your testcase. Do you play check_changelog_fragment against a repo where there is nothing to compare (main vs. main) ? What I understand is that the playbook fails because there is no changelog fragment, that is expected. The only reason why it would not complain about that is to have a new file in plugins directory... and 2 branches to get some diff between them.

In my opinion, since their is no different between the two branches, we should just ignore the test. Sometime we run our tests again the main branches, e.g with periodical jobs. And in this case a role like this one should not raise an error.

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' }}.
Copy link
Collaborator

@goneri goneri Apr 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also get the message when there is no difference between the two branches, but I'm fine with that at this stage.

Copy link
Collaborator

@goneri goneri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thank you @quidame.

@goneri goneri requested a review from pabelanger April 15, 2021 19:56
@goneri goneri added the gate Gate PR in Zuul CI label Apr 15, 2021
@ansible-zuul ansible-zuul bot merged commit 1a7a95c into ansible:master Apr 15, 2021
@quidame
Copy link
Contributor Author

quidame commented Apr 15, 2021

@pabelanger @goneri thanks for reviewing !

@quidame quidame deleted the fix/check_ansible-changelog-fragment_against_whole_pr branch April 15, 2021 20:28
@goneri
Copy link
Collaborator

goneri commented Apr 15, 2021

@pabelanger @goneri thanks for reviewing !

You're welcome. Merci pour ta patience :-)

@pabelanger
Copy link
Contributor

@quidame @goneri: given we cannot test this before merge, we should not modify this job. We should create a 2nd job, to iterate on, then merge it.

Because this run on the executor, we need to take special care about the git repos

@pabelanger
Copy link
Contributor

@goneri
Copy link
Collaborator

goneri commented Apr 15, 2021

Give me a sec, I push a revert PR.

@goneri
Copy link
Collaborator

goneri commented Apr 15, 2021

This PR reverts the change on the run.yaml and provides a new job that consume the new role: #801

# * the PR renames existing file(s)


# Rebasing ensures diffs are related to the PR, and only to the PR. If the task
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I finally had some time to look at this, there isn't a need to rebase here. We have dedicated zuul-mergers that run merge operations, if the merge fails the job won't run. So, lets delete this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, ok, that's fine, I'll remove it

changed_when: check_changelog_fragment__rebase.stdout_lines | length > 1


- name: Look for any diff between current and target branches
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should always be a diff right? As the PR running will have a new commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, there should be a diff, except in the use case explained above by @goneri (playing the role in scheduled jobs against the default branch itself, so with an empty diff)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
gate Gate PR in Zuul CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ansible-changelog-fragment check doesn't refer to the PR content, or its error message is unclear
4 participants