Skip to content

Gitops repository cleanup #67

Gitops repository cleanup

Gitops repository cleanup #67

Workflow file for this run

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.GH_TOKEN }}
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