-
Notifications
You must be signed in to change notification settings - Fork 384
60 lines (49 loc) · 1.88 KB
/
nightly-remove-stale-review-apps.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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