Skip to content

🐛 Fix lint scripts to support remote config download fallback#201

Merged
openshift-merge-bot[bot] merged 2 commits intoopen-cluster-management-io:mainfrom
xuezhaojun:fix/lint-remote-config-fallback
Feb 25, 2026
Merged

🐛 Fix lint scripts to support remote config download fallback#201
openshift-merge-bot[bot] merged 2 commits intoopen-cluster-management-io:mainfrom
xuezhaojun:fix/lint-remote-config-fallback

Conversation

@xuezhaojun
Copy link
Member

@xuezhaojun xuezhaojun commented Feb 25, 2026

Summary

  • Add remote download fallback for golangci-v2.yml config in both run-lint.sh and install-golangci-lint.sh
  • When the local config file is not found alongside the scripts, the scripts now download it from the upstream sdk-go GitHub repository instead of failing
  • This fixes the error when lint scripts are used in other repos (e.g., klusterlet-addon-controller) that don't have the config file copied alongside the scripts

Problem

When other repos use the lint scripts from sdk-go, they may not have golangci-v2.yml alongside the scripts, causing:

cp: cannot stat '/go/src/github.com/stolostron/klusterlet-addon-controller/golangci-v2.yml': No such file or directory

Fix

Both scripts now follow a local-first, remote-fallback strategy:

  1. If golangci-v2.yml exists locally alongside the script → use local copy
  2. If not → download from https://raw.githubusercontent.com/open-cluster-management-io/sdk-go/main/ci/lint/golangci-v2.yml

The download failure in install-golangci-lint.sh is non-fatal (returns 0 with a warning) to avoid script exit under set -eo pipefail.

Test plan

  • Run ./ci/lint/run-lint.sh in sdk-go — should use local config (no download)
  • Copy only scripts (without golangci-v2.yml) to another repo and run — should download from GitHub
  • Run make verify in sdk-go to confirm no regressions

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Lint configuration now prefers a local config but automatically falls back to a remote config when local config is missing.
    • Improved logging to clearly indicate whether the config was copied locally or downloaded remotely.
    • Download failures no longer cause hard failures; a warning is shown with guidance for manual setup or supplying a config.

When lint scripts are used in other repos without golangci-v2.yml
alongside them, the config copy fails. Add a remote download fallback
from the sdk-go GitHub repository when the local config file is not
found.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: xuezhaojun <zxue@redhat.com>
@openshift-ci openshift-ci bot requested review from deads2k and qiujian16 February 25, 2026 07:50
@openshift-ci
Copy link

openshift-ci bot commented Feb 25, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: xuezhaojun

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai
Copy link

coderabbitai bot commented Feb 25, 2026

Walkthrough

Adds REMOTE_CONFIG_URL and updates CI lint scripts to prefer a local golangci-v2.yml but fall back to downloading it from a remote GitHub URL; download failures now emit a warning and return success instead of hard-failing.

Changes

Cohort / File(s) Summary
golangci-lint CI scripts
ci/lint/install-golangci-lint.sh, ci/lint/run-lint.sh
Introduce REMOTE_CONFIG_URL (points to GitHub open-cluster-management-io/sdk-go path). Change config provisioning to: if local golangci-v2.yml exists, copy it; otherwise download ${REMOTE_CONFIG_URL}/golangci-v2.yml. On remote download failure, print a warning/suggestion and return success (0) instead of failing. Update log messages to distinguish local vs remote sources.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding a remote config download fallback for lint scripts when local config is unavailable.
Description check ✅ Passed The description comprehensively covers the summary, problem, fix approach, and test plan; follows the template structure with summary and related issue sections.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
ci/lint/install-golangci-lint.sh (1)

24-24: Same mutable remote-ref concern applies here.

Please apply the same immutable ref pinning approach as in ci/lint/run-lint.sh.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ci/lint/install-golangci-lint.sh` at line 24, The REMOTE_CONFIG_URL currently
points to a mutable branch URL; update REMOTE_CONFIG_URL to use an immutable ref
(tag or commit hash) like you did in run-lint.sh so the script fetches a fixed
version of the remote lint config; locate the REMOTE_CONFIG_URL variable in this
file and replace the branch-based URL with the pinned raw URL that includes the
chosen tag or commit SHA.
🧹 Nitpick comments (1)
ci/lint/run-lint.sh (1)

150-151: Harden remote download with retries/timeouts and atomic write.

Direct curl -o "$CONFIG_PATH" can leave a partial config and poison cache on flaky networks.

Suggested change
-            echo "Downloading config: golangci-v2.yml"
-            curl -sSfL "${REMOTE_CONFIG_URL}/golangci-v2.yml" -o "$CONFIG_PATH"
+            echo "Downloading config: golangci-v2.yml"
+            tmp_config="$(mktemp "${CONFIG_PATH}.tmp.XXXXXX")"
+            if ! curl --retry 3 --retry-delay 2 --connect-timeout 10 --max-time 60 -sSfL \
+                "${REMOTE_CONFIG_URL}/golangci-v2.yml" -o "$tmp_config"; then
+                rm -f "$tmp_config"
+                echo "Error: failed to download ${REMOTE_CONFIG_URL}/golangci-v2.yml" >&2
+                exit 1
+            fi
+            mv "$tmp_config" "$CONFIG_PATH"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ci/lint/run-lint.sh` around lines 150 - 151, Replace the direct curl write to
CONFIG_PATH with a hardened download: use curl retry and timeout flags (e.g.
--retry, --retry-connrefused, --retry-delay, --connect-timeout, --max-time, -fS)
targeting REMOTE_CONFIG_URL/golangci-v2.yml, download to a temporary file
created via mktemp, verify curl exit status, and atomically move the temp file
into CONFIG_PATH (mv) only on success so partial downloads never overwrite the
cached config; update the echo/curl block around REMOTE_CONFIG_URL and
CONFIG_PATH accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@ci/lint/install-golangci-lint.sh`:
- Around line 239-241: The message in the download-failure branch of
copy_config() is misleading: it says "Warning:" but returns 1 which under set
-eo pipefail makes the script exit; either make the failure non-fatal or make
the message reflect a hard failure. Fix by updating copy_config() so that if you
want a non-fatal fallback it echoes a true warning and does not return non-zero
(remove or change the return 1), or if it must abort then change the message
prefix to "Error:" (and keep return 1) so the log matches the behavior; update
the echo lines that reference REMOTE_CONFIG_URL/CONFIG_FILE and LOCAL_CONFIG
accordingly and ensure callers of copy_config() (the calls at lines where
copy_config() is invoked) rely on the chosen behavior.

In `@ci/lint/run-lint.sh`:
- Line 23: Update the REMOTE_CONFIG_URL in ci/lint/run-lint.sh (variable
REMOTE_CONFIG_URL) to reference an immutable ref (commit SHA or release tag)
instead of the mutable branch "main"; also update the matching URL in
ci/lint/install-golangci-lint.sh to the same pinned tag/SHA so both scripts
fetch a deterministic config. Replace the "main" path component with the chosen
tag or SHA and verify the URL resolves before committing.

---

Duplicate comments:
In `@ci/lint/install-golangci-lint.sh`:
- Line 24: The REMOTE_CONFIG_URL currently points to a mutable branch URL;
update REMOTE_CONFIG_URL to use an immutable ref (tag or commit hash) like you
did in run-lint.sh so the script fetches a fixed version of the remote lint
config; locate the REMOTE_CONFIG_URL variable in this file and replace the
branch-based URL with the pinned raw URL that includes the chosen tag or commit
SHA.

---

Nitpick comments:
In `@ci/lint/run-lint.sh`:
- Around line 150-151: Replace the direct curl write to CONFIG_PATH with a
hardened download: use curl retry and timeout flags (e.g. --retry,
--retry-connrefused, --retry-delay, --connect-timeout, --max-time, -fS)
targeting REMOTE_CONFIG_URL/golangci-v2.yml, download to a temporary file
created via mktemp, verify curl exit status, and atomically move the temp file
into CONFIG_PATH (mv) only on success so partial downloads never overwrite the
cached config; update the echo/curl block around REMOTE_CONFIG_URL and
CONFIG_PATH accordingly.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 57fc6b2 and 240d9d6.

📒 Files selected for processing (2)
  • ci/lint/install-golangci-lint.sh
  • ci/lint/run-lint.sh


# Resolve the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REMOTE_CONFIG_URL="https://raw.githubusercontent.com/stolostron/sdk-go/main/ci/lint"
Copy link
Member

@zhujian7 zhujian7 Feb 25, 2026

Choose a reason for hiding this comment

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

I think we should avoid using stolostron?

Copy link
Member Author

@xuezhaojun xuezhaojun Feb 25, 2026

Choose a reason for hiding this comment

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

Good point! Updated. Please take another look, thanks!

- Use open-cluster-management-io/sdk-go instead of stolostron/sdk-go
  for remote config download URLs
- Change return 1 to return 0 in copy_config() so the warning is
  truly non-fatal under set -eo pipefail

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: xuezhaojun <zxue@redhat.com>
@xuezhaojun xuezhaojun requested a review from zhujian7 February 25, 2026 08:42
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
ci/lint/install-golangci-lint.sh (1)

24-24: REMOTE_CONFIG_URL is pinned to main — consider a tagged/versioned ref.

Repos that copy only the scripts (the primary use-case for this fallback) will always pull whatever golangci-v2.yml is currently on main. A breaking change to the config file will silently affect those repos the next time they run the scripts.

🔧 Optional: use a versioned ref
-REMOTE_CONFIG_URL="https://raw.githubusercontent.com/open-cluster-management-io/sdk-go/main/ci/lint"
+# Pin to a release tag so downstream repos get a stable config.
+REMOTE_CONFIG_URL="https://raw.githubusercontent.com/open-cluster-management-io/sdk-go/v0.x.y/ci/lint"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ci/lint/install-golangci-lint.sh` at line 24, REMOTE_CONFIG_URL is pinned to
the main branch; change it to use a versioned ref so downstream repos don't pick
up breaking config changes: introduce a REMOTE_CONFIG_REF (env-overridable)
defaulting to a stable tag (e.g., "v1.0.0") and set REMOTE_CONFIG_URL to
"https://raw.githubusercontent.com/open-cluster-management-io/sdk-go/${REMOTE_CONFIG_REF}/ci/lint"
(update the REMOTE_CONFIG_URL assignment and any uses of REMOTE_CONFIG_URL
accordingly) so callers can override REMOTE_CONFIG_REF if they need a different
release.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@ci/lint/install-golangci-lint.sh`:
- Around line 238-242: The curl download can create a zero-byte or partial
LOCAL_CONFIG when using -o directly; change the logic so you first download to a
temporary file (e.g., "${LOCAL_CONFIG}.tmp" or use mktemp), verify curl exits
successfully and the temp file is non-empty, then atomically move the temp file
to LOCAL_CONFIG (mv) and clean up on failure; use the existing REMOTE_CONFIG_URL
and CONFIG_FILE variables for the download target and ensure proper permissions
on the final LOCAL_CONFIG.

---

Nitpick comments:
In `@ci/lint/install-golangci-lint.sh`:
- Line 24: REMOTE_CONFIG_URL is pinned to the main branch; change it to use a
versioned ref so downstream repos don't pick up breaking config changes:
introduce a REMOTE_CONFIG_REF (env-overridable) defaulting to a stable tag
(e.g., "v1.0.0") and set REMOTE_CONFIG_URL to
"https://raw.githubusercontent.com/open-cluster-management-io/sdk-go/${REMOTE_CONFIG_REF}/ci/lint"
(update the REMOTE_CONFIG_URL assignment and any uses of REMOTE_CONFIG_URL
accordingly) so callers can override REMOTE_CONFIG_REF if they need a different
release.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 240d9d6 and 8d3e64f.

📒 Files selected for processing (2)
  • ci/lint/install-golangci-lint.sh
  • ci/lint/run-lint.sh
🚧 Files skipped from review as they are similar to previous changes (1)
  • ci/lint/run-lint.sh

@zhujian7
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Feb 25, 2026
@openshift-merge-bot openshift-merge-bot bot merged commit 284a1f4 into open-cluster-management-io:main Feb 25, 2026
13 checks passed
@xuezhaojun xuezhaojun deleted the fix/lint-remote-config-fallback branch February 25, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants