-
Notifications
You must be signed in to change notification settings - Fork 2
121 lines (104 loc) · 4.41 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
name: preview
on:
pull_request: ~
permissions:
contents: read
packages: read
id-token: write
pull-requests: write
deployments: write
env:
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Create Deployment
uses: actions/github-script@v7
id: deployment
with:
result-encoding: string
script: |
const response = await github.rest.repos.createDeployment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
ref: "${{ github.event.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: response.data.id,
owner: context.repo.owner,
repo: context.repo.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 response.data.id
- uses: actions/checkout@v4
- name: Bootstrap Action Workspace
id: bootstrap
uses: ./.github/actions/bootstrap
- name: Publish AOT
run: ./build.sh publishbinaries
- name: Build documentation
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: .artifacts/publish/docs-builder/release/docs-builder --strict --path-prefix "/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}"
- name: Generate ARNs
id: generate_arns
shell: python
env:
AWS_ACCOUNT_ID: 197730964718
run: |
import hashlib
import os
prefix = "elastic-docs-v3-preview-"
aws_account_id = os.environ["AWS_ACCOUNT_ID"]
m = hashlib.sha256()
m.update(os.environ["GITHUB_REPOSITORY"].encode('utf-8'))
hash = m.hexdigest()[:64-len(prefix)]
name = f"{prefix}{hash}"
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
print(f"role_arn=arn:aws:iam::{aws_account_id}:role/{name}", file=f)
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
with:
role-to-assume: ${{ steps.generate_arns.outputs.role_arn }}
aws-region: us-east-1
- 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://d2euvt1bxklciq.cloudfront.net/${{ github.repository }}/pull/${{ github.event.pull_request.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}`,
})