Skip to content

Commit 4b7e1c4

Browse files
authored
Optimize preview workflows (#407)
1 parent 9322e16 commit 4b7e1c4

File tree

2 files changed

+51
-18
lines changed

2 files changed

+51
-18
lines changed

.github/workflows/preview-build.yml

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ on:
66
inputs:
77
strict:
88
description: 'Treat warnings as errors'
9-
type: boolean
10-
default: true
9+
type: string
10+
default: 'true'
1111
continue-on-error:
1212
description: 'Do not fail to publish if build fails'
13-
type: boolean
13+
type: string
1414
required: false
15-
default: true
15+
default: 'true'
1616

1717
permissions:
1818
contents: read
@@ -23,6 +23,29 @@ jobs:
2323
steps:
2424
- name: Checkout
2525
uses: actions/checkout@v4
26+
with:
27+
persist-credentials: false
28+
29+
- name: Store PR data
30+
env:
31+
PR_NUMBER: ${{ github.event.pull_request.number }}
32+
PR_REF: ${{ github.event.pull_request.head.sha }}
33+
run: |
34+
cat << EOF > pull_request.json
35+
{
36+
"number": ${PR_NUMBER},
37+
"ref": "${PR_REF}"
38+
}
39+
EOF
40+
41+
- name: Upload PR data
42+
uses: actions/upload-artifact@v4
43+
with:
44+
name: pull-request-data
45+
path: pull_request.json
46+
if-no-files-found: error
47+
retention-days: 1
48+
compression-level: 1
2649

2750
- name: Bootstrap Action Workspace
2851
if: github.repository == 'elastic/docs-builder'
@@ -40,18 +63,16 @@ jobs:
4063
- name: Build documentation
4164
if: github.repository != 'elastic/docs-builder'
4265
uses: elastic/docs-builder@main
43-
continue-on-error: true
66+
continue-on-error: ${{ fromJSON(inputs.continue-on-error != '' && inputs.continue-on-error || 'false') }}
4467
with:
4568
prefix: "/${{ github.repository }}/pull/${{ github.event.pull_request.number }}"
46-
strict: true
47-
- name: Add pull request number to build
48-
env:
49-
PR_NUMBER: ${{ github.event.pull_request.number }}
50-
PR_REF: ${{ github.event.pull_request.head.sha }}
51-
run: |
52-
echo "${PR_NUMBER}" >> .artifacts/docs/html/pull_request_number.txt
53-
echo "${PR_REF}" >> .artifacts/docs/html/pull_request_ref.txt
69+
strict: ${{ fromJSON(inputs.strict != '' && inputs.strict || 'true') }}
5470
- uses: actions/upload-artifact@v4
5571
with:
5672
name: docs
5773
path: .artifacts/docs/html/
74+
if-no-files-found: error
75+
retention-days: 1
76+
# The lower the compression-level, the faster the artifact will be uploaded.
77+
# But the size of the artifact will be larger.
78+
compression-level: 1

.github/workflows/preview-deploy.yml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,20 @@ jobs:
1717
docs-deploy:
1818
runs-on: ubuntu-latest
1919
steps:
20-
- name: Download docs
20+
- name: Download PR data
2121
env:
2222
GH_TOKEN: ${{ github.token }}
2323
run: |
24-
gh run download ${{ github.event.workflow_run.id }} --name docs --repo "${GITHUB_REPOSITORY}"
24+
gh run download ${{ github.event.workflow_run.id }} \
25+
--repo "${GITHUB_REPOSITORY}" \
26+
--name pull-request-data
2527
- name: Get PR data
2628
id: pull_request
2729
run: |
28-
echo "number=$(cat pull_request_number.txt)" >> "${GITHUB_OUTPUT}"
29-
echo "ref=$(cat pull_request_ref.txt)" >> "${GITHUB_OUTPUT}"
30+
{
31+
echo "number=$(jq -r '.number' pull_request.json)"
32+
echo "ref=$(jq -r '.ref' pull_request.json)"
33+
} >> "${GITHUB_OUTPUT}"
3034
3135
- name: Create Deployment
3236
uses: actions/github-script@v7
@@ -54,14 +58,22 @@ jobs:
5458
log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
5559
})
5660
return deployment.data.id
61+
62+
- name: Download docs
63+
env:
64+
GH_TOKEN: ${{ github.token }}
65+
run: |
66+
gh run download ${{ github.event.workflow_run.id }} \
67+
--repo "${GITHUB_REPOSITORY}" \
68+
--name docs
5769
5870
- uses: elastic/docs-builder/.github/actions/aws-auth@main
5971

6072
- name: Upload to S3
6173
env:
6274
PR_NUMBER: ${{ steps.pull_request.outputs.number }}
6375
run: |
64-
aws s3 sync . "s3://elastic-docs-v3-website-preview/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" --delete --exclude "pull_request_number.txt"
76+
aws s3 sync . "s3://elastic-docs-v3-website-preview/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" --delete --exclude "pull_request.json"
6577
aws cloudfront create-invalidation --distribution-id EKT7LT5PM8RKS --paths "/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}/*"
6678
6779
- name: Update deployment status

0 commit comments

Comments
 (0)