| 
 | 1 | +name: preview-deploy  | 
 | 2 | + | 
 | 3 | +on:  | 
 | 4 | +  workflow_call: ~  | 
 | 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 | +      - name: Create Deployment  | 
 | 31 | +        uses: actions/github-script@v7  | 
 | 32 | +        id: deployment  | 
 | 33 | +        env:  | 
 | 34 | +          PR_NUMBER: ${{ steps.pull_request.outputs.number }}  | 
 | 35 | +          PR_REF: ${{ steps.pull_request.outputs.ref }}  | 
 | 36 | +        with:  | 
 | 37 | +          result-encoding: string  | 
 | 38 | +          script: |  | 
 | 39 | +            const { owner, repo } = context.repo;  | 
 | 40 | +            const deployment = await github.rest.repos.createDeployment({  | 
 | 41 | +                owner,  | 
 | 42 | +                repo,  | 
 | 43 | +                ref: process.env.PR_REF,  | 
 | 44 | +                environment: `docs-preview-${process.env.PR_NUMBER}`,  | 
 | 45 | +                auto_merge: false,  | 
 | 46 | +                required_contexts: [],  | 
 | 47 | +            })  | 
 | 48 | +            await github.rest.repos.createDeploymentStatus({  | 
 | 49 | +                deployment_id: deployment.data.id,  | 
 | 50 | +                owner,  | 
 | 51 | +                repo,  | 
 | 52 | +                state: "in_progress",  | 
 | 53 | +                log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,  | 
 | 54 | +            })  | 
 | 55 | +            return deployment.data.id  | 
 | 56 | +
  | 
 | 57 | +      - uses: elastic/docs-builder/.github/actions/aws-auth@main  | 
 | 58 | + | 
 | 59 | +      - name: Upload to S3  | 
 | 60 | +        env:  | 
 | 61 | +          PR_NUMBER: ${{ steps.pull_request.outputs.number }}  | 
 | 62 | +        run: |  | 
 | 63 | +          aws s3 sync . "s3://elastic-docs-v3-website-preview/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" --delete --exclude "pull_request_number.txt"  | 
 | 64 | +          aws cloudfront create-invalidation --distribution-id EKT7LT5PM8RKS --paths "/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}/*"  | 
 | 65 | +
  | 
 | 66 | +      - name: Update deployment status  | 
 | 67 | +        uses: actions/github-script@v7  | 
 | 68 | +        if: always() && steps.deployment.outputs.result  | 
 | 69 | +        with:  | 
 | 70 | +          script: |  | 
 | 71 | +            await github.rest.repos.createDeploymentStatus({  | 
 | 72 | +              owner: context.repo.owner,  | 
 | 73 | +              repo: context.repo.repo,  | 
 | 74 | +              deployment_id: ${{ steps.deployment.outputs.result }},  | 
 | 75 | +              state: "${{ job.status == 'success' && 'success' || 'failure' }}",  | 
 | 76 | +              environment_url: `https://docs-v3-preview.elastic.dev/${context.repo.owner}/${context.repo.repo}/pull/${{ steps.pull_request.outputs.number}}`,  | 
 | 77 | +              log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,  | 
 | 78 | +            })  | 
0 commit comments