-
Notifications
You must be signed in to change notification settings - Fork 0
fix(texlive-tags): tell a grep failure from zero matches #175
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
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 |
|---|---|---|
|
|
@@ -127,10 +127,16 @@ while IFS= read -r spec; do | |
| # からの相対パスなので、grep も repo root で走らせる | ||
| # cd の失敗は握り潰さない。空の結果は「一致している」と区別が付かず、 | ||
| # 何も見ていない監査が ok を出すことになる | ||
| # grep の失敗は 0 件と区別する。終了コードでは見分けられない: マッチが | ||
| # 無いとき grep は 1 を返すが、xargs は子が 1..125 で終わると一律 123 を | ||
| # 返すため、「一致しなかった」と「起動できなかった」が同じ値になる。 | ||
| # grep はマッチが無いだけなら標準エラーに何も書かないので、その有無で | ||
| # 判定する。捨ててしまうと、検出器が動いていない監査が ok を出す | ||
| : > "$err_file" | ||
| hits=$( | ||
| cd "$repo_dir" || exit 1 | ||
| git ls-files -z \ | ||
| | xargs -0 -r grep -EoHn "${image}:[A-Za-z0-9._-]+" 2>/dev/null \ | ||
| | xargs -0 -r grep -EoHn "${image}:[A-Za-z0-9._-]+" 2>>"$err_file" \ | ||
| | sed "s|:${image}:|:|" || true | ||
| ) | ||
|
|
||
|
|
@@ -139,13 +145,19 @@ while IFS= read -r spec; do | |
| [ -z "$pattern" ] && continue | ||
| found=$( | ||
| cd "$repo_dir" || exit 1 | ||
| git ls-files -z | xargs -0 -r grep -oHnP "$pattern" 2>/dev/null || true | ||
| git ls-files -z | xargs -0 -r grep -oHnP "$pattern" 2>>"$err_file" || true | ||
| ) | ||
| [ -n "$found" ] && hits=$(printf '%s\n%s' "$hits" "$found") | ||
| done <<EOF | ||
| $extra | ||
| EOF | ||
|
|
||
| if [ -s "$err_file" ]; then | ||
| errors=$((errors + 1)) | ||
| log " ERROR: ${name} — grep が失敗した: $(tr '\n' ' ' < "$err_file" | cut -c1-200)" | ||
|
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. ℹ️ [LOW]
Member
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. 据え置きます。 理由は、この書き方が既存の ERROR 行と揃えたものだからです。 同じスクリプトの clone 失敗が、以前から同じ形を使っています。 log " ERROR: ${name} — clone できなかった: $(tr '\n' ' ' < "$err_file")"今回の行はこれに 脅威モデルについても、実害は限定的だと考えています。
残るリスクは、追跡ファイル名に生の ANSI エスケープを含むリポジトリを監査対象に加えた場合に CI ログの表示が乱れることですが、この監査は org 内の自リポジトリを対象にしたもので、そこまでの入力を想定していません。 もし方針として制御文字を落とすなら、 |
||
| continue | ||
| fi | ||
|
|
||
| repo_drift=0 | ||
| repo_skipped=0 | ||
| while IFS= read -r hit; do | ||
|
|
||
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.
: > "$err_file"でファイルをクリアしてから、extra_patternsのループ内で2>>"$err_file"と追記しています。この設計では、ループの途中のイテレーションで grep が失敗しても、後続のイテレーションが成功すればerr_fileにはエラーが残り続けるという点は問題ありません。しかし逆に、最初のhits=の grep が失敗した場合でも、extra_patternsループが全て正常終了すればerr_fileにはエラーが書き込まれたまま残るため、正しく検出されます。ただし、より深刻な問題として、
err_fileが複数のリポジトリ間で共有されている場合、前のリポジトリの grep エラーが残っていると誤検知が起きます。: > "$err_file"のクリアはループの先頭(各リポジトリの処理開始時)に置かれているため、この点は正しく対処されています。一方で、
err_fileの定義箇所(スクリプト上部)を確認し、mktemp等で一時ファイルとして作成されているか確認してください。もし固定パスであれば、並列実行時に競合が生じます。スクリプトが並列実行される可能性がある場合はmktempによる一時ファイルの利用を推奨します。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.
確認しました。
mktempで作成されています。 固定パスではないので並列実行での競合はありません。trapによるクリーンアップも入っています。ご指摘の推奨事項は既に満たされている形です。前半で挙げていただいた 2 点についても、認識は一致しています。
hits=の grep が失敗し、後続のextra_patternsが正常終了しても、err_fileの内容は残るので検出される: > "$err_file"でクリアすることで防いでいるなお
: > "$err_file"を置いた位置には、もう 1 つ理由があります。clone が>"$err_file" 2>&1で同じファイルに書くため、clone が成功しても何か出力していた場合にそれが残ります。grep の判定を始める前にクリアしないと、clone の出力を grep の失敗と誤認します。コード変更は不要と判断しました。