|
| 1 | +name: preview |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: ~ |
| 5 | + |
| 6 | +permissions: |
| 7 | + id-token: write |
| 8 | + pull-requests: write |
| 9 | + deployments: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + deploy: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Create Deployment |
| 16 | + uses: actions/github-script@v7 |
| 17 | + id: deployment |
| 18 | + with: |
| 19 | + result-encoding: string |
| 20 | + script: | |
| 21 | + const { owner, repo } = context.repo; |
| 22 | + const deployment = await github.rest.repos.createDeployment({ |
| 23 | + issue_number: context.issue.number, |
| 24 | + owner, |
| 25 | + repo, |
| 26 | + ref: context.payload.pull_request.head.ref, |
| 27 | + environment: `preview-${context.issue.number}`, |
| 28 | + description: `Preview deployment for PR ${context.issue.number}`, |
| 29 | + auto_merge: false, |
| 30 | + required_contexts: [], |
| 31 | + }) |
| 32 | + await github.rest.repos.createDeploymentStatus({ |
| 33 | + deployment_id: deployment.data.id, |
| 34 | + owner, |
| 35 | + repo, |
| 36 | + state: "in_progress", |
| 37 | + description: "Deployment created", |
| 38 | + log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}?pr=${context.issue.number}`, |
| 39 | + }) |
| 40 | + return deployment.data.id |
| 41 | +
|
| 42 | + - uses: actions/checkout@v4 |
| 43 | + |
| 44 | + - uses: actions/download-artifact@v4 |
| 45 | + with: |
| 46 | + name: docs |
| 47 | + path: .artifacts/docs/html |
| 48 | + |
| 49 | + - uses: ./.github/actions/aws-auth |
| 50 | + |
| 51 | + - name: Upload to S3 |
| 52 | + env: |
| 53 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 54 | + run: | |
| 55 | + aws s3 sync .artifacts/docs/html "s3://elastic-docs-v3-website-preview/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" --delete |
| 56 | + aws cloudfront create-invalidation --distribution-id EKT7LT5PM8RKS --paths "/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}/*" |
| 57 | + |
| 58 | + - name: Update deployment status |
| 59 | + uses: actions/github-script@v7 |
| 60 | + if: steps.deployment.outputs.result |
| 61 | + with: |
| 62 | + script: | |
| 63 | + await github.rest.repos.createDeploymentStatus({ |
| 64 | + owner: context.repo.owner, |
| 65 | + repo: context.repo.repo, |
| 66 | + deployment_id: ${{ steps.deployment.outputs.result }}, |
| 67 | + state: "success", |
| 68 | + description: "Deployment completed", |
| 69 | + environment_url: `https://docs-v3-preview.elastic.dev/${context.repo.owner}/${context.repo.repo}/pull/${context.issue.number}`, |
| 70 | + log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}?pr=${context.issue.number}`, |
| 71 | + }) |
| 72 | +
|
| 73 | + - name: Update Deployment Status on Failure |
| 74 | + if: failure() && steps.deployment.outputs.result |
| 75 | + uses: actions/github-script@v7 |
| 76 | + with: |
| 77 | + script: | |
| 78 | + await github.rest.repos.createDeploymentStatus({ |
| 79 | + owner: context.repo.owner, |
| 80 | + repo: context.repo.repo, |
| 81 | + deployment_id: ${{ steps.deployment.outputs.result }}, |
| 82 | + state: "failure", |
| 83 | + description: "Deployment failed", |
| 84 | + log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}?pr=${context.issue.number}`, |
| 85 | + }) |
0 commit comments