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

Add CI test that fails if a PR is issued to main #1356

Merged
merged 20 commits into from
Apr 5, 2024

Conversation

maxpkatz
Copy link
Member

No description provided.

@maxpkatz maxpkatz changed the base branch from main to development October 15, 2023 22:38
@maxpkatz maxpkatz changed the base branch from development to main October 15, 2023 22:52
@maxpkatz maxpkatz changed the base branch from main to development October 15, 2023 23:03
@maxpkatz maxpkatz changed the base branch from development to main October 15, 2023 23:55
@maxpkatz maxpkatz changed the base branch from main to development October 16, 2023 00:24
@maxpkatz maxpkatz changed the base branch from development to main October 16, 2023 00:34
@maxpkatz
Copy link
Member Author

This is a little tricky. There are several ways to inspect the target branch of the PR. For example, the code below is sufficient. The problem is that if this fails (as intended) when the PR targets main, and the target branch is switched to development, re-running the action will not fix the check. The re-run will not update for the target branch changing, since an action re-run appears to be precisely a re-run of the original action, which at the time it was created was on main, so the re-run also thinks we're still on main. This would resolve itself if a new commit were added though. But we should not want to have to require a new commit just to fix this.

$ cat check_pr_branch.yml
name: check PR branch

on:
  pull_request:
    branches:
      - main

jobs:
  check-PR-branch:
    runs-on: ubuntu-latest
    steps:
      - name: PRs should not target main. Use development instead.
        run: exit 1

@maxpkatz
Copy link
Member Author

This appears to be a symptom of the fact that changing the base branch is actually not an event that triggers a workflow to run within the GitHub pull_request event API. So either we need to manually trigger some action that updates the PR, such as adding a new commit or closing and reopening the PR, or we need some more clever approach that indirectly solves this problem.

@maxpkatz maxpkatz changed the base branch from main to development October 16, 2023 02:24
@yut23 yut23 changed the base branch from development to main April 5, 2024 22:18
The `edited` activity type includes changes to the base branch, so we
need to add that to the trigger types. It also needs to run on
development as well as main, so the workflow can succeed once the base
branch is changed.
@yut23 yut23 changed the base branch from main to development April 5, 2024 22:40
@yut23 yut23 changed the base branch from development to main April 5, 2024 22:51
@yut23 yut23 changed the base branch from main to development April 5, 2024 22:53
@yut23
Copy link
Collaborator

yut23 commented Apr 5, 2024

I'm pretty sure this is working now. It turns out target branch changes fall under the edited activity type, which I suppose makes sense after the fact since you have to use the "Edit" button to do that.

@yut23 yut23 marked this pull request as ready for review April 5, 2024 23:01
@zingale zingale merged commit e5fecb7 into AMReX-Astro:development Apr 5, 2024
28 checks passed
@maxpkatz maxpkatz deleted the pr_branch_detection branch April 5, 2024 23:27
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.

3 participants