Skip to content

Check for a APT Release file in the github workflow: #58

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions .github/workflows/generate-redirector-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,13 @@ jobs:
cd ..
OUT=$(diff -rq compare debs || true)
mkdir -p status
if [[ -z "${OUT}" ]]; then
# Check for at least one Release file
RELEASE_FOUND=$(find compare/dists -type f -name Release | wc -l)
if [[ "$RELEASE_FOUND" -eq 0 ]]; then
echo "no_release" >> status/${SERVER_ID}
echo "${SERVER_URL}" >> status/${SERVER_ID}
echo "STATUS=no_release" >> $GITHUB_ENV
elif [[ -z "${OUT}" ]]; then
Comment on lines +190 to +196
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

exit_status is never initialised & find can break ‑ leads to false classifications

  1. exit_status is referenced later in the same case clause, but it is never set in this job (the lftp call is followed by || true, discarding its exit code). Every server that reaches this branch will therefore evaluate [[ "${exit_status}" -eq 0 ]] as [[ -eq 0 ]] (empty → 0) and be marked not_in_sync even when the mirror is fine.
  2. find compare/dists … errors out (status = 1) when compare/dists does not exist (e.g. 404/timeout). With set -e -o pipefail (GitHub Actions default) that will abort the step.
-          RELEASE_FOUND=$(find compare/dists -type f -name Release | wc -l)
+          RELEASE_FOUND=$(find compare/dists -type f \( -name Release -o -name InRelease \) 2>/dev/null | wc -l)

And preserve the lftp exit code:

-              timeout 5m lftp -e "mirror --parallel=16; exit" https://${SERVER_URL}/dists/ || true
+              timeout 5m lftp -e "mirror --parallel=16; exit" https://${SERVER_URL}/dists/ || exit_status=$? || true

Finally guard the comparison:

-          elif [[ "${exit_status}" -eq 0 ]]; then
+          elif [[ -n "${exit_status}" && "${exit_status}" -eq 0 ]]; then

Apply the same fixes to every identical block below.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In .github/workflows/generate-redirector-config.yml around lines 190 to 196, the
variable exit_status is used without initialization because the lftp command's
exit code is discarded with || true, causing incorrect status classification.
Also, the find command can fail if the compare/dists directory does not exist,
which aborts the step due to set -e -o pipefail. To fix this, capture and
preserve the lftp exit code immediately after the command, avoid using || true,
and modify the find command to handle missing directories gracefully (e.g.,
check if the directory exists before running find or suppress errors). Apply
these changes consistently to all identical blocks in the file.

echo "true" >> status/${SERVER_ID}
echo "STATUS=true" >> $GITHUB_ENV
elif [[ "${exit_status}" -eq 0 ]]; then
Expand Down Expand Up @@ -246,7 +252,13 @@ jobs:
cd ..
OUT=$(diff -rq compare debs || true)
mkdir -p status
if [[ -z "${OUT}" ]]; then
# Check for at least one Release file
RELEASE_FOUND=$(find compare/dists -type f -name Release | wc -l)
if [[ "$RELEASE_FOUND" -eq 0 ]]; then
echo "no_release" >> status/${SERVER_ID}
echo "${SERVER_URL}" >> status/${SERVER_ID}
echo "STATUS=no_release" >> $GITHUB_ENV
elif [[ -z "${OUT}" ]]; then
echo "true" >> status/${SERVER_ID}
echo "STATUS=true" >> $GITHUB_ENV
elif [[ "${exit_status}" -eq 0 ]]; then
Expand Down Expand Up @@ -412,6 +424,8 @@ jobs:
echo "# Timeouts" >> $GITHUB_STEP_SUMMARY
grep timeout status/* | cut -d":" -f1 | xargs awk 'FNR==2{print}' >> $GITHUB_STEP_SUMMARY
#echo "$(grep timeout status/* | cut -d":" -f1 | cut -d"/" -f2 | sed ':a; N; s/\n/ /; ta') " >> $GITHUB_STEP_SUMMARY
echo "# No Release file" >> $GITHUB_STEP_SUMMARY
grep no_release status/* | cut -d":" -f1 | xargs awk 'FNR==2{print}' >> $GITHUB_STEP_SUMMARY

Comment on lines +427 to 429
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

grep … | awk pipeline will fail when there are no no_release files

If no mirror is missing a Release file grep exits 1 and, with pipefail, the whole step fails. Add a fallback:

-grep no_release status/* | cut -d":" -f1 | xargs awk 'FNR==2{print}' >> $GITHUB_STEP_SUMMARY
+grep -q no_release status/* 2>/dev/null && \
+  grep no_release status/* | cut -d":" -f1 | xargs awk 'FNR==2{print}' >> $GITHUB_STEP_SUMMARY || true

Repeat for the three other summary blocks (lines 461-463, 494-496, 528-530).

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
echo "# No Release file" >> $GITHUB_STEP_SUMMARY
grep no_release status/* | cut -d":" -f1 | xargs awk 'FNR==2{print}' >> $GITHUB_STEP_SUMMARY
echo "# No Release file" >> $GITHUB_STEP_SUMMARY
grep -q no_release status/* 2>/dev/null && \
grep no_release status/* | cut -d":" -f1 | xargs awk 'FNR==2{print}' >> $GITHUB_STEP_SUMMARY || true
🤖 Prompt for AI Agents
In .github/workflows/generate-redirector-config.yml around lines 427 to 429, the
pipeline using grep and awk fails when no files match "no_release" because grep
exits with status 1, causing the step to fail under pipefail. To fix this,
modify the command to provide a fallback that prevents failure when no matches
are found, such as appending "|| true" after the grep pipeline. Apply the same
fix to the similar summary blocks at lines 461-463, 494-496, and 528-530.

echo "failoverserver=$(grep true status/* | cut -d":" -f1 | cut -d"/" -f2 | sed ':a; N; s/\n/ /; ta') " >> $GITHUB_ENV
echo "reloadKey=$(openssl rand -hex 16)" >> $GITHUB_ENV
Expand Down Expand Up @@ -444,6 +458,9 @@ jobs:
echo "# Timeouts" >> $GITHUB_STEP_SUMMARY
grep timeout status/* | cut -d":" -f1 | xargs awk 'FNR==2{print}' >> $GITHUB_STEP_SUMMARY
#echo "$(grep timeout status/* | cut -d":" -f1 | cut -d"/" -f2 | sed ':a; N; s/\n/ /; ta') " >> $GITHUB_STEP_SUMMARY
echo "# No Release file" >> $GITHUB_STEP_SUMMARY
grep no_release status/* | cut -d":" -f1 | xargs awk 'FNR==2{print}' >> $GITHUB_STEP_SUMMARY

echo "failoverserver=$(grep true status/* | cut -d":" -f1 | cut -d"/" -f2 | sed ':a; N; s/\n/ /; ta') " >> $GITHUB_ENV
echo "reloadKey=$(openssl rand -hex 16)" >> $GITHUB_ENV
rm -rf status
Expand Down Expand Up @@ -474,6 +491,8 @@ jobs:
echo "# Timeouts" >> $GITHUB_STEP_SUMMARY
grep timeout status/* | cut -d":" -f1 | xargs awk 'FNR==2{print}' >> $GITHUB_STEP_SUMMARY
#echo "$(grep timeout status/* | cut -d":" -f1 | cut -d"/" -f2 | sed ':a; N; s/\n/ /; ta') " >> $GITHUB_STEP_SUMMARY
echo "# No Release file" >> $GITHUB_STEP_SUMMARY
grep no_release status/* | cut -d":" -f1 | xargs awk 'FNR==2{print}' >> $GITHUB_STEP_SUMMARY

echo "failoverserver=$(grep true status/* | cut -d":" -f1 | cut -d"/" -f2 | sed ':a; N; s/\n/ /; ta') " >> $GITHUB_ENV
echo "reloadKey=$(openssl rand -hex 16)" >> $GITHUB_ENV
Expand Down Expand Up @@ -506,6 +525,8 @@ jobs:
echo "# Timeouts" >> $GITHUB_STEP_SUMMARY
grep timeout status/* | cut -d":" -f1 | xargs awk 'FNR==2{print}' >> $GITHUB_STEP_SUMMARY
#echo "$(grep timeout status/* | cut -d":" -f1 | cut -d"/" -f2 | sed ':a; N; s/\n/ /; ta') " >> $GITHUB_STEP_SUMMARY
echo "# No Release file" >> $GITHUB_STEP_SUMMARY
grep no_release status/* | cut -d":" -f1 | xargs awk 'FNR==2{print}' >> $GITHUB_STEP_SUMMARY

echo "failoverserver=$(grep true status/* | cut -d":" -f1 | cut -d"/" -f2 | sed ':a; N; s/\n/ /; ta') " >> $GITHUB_ENV
echo "reloadKey=$(openssl rand -hex 16)" >> $GITHUB_ENV
Expand Down