Skip to content

Commit 2906ca4

Browse files
committed
test
1 parent 29118e1 commit 2906ca4

File tree

4 files changed

+135
-6
lines changed

4 files changed

+135
-6
lines changed

.github/workflows/pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ jobs:
4545

4646
preview:
4747
needs: build
48-
uses: ./.github/workflows/preview.yml
48+
uses: ./.github/workflows/preview-build.yml
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: preview-build
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
strict:
7+
description: 'Treat warnings as errors'
8+
type: boolean
9+
default: true
10+
continue-on-error:
11+
description: 'Do not fail to publish if build fails'
12+
type: boolean
13+
required: false
14+
default: true
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
- name: Download docs-builder binary
23+
uses: actions/download-artifact@v4
24+
if: github.repository == 'elastic/docs-builder'
25+
with:
26+
name: docs-builder-binary
27+
28+
# we run our artifact directly please use the prebuild
29+
# elastic/docs-builder@main GitHub Action for all other repositories!
30+
- name: Build documentation
31+
if: github.repository == 'elastic/docs-builder'
32+
env:
33+
PR_NUMBER: ${{ github.event.pull_request.number }}
34+
run: |
35+
chmod +x ./docs-builder
36+
./docs-builder --strict --path-prefix "/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}"
37+
38+
- name: Build documentation
39+
uses: elastic/docs-builder@main
40+
continue-on-error: true
41+
with:
42+
prefix: "/${{ github.repository }}/pull/${{ github.event.pull_request.number }}"
43+
strict: true
44+
- name: Add pull request number to build
45+
env:
46+
PR_NUMBER: ${{ github.event.pull_request.number }}
47+
PR_REF: ${{ github.event.pull_request.head.sha }}
48+
run: |
49+
echo "${PR_NUMBER}" >> .artifacts/docs/html/pull_request_number.txt
50+
echo "${PR_REF}" >> .artifacts/docs/html/pull_request_ref.txt
51+
- uses: actions/upload-artifact@v4
52+
with:
53+
name: docs
54+
path: .artifacts/docs/html/

.github/workflows/preview-cleanup.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: preview-cleanup
22

33
on:
44
workflow_call: ~
5-
pull_request_target:
5+
pull_request:
66
types: [closed]
77

88
permissions:
@@ -14,7 +14,6 @@ jobs:
1414
destroy:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v4
1817
- uses: elastic/docs-builder/.github/actions/aws-auth@main
1918
- name: Delete s3 objects
2019
env:
@@ -46,6 +45,3 @@ jobs:
4645
deployment_id: deployment.id
4746
});
4847
}
49-
50-
51-
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
name: preview-deploy
3+
4+
on:
5+
workflow_run:
6+
workflows: [preview-build]
7+
types:
8+
- completed
9+
10+
permissions:
11+
id-token: write
12+
deployments: write
13+
actions: read
14+
15+
jobs:
16+
docs-deploy:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Download docs
20+
env:
21+
GH_TOKEN: ${{ github.token }}
22+
run: |
23+
gh run download ${{ github.event.workflow_run.id }} --name docs --repo "${GITHUB_REPOSITORY}"
24+
- name: Get PR data
25+
id: pull_request
26+
run: |
27+
echo "number=$(cat pull_request_number.txt)" >> "${GITHUB_OUTPUT}"
28+
echo "ref=$(cat pull_request_ref.txt)" >> "${GITHUB_OUTPUT}"
29+
30+
31+
- name: Create Deployment
32+
uses: actions/github-script@v7
33+
id: deployment
34+
env:
35+
PR_NUMBER: ${{ steps.pull_request.outputs.number }}
36+
PR_REF: ${{ steps.pull_request.outputs.ref }}
37+
with:
38+
result-encoding: string
39+
script: |
40+
const { owner, repo } = context.repo;
41+
const deployment = await github.rest.repos.createDeployment({
42+
owner,
43+
repo,
44+
ref: process.env.PR_REF,
45+
environment: `docs-preview`,
46+
auto_merge: false,
47+
required_contexts: [],
48+
})
49+
await github.rest.repos.createDeploymentStatus({
50+
deployment_id: deployment.data.id,
51+
owner,
52+
repo,
53+
state: "in_progress",
54+
log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
55+
})
56+
return deployment.data.id
57+
58+
- uses: elastic/docs-builder/.github/actions/aws-auth@main
59+
60+
- name: Upload to S3
61+
env:
62+
PR_NUMBER: ${{ steps.pull_request.outputs.number }}
63+
run: |
64+
aws s3 sync . "s3://elastic-docs-v3-website-preview/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" --delete --exclude "pull_request_number.txt"
65+
aws cloudfront create-invalidation --distribution-id EKT7LT5PM8RKS --paths "/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}/*"
66+
67+
- name: Update deployment status
68+
uses: actions/github-script@v7
69+
if: always() && steps.deployment.outputs.result
70+
with:
71+
script: |
72+
await github.rest.repos.createDeploymentStatus({
73+
owner: context.repo.owner,
74+
repo: context.repo.repo,
75+
deployment_id: ${{ steps.deployment.outputs.result }},
76+
state: "${{ job.status == 'success' && 'success' || 'failure' }}",
77+
environment_url: `https://docs-v3-preview.elastic.dev/${context.repo.owner}/${context.repo.repo}/pull/${{ steps.pull_request.outputs.number}}`,
78+
log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
79+
})

0 commit comments

Comments
 (0)