Gitops repository cleanup #86
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Gitops repository cleanup | |
on: | |
schedule: | |
- cron: "0 0 * * 0" | |
workflow_dispatch: | |
jobs: | |
cleanup: | |
name: Cleanup | |
runs-on: ubuntu-latest | |
steps: | |
- name: Delete leftover repositories | |
env: | |
TOKEN: ${{ secrets.REMOVE_REPOS_TOKEN_FROM_KATKA }} | |
run: | | |
toDate=$(date +%s --date '-1 day') | |
curl -L -H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer $TOKEN" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
"https://api.github.com/orgs/redhat-hac-qe/repos?per_page=100" | jq --argjson ts "$toDate" -r '.[] | select (.created_at | fromdateiso8601 < $ts ) | select ((.description == "GitOps Repository") or (.name | match("devfile-sample-go-basic-|devfile-sample-code-with-quarkus-"))) | .name' >> repos | |
while read repo; do | |
echo "Removing ${repo} repo..." | |
curl -L -X DELETE -H "Accept: application/vnd.github+json" \ | |
-H "Authorization: Bearer $TOKEN" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
"https://api.github.com/repos/redhat-hac-qe/$repo" | |
done < repos | |