Skip to content
Merged
6 changes: 3 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ jobs:
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Initialize CodeQL
uses: github/codeql-action/init@c10b8064de6f491fea524254123dbe5e09572f13 # v4.35.1
uses: github/codeql-action/init@68bde559dea0fdcac2102bfdf6230c5f70eb485e # v4.35.4
with:
languages: ${{ matrix.language }}

- name: Autobuild
uses: github/codeql-action/autobuild@c10b8064de6f491fea524254123dbe5e09572f13 # v4.35.1
uses: github/codeql-action/autobuild@68bde559dea0fdcac2102bfdf6230c5f70eb485e # v4.35.4

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@c10b8064de6f491fea524254123dbe5e09572f13 # v4.35.1
uses: github/codeql-action/analyze@68bde559dea0fdcac2102bfdf6230c5f70eb485e # v4.35.4
83 changes: 74 additions & 9 deletions .github/workflows/opencode-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ jobs:
local runs_json

runs_json="$(mktemp)"
if ! gh api -X GET "repos/${GH_REPOSITORY}/actions/workflows/strix.yml/runs?event=pull_request_target&per_page=30" >"$runs_json"; then
if ! gh api -X GET "repos/${GH_REPOSITORY}/actions/workflows/strix.yml/runs?per_page=100" >"$runs_json"; then
rm -f "$runs_json"
return 1
fi
Expand All @@ -1394,7 +1394,7 @@ jobs:
(.workflow_runs // [])
| map(
select((.head_sha // "") == $head_sha)
| select((.event // "") == "pull_request_target")
| select((.event // "") == "pull_request_target" or (.event // "") == "workflow_dispatch")
| select((.status // "") == "completed")
| select((.conclusion // "" | ascii_upcase) as $c | ["FAILURE","TIMED_OUT","ACTION_REQUIRED","CANCELLED","STARTUP_FAILURE"] | index($c))
| "- Strix Security Scan/strix workflow run: " + (.conclusion // "unknown") + (if (.html_url // "") != "" then " (" + .html_url + ")" else "" end)
Expand All @@ -1407,7 +1407,7 @@ jobs:
(.workflow_runs // [])
| map(
select((.head_sha // "") == $head_sha)
| select((.event // "") == "pull_request_target")
| select((.event // "") == "pull_request_target" or (.event // "") == "workflow_dispatch")
| select((.status // "") != "completed")
| "- Strix Security Scan/strix workflow run: " + (.status // "unknown") + (if (.html_url // "") != "" then " (" + .html_url + ")" else "" end)
)
Expand All @@ -1423,14 +1423,67 @@ jobs:
rm -f "$runs_json"
}

collect_current_head_strix_success_run_ids() {
local output_file="$1"

HEAD_SHA="$HEAD_SHA" gh run list \
--repo "$GH_REPOSITORY" \
--commit "$HEAD_SHA" \
--limit 100 \
--json databaseId,workflowName,status,conclusion,event,headSha \
--jq '
.[]
| select((.event // "") == "pull_request_target" or (.event // "") == "workflow_dispatch")
| select((.headSha // "") == env.HEAD_SHA)
| select((.workflowName // "") == "Strix Security Scan" or (.workflowName // "") == "Strix")
| select((.status // "") == "completed")
| select((.conclusion // "" | ascii_downcase) == "success")
| ((.databaseId // "") | tostring)
' >"$output_file"
}

filter_superseded_strix_failure_lines() {
local input_file="$1"
local output_file="$2"
local latest_success_run_id="$3"

if [ -z "$latest_success_run_id" ]; then
cat "$input_file" >"$output_file"
return 0
fi

awk -v latest_success_run_id="$latest_success_run_id" '
/Strix Security Scan/ {
line = $0
run_id = 0
if (line ~ /actions\/runs\/[0-9]+/) {
sub(/^.*actions\/runs\//, "", line)
sub(/[^0-9].*$/, "", line)
run_id = line + 0
}
if (run_id > 0 && run_id < (latest_success_run_id + 0)) {
next
}
}
{ print }
' "$input_file" >"$output_file"
}

collect_failed_github_checks() {
local output_file="$1"
local owner="${GH_REPOSITORY%%/*}"
local name="${GH_REPOSITORY#*/}"
local rollup_file
local strix_runs_file
local combined_file
local filtered_file
local strix_success_run_ids_file
local latest_strix_success_run_id
rollup_file="$(mktemp)"
strix_runs_file="$(mktemp)"
combined_file="$(mktemp)"
filtered_file="$(mktemp)"
strix_success_run_ids_file="$(mktemp)"
# shellcheck disable=SC2016
if ! gh api graphql \
-f owner="$owner" \
Expand Down Expand Up @@ -1474,31 +1527,43 @@ jobs:
| map(
if .__typename == "CheckRun" then
select((.status // "") == "COMPLETED")
| select((.name // "") != "opencode-review")
| select((.checkSuite.workflowRun.workflow.name // "") != "OpenCode PR Review")
| select((.checkSuite.workflowRun.workflow.name // "") != "OpenCode Review")
| select((.conclusion // "" | ascii_upcase) as $c | ["FAILURE","TIMED_OUT","ACTION_REQUIRED","CANCELLED","STARTUP_FAILURE"] | index($c))
| "- " + ((.checkSuite.workflowRun.workflow.name // "") + "/" + (.name // "check") | gsub("^/"; "")) + ": " + (.conclusion // "unknown") + (if (.detailsUrl // "") != "" then " (" + .detailsUrl + ")" else "" end)
elif .__typename == "StatusContext" then
select((.state // "" | ascii_upcase) as $s | ["FAILURE","ERROR"] | index($s))
select((.context // "") != "opencode-review")
| select((.context // "") != "OpenCode Review")
| select((.state // "" | ascii_upcase) as $s | ["FAILURE","ERROR"] | index($s))
| "- " + (.context // "status") + ": " + (.state // "unknown") + (if (.targetUrl // "") != "" then " (" + .targetUrl + ")" else "" end)
else
empty
end
)
| .[]
' >"$rollup_file"; then
rm -f "$rollup_file" "$strix_runs_file"
rm -f "$rollup_file" "$strix_runs_file" "$combined_file" "$filtered_file" "$strix_success_run_ids_file"
return 1
fi

if ! collect_current_head_strix_workflow_runs "$strix_runs_file" failed; then
rm -f "$rollup_file" "$strix_runs_file"
rm -f "$rollup_file" "$strix_runs_file" "$combined_file" "$filtered_file" "$strix_success_run_ids_file"
return 1
fi
if grep -Fq -- "Strix Security Scan/strix:" "$rollup_file"; then
cat "$rollup_file" >"$output_file"
cat "$rollup_file" >"$combined_file"
else
cat "$rollup_file" "$strix_runs_file" >"$output_file"
cat "$rollup_file" "$strix_runs_file" >"$combined_file"
fi
rm -f "$rollup_file" "$strix_runs_file"
if collect_current_head_strix_success_run_ids "$strix_success_run_ids_file" && [ -s "$strix_success_run_ids_file" ]; then
latest_strix_success_run_id="$(sort -n "$strix_success_run_ids_file" | tail -n 1)"
filter_superseded_strix_failure_lines "$combined_file" "$filtered_file" "$latest_strix_success_run_id"
cat "$filtered_file" >"$output_file"
else
cat "$combined_file" >"$output_file"
fi
rm -f "$rollup_file" "$strix_runs_file" "$combined_file" "$filtered_file" "$strix_success_run_ids_file"

}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ jobs:
publish_results: true

- name: Upload SARIF
uses: github/codeql-action/upload-sarif@c10b8064de6f491fea524254123dbe5e09572f13 # v4.35.1
uses: github/codeql-action/upload-sarif@68bde559dea0fdcac2102bfdf6230c5f70eb485e # v4.35.4
with:
sarif_file: results.sarif
54 changes: 52 additions & 2 deletions scripts/ci/collect_failed_check_evidence.sh
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,53 @@ owner="${GH_REPOSITORY%%/*}"
repo="${GH_REPOSITORY#*/}"
failed_contexts="$(mktemp)"
workflow_run_contexts="$(mktemp)"
tmp_files=("$failed_contexts" "$workflow_run_contexts")
strix_success_run_ids="$(mktemp)"
tmp_files=("$failed_contexts" "$workflow_run_contexts" "$strix_success_run_ids")
cleanup() {
rm -f "${tmp_files[@]}"
}
trap cleanup EXIT

collect_current_head_strix_success_run_ids() {
local output_file="$1"

HEAD_SHA="$HEAD_SHA" gh run list \
--repo "$GH_REPOSITORY" \
--commit "$HEAD_SHA" \
--limit 100 \
--json databaseId,workflowName,status,conclusion,event,headSha \
--jq '
.[]
| select((.event // "") == "pull_request_target" or (.event // "") == "workflow_dispatch")
| select((.headSha // "") == env.HEAD_SHA)
| select((.workflowName // "") == "Strix Security Scan" or (.workflowName // "") == "Strix")
| select((.status // "") == "completed")
| select((.conclusion // "" | ascii_downcase) == "success")
| ((.databaseId // "") | tostring)
' >"$output_file"
}

filter_superseded_strix_failures() {
local contexts_file="$1"
local latest_success_run_id="$2"
local filtered_contexts

if [ -z "$latest_success_run_id" ]; then
return 0
fi

filtered_contexts="$(mktemp)"
tmp_files+=("$filtered_contexts")
awk -F '\t' -v latest_success_run_id="$latest_success_run_id" '
BEGIN { OFS = FS }
$2 ~ /Strix/ && $5 ~ /^[0-9]+$/ && ($5 + 0) < (latest_success_run_id + 0) {
next
}
{ print }
' "$contexts_file" >"$filtered_contexts"
cp "$filtered_contexts" "$contexts_file"
}

# shellcheck disable=SC2016
gh api graphql \
-f owner="$owner" \
Expand Down Expand Up @@ -227,6 +268,9 @@ gh api graphql \
| map(
if .__typename == "CheckRun" then
select((.status // "") == "COMPLETED")
| select((.name // "") != "opencode-review")
| select((.checkSuite.workflowRun.workflow.name // "") != "OpenCode PR Review")
| select((.checkSuite.workflowRun.workflow.name // "") != "OpenCode Review")
| select((.conclusion // "" | ascii_upcase) as $c | ["FAILURE","TIMED_OUT","ACTION_REQUIRED","CANCELLED","STARTUP_FAILURE"] | index($c))
| [
"check_run",
Expand All @@ -237,7 +281,8 @@ gh api graphql \
((.databaseId // "") | tostring)
]
elif .__typename == "StatusContext" then
select((.state // "" | ascii_upcase) as $s | ["FAILURE","ERROR"] | index($s))
select((.context // "") != "opencode-review")
| select((.state // "" | ascii_upcase) as $s | ["FAILURE","ERROR"] | index($s))
| [
"status_context",
(.context // "status"),
Expand Down Expand Up @@ -287,6 +332,11 @@ while IFS=$'\t' read -r kind label conclusion details_url run_id check_run_id; d
printf '%s\t%s\t%s\t%s\t%s\t%s\n' "$kind" "$label" "$conclusion" "$details_url" "$run_id" "$check_run_id" >>"$failed_contexts"
done <"$workflow_run_contexts"

if collect_current_head_strix_success_run_ids "$strix_success_run_ids" && [ -s "$strix_success_run_ids" ]; then
latest_strix_success_run_id="$(sort -n "$strix_success_run_ids" | tail -n 1)"
filter_superseded_strix_failures "$failed_contexts" "$latest_strix_success_run_id"
fi

{
printf '# Failed GitHub Check Evidence\n\n'
printf -- '- PR: #%s\n' "$PR_NUMBER"
Expand Down
Loading
Loading