-
Notifications
You must be signed in to change notification settings - Fork 250
ci: Future proof golangci-lint workflow by using dynamic base branch #3805
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
Conversation
Co-authored-by: jpayne3506 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes in both files are required.
Expected result as GITHUB_BASE_REF
is intended to solve this problem.
The name of the base ref or target branch of the pull request in a workflow run. This is only set when the event that triggers a workflow run is either pull_request or pull_request_target. For example, main.```
/azp run Azure Container Networking PR |
Azure Pipelines successfully started running 1 pipeline(s). |
Confirmed. The implementation uses
The solution now works for PRs against any branch (commit be5416e). Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
The golangci-lint workflow was hardcoded to use
--new-from-rev=origin/master
which caused failures when:Changes Made
1. Removed hardcoded base branch from
.golangci.yml
Before:
After:
2. Updated GitHub workflow to use dynamic base branch
Before:
After:
How It Works
The solution uses GitHub Actions context variables and conditional expressions:
github.base_ref
to get the target branch dynamically--new-from-rev
parameter (runs full linting)Test Scenarios
pull_request
master
--new-from-rev=origin/master
pull_request
feature/awesome-feature
--new-from-rev=origin/feature/awesome-feature
workflow_dispatch
merge_group
Benefits
✅ Future-proof: Works with any base branch without manual changes
✅ Automatic: No need to update workflow when creating feature branches
✅ Robust: Handles different event types gracefully
✅ Minimal: Only 2 lines changed across 2 files
✅ Backward compatible: Still works for existing workflows
The workflow now automatically adapts to any base branch without requiring manual changes when creating feature branches or opening PRs against them.
Fixes #3804.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
golangci-lint.run
golangci-lint config verify --config=.golangci.yml
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.