-
Notifications
You must be signed in to change notification settings - Fork 44
129 lines (115 loc) · 4.79 KB
/
Copy pathassembler-preview.yml
File metadata and controls
129 lines (115 loc) · 4.79 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
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
122
123
124
125
126
127
128
129
name: assembler-preview
on:
pull_request: ~
workflow_dispatch:
inputs:
pr_number:
description: 'Pull Request number to build the assembler preview for'
required: true
type: string
permissions:
contents: read
deployments: write
id-token: write
pull-requests: read
concurrency:
group: assembler-preview-${{ github.event.pull_request.number || inputs.pr_number }}
cancel-in-progress: true
jobs:
build:
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
runs-on: docs-internal-latest-16
env:
PR_NUMBER: ${{ github.event.pull_request.number || inputs.pr_number }}
ASSEMBLER_PREVIEW_PATH_PREFIX: ${{ github.repository }}/docs/${{ github.event.pull_request.number || inputs.pr_number }}
steps:
- name: Get PR details
if: github.event_name == 'workflow_dispatch'
id: pr-details
uses: actions/github-script@v9
env:
PR_NUMBER: ${{ inputs.pr_number }}
with:
result-encoding: string
script: |
const { owner, repo } = context.repo;
const prNumber = parseInt(process.env.PR_NUMBER, 10);
if (isNaN(prNumber) || prNumber <= 0) {
core.setFailed(`Invalid PR number: ${process.env.PR_NUMBER}`);
return;
}
try {
const { data: pr } = await github.rest.pulls.get({
owner,
repo,
pull_number: prNumber,
});
return pr.head.sha;
} catch (error) {
core.setFailed(`Failed to get PR #${prNumber}: ${error.message}`);
}
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ steps.pr-details.outputs.result || github.event.pull_request.head.sha }}
persist-credentials: false
- name: Create Deployment
uses: actions/github-script@v9
id: deployment
env:
PR_SHA: ${{ steps.pr-details.outputs.result || github.event.pull_request.head.sha }}
with:
result-encoding: string
script: |
const { owner, repo } = context.repo;
const prNumber = process.env.PR_NUMBER;
const environment = 'assembler-preview';
const task = `assembler-preview-${prNumber}`;
const deployment = await github.rest.repos.createDeployment({
owner,
repo,
environment,
task,
ref: process.env.PR_SHA,
auto_merge: false,
transient_environment: true,
required_contexts: [],
})
await github.rest.repos.createDeploymentStatus({
deployment_id: deployment.data.id,
owner,
repo,
state: "in_progress",
log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
})
return deployment.data.id
- name: Bootstrap Action Workspace
uses: elastic/docs-builder/.github/actions/bootstrap@main
- name: Build assembled documentation
run: |
yq -i ".environments.preview.path_prefix = \"${ASSEMBLER_PREVIEW_PATH_PREFIX}\"" config/assembler.yml
dotnet run --project src/tooling/docs-builder -- assemble --skip-private-repositories --environment preview
- uses: elastic/docs-builder/.github/actions/aws-auth@main
- name: Upload assembled docs to S3
id: s3-upload
env:
AWS_RETRY_MODE: standard
AWS_MAX_ATTEMPTS: 6
run: |
aws s3 sync .artifacts/assembly/${ASSEMBLER_PREVIEW_PATH_PREFIX} "s3://elastic-docs-v3-website-preview/${ASSEMBLER_PREVIEW_PATH_PREFIX}" --delete --no-follow-symlinks
aws cloudfront create-invalidation \
--distribution-id EKT7LT5PM8RKS \
--paths "/${ASSEMBLER_PREVIEW_PATH_PREFIX}" "/${ASSEMBLER_PREVIEW_PATH_PREFIX}/*"
- name: Update Deployment Status
if: always() && steps.deployment.outputs.result
uses: actions/github-script@v9
with:
script: | # zizmor: ignore[template-injection] deployment_id from prior step output
await github.rest.repos.createDeploymentStatus({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: ${{ steps.deployment.outputs.result }},
state: "${{ steps.s3-upload.outcome == 'success' && 'success' || 'failure' }}",
environment_url: `https://docs-v3-preview.elastic.dev/${process.env.ASSEMBLER_PREVIEW_PATH_PREFIX}`,
log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
})