-
Notifications
You must be signed in to change notification settings - Fork 373
Expand file tree
/
Copy pathnightly-remove-stale-review-apps.yml
More file actions
54 lines (45 loc) · 1.72 KB
/
nightly-remove-stale-review-apps.yml
File metadata and controls
54 lines (45 loc) · 1.72 KB
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
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 * * *'
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
with:
token: ${{ secrets.CPLN_TOKEN_STAGING }}
org: ${{ vars.CPLN_ORG_STAGING }}
- 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"
CPLN_ORG=${{ vars.CPLN_ORG_STAGING }}
echo "🗑️ Deleting stale review app for PR #$pr: $APP_NAME"
${{ github.workspace }}/.github/actions/delete-control-plane-app/scripts/delete-app.sh
done