Add preview workflow #39
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: preview | |
on: | |
pull_request: ~ | |
permissions: | |
id-token: write | |
pull-requests: write | |
deployments: write | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Create Deployment | |
uses: actions/github-script@v7 | |
id: deployment | |
with: | |
result-encoding: string | |
script: | | |
const deployment = await github.rest.repos.createDeployment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: context.payload.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: deployment.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 deployment.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}" | |
- uses: ./actions/aws-auth | |
- 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/${context.repo.owner}/${context.repo.repo}/pull/${context.issue.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}`, | |
}) |