Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix branch reuse issue in new prefix PR creation workflow #1258

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

nagutm
Copy link
Collaborator

@nagutm nagutm commented Nov 10, 2024

The GitHub Actions workflow for registering new prefixes through the issue template is reusing the same branch for each new issue, leading to the content of the second pull request overwriting the first. This was first noticed in this PR: #1240. This occurs because the workflow does not generate a unique branch for each new issue. As a result, subsequent PRs are force-pushing content to the previous PR's branch instead of creating new, independent branches for each PR.

This PR introduces the following changes to the new_prefix_pr.yml to address this issue:

  • Create a step to extract the issue number from the issue URL.
  • Dynamically generate a unique branch name (create-pull-request/patch-<issue_number>) for each new issue.
  • Modify the PR creation step to use the dynamically generated branch name, ensuring that each PR is linked to its own unique branch.

Copy link

codecov bot commented Nov 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 43.45%. Comparing base (8950e70) to head (5e8cd2c).
Report is 145 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1258      +/-   ##
==========================================
+ Coverage   42.51%   43.45%   +0.94%     
==========================================
  Files         117      118       +1     
  Lines        8327     8257      -70     
  Branches     1963     1357     -606     
==========================================
+ Hits         3540     3588      +48     
+ Misses       4582     4501      -81     
+ Partials      205      168      -37     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bgyori
Copy link
Contributor

bgyori commented Nov 10, 2024

This makes sense to me, and it seems to work via testing on a fork repository. One more thing that I think could be improved is that the update code is invoked even for issues that are not new prefix requests. For example, https://github.com/biopragmatics/bioregistry/actions/runs/11645684752/job/32428984849, which is a non-new-prefix issue runs the same update code as a new prefix issue would. Is it possible to detect early whether something is not a new prefix issue and end the workflow under that condition before attempting to run an update?

@bgyori
Copy link
Contributor

bgyori commented Nov 10, 2024

Following up on my previous comment, given that we use

on:
  issues:
    types: [opened]

as the starting point for the action, it should be possible to add a step like

      - name: Get issue details
        id: get_issue
        uses: actions/github-script@v6
        with:
          script: |
            <here we can access context.payload.issue to determine what is in the issue>

to examine the content/metadata for the issue and determine if it is relevant for a new prefix, before invoking the update code and the PR code.

@nagutm
Copy link
Collaborator Author

nagutm commented Nov 13, 2024

I've updated the workflow to check if an issue contains the required New and Prefix labels before running the main script and creating a pull request. I've tested this in my forked repository and it successfully halts the workflow before the Update step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants