Skip to content

Commit

Permalink
feat: age out Pull Request environments (#1494)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekRoberts authored Oct 18, 2023
1 parent 7368bc0 commit b29f123
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/pr-purge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: PR Env Purge

on:
schedule: [cron: "0 13 * * *"] # 4 AM PST = 1 PM UDT
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
ageOutPRs:
name: PR Env Purge
env:
# https://tecadmin.net/getting-yesterdays-date-in-bash/
DATE: "1 week ago"
TYPE: "po,image,pvc"
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- run: |
# Login to OpenShift (NOTE: project command is a safeguard)
oc login --token=${{ secrets.OC_TOKEN }} --server=${{ vars.OC_SERVER }}
oc project ${{ vars.OC_NAMESPACE }}
oc get ${{ env.TYPE }} -o go-template --template '{{range .items}}{{.metadata.name}} {{.metadata.creationTimestamp}}{{"\n"}}{{end}}' | \
awk '$2 <= "'$(date -d '${{ env.DATE }}' -Ins --utc | sed 's/+0000/Z/')'" { print $1 }' | \
xargs --no-run-if-empty oc delete ${{ env.TYPE }}

0 comments on commit b29f123

Please sign in to comment.