From 75cdffb8b3683a52bde0d9dbdb96b2849e2f1412 Mon Sep 17 00:00:00 2001 From: Bart Piotrowski Date: Thu, 17 Sep 2026 14:01:37 +0200 Subject: [PATCH] external-data-checker: Use code search and shard apps --- .../entrypoint.sh | 68 ++++++++++++++++--- .github/workflows/external-data-checker.yml | 6 ++ 2 files changed, 65 insertions(+), 9 deletions(-) diff --git a/.github/actions/flatpak-external-data-checker/entrypoint.sh b/.github/actions/flatpak-external-data-checker/entrypoint.sh index e50700c..9dd0bb4 100755 --- a/.github/actions/flatpak-external-data-checker/entrypoint.sh +++ b/.github/actions/flatpak-external-data-checker/entrypoint.sh @@ -11,9 +11,7 @@ git config --global user.email "sysadmin@flathub.org" mkdir flathub cd flathub || exit -gh repo list flathub --visibility public -L 8000 --json url --json isArchived --jq '.[] | select(.isArchived == false)|.url' | parallel "git clone --depth 1 {}" - -echo "==> Deleting inactive repos" +echo "==> Fetching inactive repos" inactive_repos_url="https://builds.flathub.org/api/inactive-repos.txt" inactive_repos_file=$(mktemp) || exit 1 @@ -32,16 +30,68 @@ while IFS= read -r folder || [[ -n "$folder" ]]; do fi done < "$inactive_repos_file" -while IFS= read -r folder; do - if [[ -d "./$folder" ]]; then - echo "==> Deleting $folder" - rm -rf -- "./$folder" - fi +declare -A inactive_repos=() +while IFS= read -r folder || [[ -n "$folder" ]]; do + inactive_repos["$folder"]=1 done < "$inactive_repos_file" rm -f -- "$inactive_repos_file" -mapfile -t checker_apps < <( grep -rl -E 'extra-data|x-checker-data|\.AppImage' | cut -d/ -f1 | sort -u | shuf ) +declare -A candidates=() +if [[ -n "${APP_ID:-}" ]]; then + if [[ ! "$APP_ID" =~ ^[A-Za-z0-9._-]+$ || "$APP_ID" == "." || "$APP_ID" == ".." ]]; then + echo "Invalid application ID" >&2 + exit 1 + fi + candidates["$APP_ID"]=1 +else + hour=$(date -u +%H) + shard=$((10#$hour / 4)) + echo "==> Discovering apps for shard $shard/6" + for marker in extra-data x-checker-data .AppImage; do + for extension in json yaml yml; do + query="\"$marker\" org:flathub in:file extension:$extension" + page=1 + while :; do + sleep 6.1 + result=$(gh api --method GET search/code \ + -f q="$query" -F per_page=100 -F page="$page") || exit 1 + if ! jq -e '.incomplete_results == false and .total_count < 1000' \ + <<< "$result" > /dev/null; then + echo "Incomplete search or 1000-result ceiling reached: $query (page $page)" >&2 + exit 1 + fi + repos=$(jq -r '.items[].repository | select(.private == false) | .name' \ + <<< "$result") || exit 1 + while IFS= read -r repo; do + [[ -n "$repo" ]] || continue + if [[ "$marker" == extra-data ]]; then + candidates["$repo"]=1 + elif [[ -z "${candidates[$repo]:-}" ]]; then + candidates["$repo"]=0 + fi + done <<< "$repos" + total=$(jq -r '.total_count' <<< "$result") || exit 1 + ((page * 100 < total)) || break + ((page++)) + done + done + done +fi + +checker_apps=() +for repo in "${!candidates[@]}"; do + [[ -z "${inactive_repos[$repo]:-}" ]] || continue + if [[ "${candidates[$repo]}" == 0 ]]; then + checksum=$(printf '%s' "$repo" | cksum) + checksum=${checksum%% *} + ((checksum % 6 == shard)) || continue + fi + active=$(gh api "repos/flathub/$repo" --jq '.archived == false and .private == false') || exit 1 + [[ "$active" == true ]] || continue + git clone --depth 1 "https://github.com/flathub/$repo.git" || exit 1 + checker_apps+=("$repo") +done for repo in "${checker_apps[@]}"; do FEDC_OPTS=() diff --git a/.github/workflows/external-data-checker.yml b/.github/workflows/external-data-checker.yml index 614ccc1..31b1de0 100644 --- a/.github/workflows/external-data-checker.yml +++ b/.github/workflows/external-data-checker.yml @@ -4,6 +4,11 @@ on: - cron: '0 */4 * * *' workflow_dispatch: + inputs: + app_id: + description: 'Application ID to check instead of the global shard' + required: false + type: string concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -25,3 +30,4 @@ jobs: - uses: ./.github/actions/flatpak-external-data-checker env: GITHUB_TOKEN: ${{ secrets.FLATHUBBOT_TOKEN }} + APP_ID: ${{ inputs.app_id }}