Skip to content

Commit

Permalink
Optimize preview workflows (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
reakaleek authored Feb 4, 2025
1 parent 9322e16 commit 4b7e1c4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 18 deletions.
47 changes: 34 additions & 13 deletions .github/workflows/preview-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ on:
inputs:
strict:
description: 'Treat warnings as errors'
type: boolean
default: true
type: string
default: 'true'
continue-on-error:
description: 'Do not fail to publish if build fails'
type: boolean
type: string
required: false
default: true
default: 'true'

permissions:
contents: read
Expand All @@ -23,6 +23,29 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Store PR data
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_REF: ${{ github.event.pull_request.head.sha }}
run: |
cat << EOF > pull_request.json
{
"number": ${PR_NUMBER},
"ref": "${PR_REF}"
}
EOF
- name: Upload PR data
uses: actions/upload-artifact@v4
with:
name: pull-request-data
path: pull_request.json
if-no-files-found: error
retention-days: 1
compression-level: 1

- name: Bootstrap Action Workspace
if: github.repository == 'elastic/docs-builder'
Expand All @@ -40,18 +63,16 @@ jobs:
- name: Build documentation
if: github.repository != 'elastic/docs-builder'
uses: elastic/docs-builder@main
continue-on-error: true
continue-on-error: ${{ fromJSON(inputs.continue-on-error != '' && inputs.continue-on-error || 'false') }}
with:
prefix: "/${{ github.repository }}/pull/${{ github.event.pull_request.number }}"
strict: true
- name: Add pull request number to build
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_REF: ${{ github.event.pull_request.head.sha }}
run: |
echo "${PR_NUMBER}" >> .artifacts/docs/html/pull_request_number.txt
echo "${PR_REF}" >> .artifacts/docs/html/pull_request_ref.txt
strict: ${{ fromJSON(inputs.strict != '' && inputs.strict || 'true') }}
- uses: actions/upload-artifact@v4
with:
name: docs
path: .artifacts/docs/html/
if-no-files-found: error
retention-days: 1
# The lower the compression-level, the faster the artifact will be uploaded.
# But the size of the artifact will be larger.
compression-level: 1
22 changes: 17 additions & 5 deletions .github/workflows/preview-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ jobs:
docs-deploy:
runs-on: ubuntu-latest
steps:
- name: Download docs
- name: Download PR data
env:
GH_TOKEN: ${{ github.token }}
run: |
gh run download ${{ github.event.workflow_run.id }} --name docs --repo "${GITHUB_REPOSITORY}"
gh run download ${{ github.event.workflow_run.id }} \
--repo "${GITHUB_REPOSITORY}" \
--name pull-request-data
- name: Get PR data
id: pull_request
run: |
echo "number=$(cat pull_request_number.txt)" >> "${GITHUB_OUTPUT}"
echo "ref=$(cat pull_request_ref.txt)" >> "${GITHUB_OUTPUT}"
{
echo "number=$(jq -r '.number' pull_request.json)"
echo "ref=$(jq -r '.ref' pull_request.json)"
} >> "${GITHUB_OUTPUT}"
- name: Create Deployment
uses: actions/github-script@v7
Expand Down Expand Up @@ -54,14 +58,22 @@ jobs:
log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
})
return deployment.data.id
- name: Download docs
env:
GH_TOKEN: ${{ github.token }}
run: |
gh run download ${{ github.event.workflow_run.id }} \
--repo "${GITHUB_REPOSITORY}" \
--name docs
- uses: elastic/docs-builder/.github/actions/aws-auth@main

- name: Upload to S3
env:
PR_NUMBER: ${{ steps.pull_request.outputs.number }}
run: |
aws s3 sync . "s3://elastic-docs-v3-website-preview/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" --delete --exclude "pull_request_number.txt"
aws s3 sync . "s3://elastic-docs-v3-website-preview/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" --delete --exclude "pull_request.json"
aws cloudfront create-invalidation --distribution-id EKT7LT5PM8RKS --paths "/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}/*"
- name: Update deployment status
Expand Down

0 comments on commit 4b7e1c4

Please sign in to comment.