-
Notifications
You must be signed in to change notification settings - Fork 2
93 lines (83 loc) · 3.54 KB
/
preview.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
91
92
93
name: preview
on:
workflow_call: ~
permissions:
id-token: write
pull-requests: write
deployments: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Create Deployment
uses: actions/github-script@v7
id: deployment
with:
result-encoding: string
script: |
const { owner, repo } = context.repo;
const deployment = await github.rest.repos.createDeployment({
issue_number: context.issue.number,
owner,
repo,
ref: context.payload.pull_request.head.ref,
environment: `preview-${context.issue.number}`,
description: `Preview deployment for PR ${context.issue.number}`,
auto_merge: false,
required_contexts: [],
})
await github.rest.repos.createDeploymentStatus({
deployment_id: deployment.data.id,
owner,
repo,
state: "in_progress",
description: "Deployment created",
log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}?pr=${context.issue.number}`,
})
return deployment.data.id
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: docs-builder-binary
# we run our artifact directly please use the prebuild
# elastic/docs-builder@main GitHub Action for all other repositories!
- name: Build documentation
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
chmod +x ./docs-builder
./docs-builder --strict --path-prefix "/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}"
- uses: ./.github/actions/aws-auth
- name: Upload to S3
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
aws s3 sync .artifacts/docs/html "s3://elastic-docs-v3-website-preview/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" --delete
aws cloudfront create-invalidation --distribution-id EKT7LT5PM8RKS --paths "/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}/*"
- name: Update deployment status
uses: actions/github-script@v7
if: steps.deployment.outputs.result
with:
script: |
await github.rest.repos.createDeploymentStatus({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: ${{ steps.deployment.outputs.result }},
state: "success",
description: "Deployment completed",
environment_url: `https://docs-v3-preview.elastic.dev/${context.repo.owner}/${context.repo.repo}/pull/${context.issue.number}`,
log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}?pr=${context.issue.number}`,
})
- name: Update Deployment Status on Failure
if: failure() && steps.deployment.outputs.result
uses: actions/github-script@v7
with:
script: |
await github.rest.repos.createDeploymentStatus({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: ${{ steps.deployment.outputs.result }},
state: "failure",
description: "Deployment failed",
log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}?pr=${context.issue.number}`,
})