-
Notifications
You must be signed in to change notification settings - Fork 2
90 lines (76 loc) · 3.71 KB
/
handle-closed-prs.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: Remove PR Previews
on:
pull_request:
types: [closed]
concurrency: preview-teardown-${{ github.ref }}
jobs:
list-environments:
runs-on: ubuntu-latest
outputs:
hasNextJs14Env: ${{ steps.list-environments.outputs.hasNextJs14Env }}
hasNuxtEnv: ${{ steps.list-environments.outputs.hasNuxtEnv }}
hasVanillaJsEnv: ${{ steps.list-environments.outputs.hasVanillaJsEnv }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: List repo environments
id: list-environments
uses: actions/github-script@v6
with:
github-token: ${{ secrets.PIE_BOT_TOKEN }}
script: |
const pullRequestNumber = context.payload.pull_request.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
console.log(`Pull Request Number: ${pullRequestNumber}`);
// List environments
const { data: { environments } } = await github.rest.repos.getAllEnvironments({
owner: owner,
repo: repo,
per_page: 100,
});
const envList = environments.map(env => env.name);
console.log('Environment List:', envList);
// Check for existence of specific environments
const hasNextJs14Env = envList.includes(`nextjs-app-v14-pr-${pullRequestNumber}`);
const hasNuxtEnv = envList.includes(`nuxt-app-pr-${pullRequestNumber}`);
const hasVanillaJsEnv = envList.includes(`vanilla-app-pr-${pullRequestNumber}`);
console.log('Has NextJS 14 Env:', hasNextJs14Env);
console.log('Has Nuxt Env:', hasNuxtEnv);
console.log('Has VanillaJS Env:', hasVanillaJsEnv);
core.setOutput('hasNextJs14Env', hasNextJs14Env ? 'true' : 'false');
core.setOutput('hasNuxtEnv', hasNuxtEnv ? 'true' : 'false');
core.setOutput('hasVanillaJsEnv', hasVanillaJsEnv ? 'true' : 'false');
- name: Delete associated NextJS 14 app environment
if: ${{ steps.list-environments.outputs.hasNextJs14Env == 'true' }}
uses: ./.github/actions/amplify-teardown
with:
github-token: ${{ secrets.PIE_BOT_TOKEN }}
amplify-app-id: d1xxjuy6vbm7pk
aws-region: 'eu-west-1'
aws-access-key-id: ${{ secrets.AWS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
environment-name: nextjs-app-v14-pr-${{ github.event.pull_request.number }}
branch-name: 'pr${{ github.event.pull_request.number }}'
- name: Delete associated Nuxt app environment
if: ${{ steps.list-environments.outputs.hasNuxtEnv == 'true' }}
uses: ./.github/actions/amplify-teardown
with:
github-token: ${{ secrets.PIE_BOT_TOKEN }}
amplify-app-id: d36dan3bxjue8c
aws-region: 'eu-west-1'
aws-access-key-id: ${{ secrets.AWS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
environment-name: nuxt-app-pr-${{ github.event.pull_request.number }}
branch-name: 'pr${{ github.event.pull_request.number }}'
- name: Delete associated Vanilla app environment
if: ${{ steps.list-environments.outputs.hasVanillaJsEnv == 'true' }}
uses: ./.github/actions/amplify-teardown
with:
github-token: ${{ secrets.PIE_BOT_TOKEN }}
amplify-app-id: d2vb6sjgivffb3
aws-region: 'eu-west-1'
aws-access-key-id: ${{ secrets.AWS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
environment-name: vanilla-app-pr-${{ github.event.pull_request.number }}
branch-name: 'pr${{ github.event.pull_request.number }}'