| 
 | 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-builder-binary  | 
 | 47 | + | 
 | 48 | +      # we run our artifact directly please use the prebuild  | 
 | 49 | +      # elastic/docs-builder@main GitHub Action for all other repositories!  | 
 | 50 | +      - name: Build documentation  | 
 | 51 | +        env:  | 
 | 52 | +          PR_NUMBER: ${{ github.event.pull_request.number }}  | 
 | 53 | +        run: |  | 
 | 54 | +          chmod +x ./docs-builder  | 
 | 55 | +          ./docs-builder --strict --path-prefix "/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}"  | 
 | 56 | +
  | 
 | 57 | +      - uses: ./.github/actions/aws-auth  | 
 | 58 | + | 
 | 59 | +      - name: Upload to S3  | 
 | 60 | +        env:  | 
 | 61 | +          PR_NUMBER: ${{ github.event.pull_request.number }}  | 
 | 62 | +        run: |  | 
 | 63 | +          aws s3 sync .artifacts/docs/html "s3://elastic-docs-v3-website-preview/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" --delete  | 
 | 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: 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: "success",  | 
 | 76 | +              description: "Deployment completed",  | 
 | 77 | +              environment_url: `https://docs-v3-preview.elastic.dev/${context.repo.owner}/${context.repo.repo}/pull/${context.issue.number}`,  | 
 | 78 | +              log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}?pr=${context.issue.number}`,  | 
 | 79 | +            })  | 
 | 80 | +
  | 
 | 81 | +      - name: Update Deployment Status on Failure  | 
 | 82 | +        if: failure() && steps.deployment.outputs.result  | 
 | 83 | +        uses: actions/github-script@v7  | 
 | 84 | +        with:  | 
 | 85 | +          script: |  | 
 | 86 | +            await github.rest.repos.createDeploymentStatus({  | 
 | 87 | +              owner: context.repo.owner,  | 
 | 88 | +              repo: context.repo.repo,  | 
 | 89 | +              deployment_id: ${{ steps.deployment.outputs.result }},  | 
 | 90 | +              state: "failure",  | 
 | 91 | +              description: "Deployment failed",  | 
 | 92 | +              log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}?pr=${context.issue.number}`,  | 
 | 93 | +            })  | 
0 commit comments