-
Notifications
You must be signed in to change notification settings - Fork 70
🌱 Add a Makefile target and start running the API diff linter as part of CI #2411
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
base: main
Are you sure you want to change the base?
Changes from all commits
cf3eedf
336ef3b
965cee9
9221fe2
9b3ef7b
2c6d769
ad31ae0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| name: api-diff-lint | ||
|
|
||
| on: | ||
| pull_request: | ||
|
|
||
| jobs: | ||
| lint-api-diff: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 # Fetch all history for all branches (needed for API diff) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if this is really needed now, given that we are going to fetch baseline in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we must to have it to do the diff between main and pr branch. |
||
|
|
||
| - uses: actions/setup-go@v6 | ||
| with: | ||
| go-version-file: go.mod | ||
|
|
||
| - name: Run API diff linting checks | ||
| id: lint-api-diff | ||
| continue-on-error: true | ||
| run: make lint-api-diff | ||
|
|
||
| - name: Check for override label | ||
| if: ${{ steps.lint-api-diff.outcome == 'failure' }} | ||
| run: | | ||
| if gh api repos/$OWNER/$REPO/pulls/$PR --jq '.labels.[].name' | grep -q "${OVERRIDE_LABEL}"; then | ||
| echo "Found ${OVERRIDE_LABEL} label, overriding failed results." | ||
| exit 0 | ||
| else | ||
| echo "No ${OVERRIDE_LABEL} label found, failing the job." | ||
| exit 1 | ||
| fi | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| OWNER: ${{ github.repository_owner }} | ||
| REPO: ${{ github.event.repository.name }} | ||
| PR: ${{ github.event.pull_request.number }} | ||
| OVERRIDE_LABEL: "api-diff-lint-override" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -196,7 +196,16 @@ check_linter_support() { | |
|
|
||
| # Find golangci-lint binary | ||
| find_golangci_lint() { | ||
| # Check for custom build first | ||
| # Check if variables.env exists and extract golangci-lint path | ||
| if [[ -f ".bingo/variables.env" ]]; then | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when we could have a situation that this file does not exist?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The developer or Claude AI messed up?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so, do we need this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would keep that. |
||
| source .bingo/variables.env | ||
camilamacedo86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if [[ -n "${GOLANGCI_LINT}" && -f "${GOLANGCI_LINT}" ]]; then | ||
| echo "${GOLANGCI_LINT}" | ||
| return 0 | ||
| fi | ||
| fi | ||
|
|
||
| # Check for custom build | ||
| if [[ -f ".bingo/golangci-lint" ]]; then | ||
| echo ".bingo/golangci-lint" | ||
| return 0 | ||
|
|
@@ -216,6 +225,7 @@ find_golangci_lint() { | |
|
|
||
| echo -e "${RED}Error: golangci-lint not found.${NC}" >&2 | ||
| echo -e "${RED}Searched for:${NC}" >&2 | ||
| echo -e " - .bingo/variables.env (bingo-managed variables for GOLANGCI_LINT)" >&2 | ||
| echo -e " - .bingo/golangci-lint" >&2 | ||
| echo -e " - bin/golangci-lint" >&2 | ||
| echo -e " - golangci-lint on your \$PATH" >&2 | ||
|
|
@@ -482,6 +492,23 @@ main() { | |
| # Create temporary config | ||
| create_temp_config | ||
|
|
||
| # Ensure baseline branch is available (important for CI environments like GitHub Actions) | ||
| if ! git rev-parse --verify "${BASELINE_BRANCH}" &> /dev/null; then | ||
| echo -e "${YELLOW}Baseline branch '${BASELINE_BRANCH}' not found locally. Fetching from origin...${NC}" >&2 | ||
|
|
||
| # Fetch the baseline branch from origin | ||
| if ! git fetch origin "${BASELINE_BRANCH}:${BASELINE_BRANCH}" 2>&1; then | ||
| # If direct fetch fails, try fetching with remote tracking | ||
| if ! git fetch origin "${BASELINE_BRANCH}" 2>&1; then | ||
| echo -e "${RED}Error: Failed to fetch baseline branch '${BASELINE_BRANCH}' from origin${NC}" >&2 | ||
| echo -e "${RED}Please ensure the branch exists in the remote repository.${NC}" >&2 | ||
| exit 1 | ||
| fi | ||
| # Use the remote tracking branch | ||
| BASELINE_BRANCH="origin/${BASELINE_BRANCH}" | ||
camilamacedo86 marked this conversation as resolved.
Show resolved
Hide resolved
camilamacedo86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fi | ||
| fi | ||
|
|
||
| # Get changed files | ||
| get_changed_files > "${TEMP_DIR}/changed_files.txt" | ||
|
|
||
|
|
||
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.
this job should not execute at all if a PR contains no changes in
apifolder at all. You can usedorny/paths-filterfor that, see https://github.com/operator-framework/operator-controller/blob/main/.github/workflows/files-diff.yaml#L15Uh oh!
There was an error while loading. Please reload this page.
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.
Acknowledged. I intentionally left the step enabled unconditionally to improve CI feedback and make failures easier to catch and address while this stabilizes.
If that’s a merge blocker from your POV, I can change it (it remains runnable locally).
My preference is to keep it always-on for now since it completes in under 2 minutes and simplifies validation.
Then, after we improve it we can change things out when we have fewer issues to get solved