Skip to content

Nightly Remove Stale Review Apps and Images #129

Nightly Remove Stale Review Apps and Images

Nightly Remove Stale Review Apps and Images #129

name: Nightly Remove Stale Review Apps and Images
on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
env:
CPLN_ORG: ${{secrets.CPLN_ORG_STAGING}}
CPLN_TOKEN: ${{secrets.CPLN_TOKEN_STAGING}}
jobs:
remove-stale-review-apps:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Environment
uses: ./.github/actions/setup-environment
- name: Get Stale PRs
id: stale_prs
uses: actions/github-script@v7
with:
script: |
const thirtyDaysAgo = new Date();
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
const prs = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'closed',
sort: 'updated',
direction: 'desc'
});
const stalePRs = prs.data
.filter(pr => new Date(pr.updated_at) < thirtyDaysAgo)
.map(pr => pr.number);
console.log('Found stale PRs:', stalePRs);
return stalePRs;
- name: Delete Stale Review Apps
if: ${{ steps.stale_prs.outputs.result != '[]' }}
run: |
for pr in $(echo "${{ steps.stale_prs.outputs.result }}" | jq -r '.[]'); do
APP_NAME="qa-react-webpack-rails-tutorial-pr-$pr"
echo "🗑️ Deleting stale review app for PR #$pr: $APP_NAME"
${{ github.workspace }}/.github/actions/deploy-to-control-plane/scripts/delete-app.sh
done
env:
APP_NAME: qa-react-webpack-rails-tutorial-pr-${{ steps.stale_prs.outputs.result }}
- name: Run cleanup-images script
run: |
cpflow cleanup-images -a qa-react-webpack-rails-tutorial -y