-
Notifications
You must be signed in to change notification settings - Fork 43
56 lines (50 loc) · 1.86 KB
/
docs-preview-cleanup-local.yml
File metadata and controls
56 lines (50 loc) · 1.86 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
55
56
name: Docs preview cleanup (local)
# Runs when a PR is closed. Pairs with docs-preview-local.yml (push/PR build).
# Inlined cleanup: GitHub deployment records + S3 preview prefix (no docs-actions call).
on:
pull_request_target:
types: [closed]
permissions:
contents: none
deployments: write
id-token: write
jobs:
destroy:
if: github.event.repository.fork == false # Skip on fork repo; upstream PRs still run here.
runs-on: ubuntu-latest
steps:
- name: Delete GitHub environment
uses: actions/github-script@v9
id: delete-deployment
with:
script: |
const { owner, repo } = context.repo;
const deployments = await github.rest.repos.listDeployments({
owner,
repo,
environment: 'docs-preview',
task: `docs-preview-${context.issue.number}`,
});
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