-
Notifications
You must be signed in to change notification settings - Fork 5
53 lines (48 loc) · 1.6 KB
/
preview-cleanup.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
name: preview-cleanup
on:
workflow_call: ~
pull_request_target:
types: [closed]
permissions:
contents: none
deployments: write
id-token: write
jobs:
destroy:
runs-on: ubuntu-latest
steps:
- name: Delete GitHub environment
uses: actions/github-script@v7
id: delete-deployment
with:
script: |
const { owner, repo } = context.repo;
const deployments = await github.rest.repos.listDeployments({
owner,
repo,
environment: 'docs-preview',
ref: context.payload.pull_request.head.ref,
});
core.setOutput('is-empty', deployments.data.length === 0)
for (const deployment of deployments.data) {
await github.rest.repos.createDeploymentStatus({
owner,
repo,
deployment_id: deployment.id,
state: 'inactive',
description: 'Marking deployment as inactive'
});
await github.rest.repos.deleteDeployment({
owner,
repo,
deployment_id: deployment.id
});
}
- uses: elastic/docs-builder/.github/actions/aws-auth@main
if: steps.delete-deployment.outputs.is-empty == 'false'
- name: Delete s3 objects
if: steps.delete-deployment.outputs.is-empty == 'false'
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
aws s3 rm "s3://elastic-docs-v3-website-preview/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" --recursive