-
Notifications
You must be signed in to change notification settings - Fork 0
Fix GitLab platform detection for self-hosted instances #8
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
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -89,9 +89,14 @@ detect_platform() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local remote_url="" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| remote_url=$(git remote get-url origin 2>/dev/null || true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ "$remote_url" == *"gitlab"* ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ "$remote_url" == *"github"* ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PLATFORM="github" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| elif [[ "$remote_url" == *"gitlab"* ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PLATFORM="gitlab" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| elif [[ -f ".gitlab-ci.yml" ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Infer GitLab from CI config presence (e.g. self-hosted GitLab) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PLATFORM="gitlab" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| elif [[ "$remote_url" == *"github"* ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| elif [[ -d ".github" ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PLATFORM="github" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PLATFORM="github" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -314,8 +319,25 @@ check_architecture_doc() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| check_ci_workflow() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ "$PLATFORM" == "gitlab" ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ -f ".gitlab-ci.yml" ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Search root file and all include:local files for harness job | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local found_harness=false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if grep -q "harness-verify\|verify-harness" ".gitlab-ci.yml"; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pass 2 "CI harness job found in .gitlab-ci.yml" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| found_harness=true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Check files referenced via include:local (supports globs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| while IFS= read -r inc_pattern; do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # shellcheck disable=SC2086 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for inc_file in $inc_pattern; do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [[ -f "$inc_file" ]] && grep -q "harness-verify\|verify-harness" "$inc_file"; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| found_harness=true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| done < <(grep -oP 'local:\s*\K\S+' ".gitlab-ci.yml" 2>/dev/null \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | sed "s/['\"]//g" || true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+336
to
+337
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| done < <(grep -oP 'local:\s*\K\S+' ".gitlab-ci.yml" 2>/dev/null \ | |
| | sed "s/['\"]//g" || true) | |
| done < <( | |
| awk ' | |
| /^[[:space:]]*local:/ { | |
| # Strip leading spaces and "local:" key | |
| sub(/^[[:space:]]*local:[[:space:]]*/, "", $0) | |
| if ($0 != "") { | |
| # Inline value or list, e.g.: | |
| # local: path.yml | |
| # local: [a.yml, b.yml] | |
| gsub(/[][,\r]/, " ") | |
| for (i = 1; i <= NF; i++) { | |
| print $i | |
| } | |
| next | |
| } | |
| in_local = 1 | |
| local_indent = match($0, /[^ ]/) - 1 | |
| next | |
| } | |
| in_local { | |
| # Stop if blank line | |
| if ($0 ~ /^[[:space:]]*$/) { | |
| in_local = 0 | |
| next | |
| } | |
| # Stop if dedented to same or lower indent | |
| cur_indent = match($0, /[^ ]/) - 1 | |
| if (cur_indent <= local_indent) { | |
| in_local = 0 | |
| next | |
| } | |
| # Handle list items like: | |
| # - a.yml | |
| if ($0 ~ /^[[:space:]]*-[[:space:]]*/) { | |
| sub(/^[[:space:]]*-[[:space:]]*/, "", $0) | |
| if ($0 != "") { | |
| print $0 | |
| } | |
| } | |
| } | |
| ' ".gitlab-ci.yml" 2>/dev/null | sed -E "s/['\"]//g" || true | |
| ) |
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.
grep -q "harness-verify\|verify-harness"relies on\|alternation in basic regex, which isn’t consistently portable across grep implementations. Consider switching togrep -Ewithharness-verify|verify-harness(or equivalent) to make the match behavior explicit and reliable.