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

Automated GitHub Action to Prevent PRs from Main Branch #6440

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/check-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Enforce PR Branch Naming

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
check-branch-name:
runs-on: ubuntu-latest
steps:
- name: Fail if PR is from 'main' branch
run: |
if [[ "${{ github.head_ref }}" == "main" ]]; then
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a security expert, but I think there may be a risk of template injection here.
github.head_ref is user-controllable input IIUC. I can't come up with something that would do harm right of the bat, but I can break the workflow by using a branch name like foo";hostname

Might be safer to have it be put in an env variable (outside of run) as to not influence script generation.

echo "❌ Pull requests must not be created from the 'main' branch."
echo "❗ Please create a new branch and submit your PR again."
exit 1
else
echo "✅ Branch name is valid."
fi
1 change: 1 addition & 0 deletions opentelemetry.io
Copy link
Member

Choose a reason for hiding this comment

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

remove this submodule

Submodule opentelemetry.io added at f67026