Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Check Stale Repos #3549

Check Stale Repos

Check Stale Repos #3549

Workflow file for this run

on:
schedule:
- cron: "0 */6 * * *" # every 6 hours
pull_request:
paths:
- 'configs/*.json'
name: Check Stale Repos
jobs:
matrix:
name: Find stale repositories
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- id: repos
name: find repositories to check
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: |
# returns a JSON array of repository objects with the following schema:
# [ {"config": "$JSON_CONFIG_FILE_PATH", "repo": "$GITHUB_REPOSITORY_FULL_NAME"} ]
repos="$(jq -nc '[inputs | .repositories[] | {"config":input_filename,"repo":.target}]' configs/*.json)"
if [[ "$GITHUB_EVENT_NAME" == 'pull_request' ]]; then
# resets the checkout to PR target commit
git fetch origin $BASE_SHA
git checkout $BASE_SHA
# returns a JSON array of repository objects as they exist on pull request target
base="$(jq -nc '[inputs | .repositories[] | {"config":input_filename,"repo":.target}]' configs/*.json)"
# returns a JSON array of repository objects as they exists on pull request head
# without the objects that also exist on pull request target
repos="$(jq -nc '$head - $base' --argjson head "$repos" --argjson base "$base")"
fi
echo "repos=$repos" >> $GITHUB_OUTPUT
- name: find deleted / archived repositories
if: steps.repos.outputs.repos != '[]'
env:
GITHUB_TOKEN: ${{ secrets.WEB3_BOT_GITHUB_TOKEN }}
REPOS: ${{ steps.repos.outputs.repos }}
run: |
status=0
while read config; do
echo "::group::$config"
while read repo; do
exists=true
output=$(curl -s -f -H "Accept: application/vnd.github.v3+json" -H "authorization: Bearer $GITHUB_TOKEN" "https://api.github.com/repos/$repo") || exists=false
if ! $exists; then
echo "Repository $repo does not exist."
status=1
continue
fi
if [[ $(echo "$output" | jq ".archived") == "true" ]]; then
echo "Repository $repo is archived."
status=1
fi
done <<< "$(jq -r '.[] | select(.config == $key) | .repo' --arg key "$config" <<< "$REPOS")"
echo "::endgroup::"
done <<< "$(jq -r 'map(.config) | unique | .[]' <<< "$REPOS")"
exit $status