Add repository input (#368) #41
This file contains hidden or 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: | |
| push: | |
| branches: | |
| - main | |
| workflow_call: | |
| inputs: | |
| strict: | |
| type: boolean | |
| default: true | |
| permissions: | |
| id-token: write | |
| deployments: write | |
| contents: read | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Create Deployment | |
| uses: actions/github-script@v7 | |
| id: deployment | |
| with: | |
| result-encoding: string | |
| script: | | |
| const { owner, repo } = context.repo; | |
| const deployment = await github.rest.repos.createDeployment({ | |
| owner, | |
| repo, | |
| ref: context.payload.pull_request.head.ref, | |
| environment: `docs-preview-${context.issue.number}`, | |
| auto_merge: false, | |
| required_contexts: [], | |
| }) | |
| await github.rest.repos.createDeploymentStatus({ | |
| deployment_id: deployment.data.id, | |
| owner, | |
| repo, | |
| state: "in_progress", | |
| 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 | |
| with: | |
| ref: ${{ github.event.pull_request.head.ref }} | |
| - uses: actions/download-artifact@v4 | |
| if: github.repository == 'elastic/docs-builder' | |
| with: | |
| name: docs-builder-binary | |
| # we run our artifact directly please use the prebuild | |
| # elastic/docs-builder@main GitHub Action for all other repositories! | |
| - name: Build documentation | |
| if: github.repository == 'elastic/docs-builder' | |
| env: | |
| PR_NUMBER: | |
| run: | | |
| chmod +x ./docs-builder | |
| ./docs-builder --strict --path-prefix "/${GITHUB_REPOSITORY}/pull/${{ github.event.pull_request.number }}" | |
| - name: Build documentation | |
| if: github.repository != 'elastic/docs-builder' | |
| uses: elastic/docs-builder@main | |
| continue-on-error: ${{ inputs.strict != 'true' }} # Will be removed after the migration phase | |
| with: | |
| prefix: "/${{ github.repository }}/pull/${{ github.event.pull_request.number }}" | |
| strict: ${{ inputs.strict }} | |
| - uses: elastic/docs-builder/.github/actions/aws-auth@main | |
| - 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: always() && 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: "${{ job.status == 'success' && 'success' || 'failure' }}", | |
| environment_url: `https://docs-v3-preview.elastic.dev/${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}`, | |
| }) |