-
Notifications
You must be signed in to change notification settings - Fork 1
84 lines (67 loc) · 2.45 KB
/
cleanup-pr.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
name: Cleanup PR Environment
on:
pull_request:
types: [closed]
branches: [main]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
permissions:
id-token: write
contents: read
pull-requests: write
jobs:
cleanup:
runs-on: ubuntu-latest
if: github.actor != 'dependabot[bot]'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN_DEV }}
aws-region: eu-west-2
- name: Setup AWS Profile
run: |
aws configure set region eu-west-2 --profile tvseries-dev
aws configure set aws_access_key_id ${{ env.AWS_ACCESS_KEY_ID }} --profile tvseries-dev
aws configure set aws_secret_access_key ${{ env.AWS_SECRET_ACCESS_KEY }} --profile tvseries-dev
aws configure set aws_session_token ${{ env.AWS_SESSION_TOKEN }} --profile tvseries-dev
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
run_install: false
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.node-version'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Remove PR Environment
run: pnpm sst remove --stage pr-${{ github.event.pull_request.number }}
- name: Update PR Comment
uses: actions/github-script@v7
with:
script: |
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existingComment = comments.find(comment =>
comment.user.login === 'github-actions[bot]' &&
comment.body.includes('preview environment')
);
if (existingComment) {
const previewUrl = `https://pr-${context.issue.number}.dev.tvseri.es`;
const commentBody = `## 🧹 Preview environment cleaned up!
Was hosted at ${previewUrl}`;
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: commentBody
});
}