From d125fde6e38869169f63843ca1dc1f8ac4aabdd6 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 27 Jan 2025 14:56:14 +0100 Subject: [PATCH 01/31] Add preview action --- actions/preview/action.yml | 97 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 actions/preview/action.yml diff --git a/actions/preview/action.yml b/actions/preview/action.yml new file mode 100644 index 000000000..6ef09dee2 --- /dev/null +++ b/actions/preview/action.yml @@ -0,0 +1,97 @@ +name: 'Documentation Preview' +description: 'Builds and publishes documentation to preview environment' + +branding: + icon: 'filter' + color: 'red' + +inputs: + strict: + description: 'Whether to fail the build if there are any warnings' + default: true + required: false + +runs: + using: "composite" + steps: + - name: Create Deployment + uses: actions/github-script@v7 + id: deployment + with: + result-encoding: string + script: | + const { owner, repo } = context.repo; + const branch = context.payload.pull_request + ? context.payload.pull_request.head.ref + : context.ref.replace('refs/heads/', ''); + + const repoResponse = await github.rest.repos.get({ + owner, + repo + }) + const defaultBranch = repoResponse.data.default_branch; + const isDefaultBranch = branch === defaultBranch; + + const environment = isDefaultBranch + ? `docs-preview-${defaultBranch}` + : `docs-preview-${context.issue.number}`; + + const logUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; + + const deployment = await github.rest.repos.createDeployment({ + owner, + repo, + ref: branch, + environment, + auto_merge: false, + required_contexts: [], + }) + await github.rest.repos.createDeploymentStatus({ + deployment_id: deployment.data.id, + owner, + repo, + state: "in_progress", + log_url: logUrl, + }) + return deployment.data.id + + - name: Generate Path Prefix + id: path-prefix + shell: bash + run: | + if [[ -n "${{ github.event.pull_request }}" ]]; then + echo "result=/${GITHUB_REPOSITORY}/pull/${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT + else + echo "result=/${GITHUB_REPOSITORY}/${{ github.ref_name }}" >> $GITHUB_OUTPUT + fi + + - name: Build public documentation + uses: elastic/docs-builder@main + continue-on-error: ${{ inputs.strict != 'true' }} + with: + prefix: ${{ steps.path-prefix.outputs.result }} + strict: ${{ inputs.strict }} + + - name: Authenticate + uses: elastic/docs-builder/.github/actions/aws-auth@main + + - name: Upload artifact + shell: bash + run: | + aws s3 sync .artifacts/docs/html s3://elastic-docs-v3-website-preview${{steps.path-prefix.outputs.result}} --delete --quiet + aws cloudfront create-invalidation --distribution-id EKT7LT5PM8RKS --paths "${{steps.path-prefix.outputs.result}}/*" + + - name: Update deployment status + uses: actions/github-script@v7 + if: always() + 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${{steps.path-prefix.outputs.result}}`, + log_url: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}', + description: "Deployment completed", + }) From bcc0c8ece7a726c957a669d657a7aa5226f3f27b Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Mon, 27 Jan 2025 21:09:49 +0100 Subject: [PATCH 02/31] test --- actions/preview/action.yml | 50 ++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/actions/preview/action.yml b/actions/preview/action.yml index 6ef09dee2..a6e4e0fc0 100644 --- a/actions/preview/action.yml +++ b/actions/preview/action.yml @@ -11,10 +11,50 @@ inputs: default: true required: false +env: + IS_DEPLOYMENT: ${{ github.event_name == 'pull_request' || github.ref == 'refs/heads/main' }} + IS_CLEANUP: ${{ github.event_name == 'pull_request_target' && github.event.action == 'closed' }} + runs: using: "composite" steps: + + - name: Authenticate + uses: elastic/docs-builder/.github/actions/aws-auth@main + + - name: Cleanup + if: ${{ env.IS_CLEANUP }} + run: | + aws s3 rm "s3://elastic-docs-v3-website-preview/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" --recursive + + - name: Delete GitHub environment + if: ${{ env.IS_CLEANUP }} + uses: actions/github-script@v7 + with: + script: | + const { owner, repo } = context.repo; + const deployments = await github.rest.repos.listDeployments({ + owner, + repo, + environment: `preview-${context.issue.number}` + }); + for (const deployment of deployments.data) { + await github.rest.repos.createDeploymentStatus({ + owner, + repo, + deployment_id: deployment.id, + state: 'inactive', + description: 'Marking deployment as inactive' + }); + await github.rest.repos.deleteDeployment({ + owner, + repo, + deployment_id: deployment.id + }); + } + - name: Create Deployment + if: env.IS_DEPLOYMENT uses: actions/github-script@v7 id: deployment with: @@ -56,6 +96,7 @@ runs: return deployment.data.id - name: Generate Path Prefix + if: env.IS_DEPLOYMENT id: path-prefix shell: bash run: | @@ -66,16 +107,15 @@ runs: fi - name: Build public documentation + if: env.IS_DEPLOYMENT uses: elastic/docs-builder@main - continue-on-error: ${{ inputs.strict != 'true' }} + continue-on-error: ${{ inputs.strict != 'true' }} # Will be removed after the migration phase with: prefix: ${{ steps.path-prefix.outputs.result }} strict: ${{ inputs.strict }} - - name: Authenticate - uses: elastic/docs-builder/.github/actions/aws-auth@main - - name: Upload artifact + if: env.IS_DEPLOYMENT shell: bash run: | aws s3 sync .artifacts/docs/html s3://elastic-docs-v3-website-preview${{steps.path-prefix.outputs.result}} --delete --quiet @@ -83,7 +123,7 @@ runs: - name: Update deployment status uses: actions/github-script@v7 - if: always() + if: always() && env.IS_DEPLOYMENT with: script: | await github.rest.repos.createDeploymentStatus({ From bdfbcd09bb561f7a9c5c9cc299faf85063f484bc Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 28 Jan 2025 13:38:05 +0100 Subject: [PATCH 03/31] fix --- actions/preview/action.yml | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/actions/preview/action.yml b/actions/preview/action.yml index a6e4e0fc0..933f73d59 100644 --- a/actions/preview/action.yml +++ b/actions/preview/action.yml @@ -11,24 +11,31 @@ inputs: default: true required: false -env: - IS_DEPLOYMENT: ${{ github.event_name == 'pull_request' || github.ref == 'refs/heads/main' }} - IS_CLEANUP: ${{ github.event_name == 'pull_request_target' && github.event.action == 'closed' }} + runs: using: "composite" steps: + - name: Get types + id: type + env: + IS_DEPLOYMENT: ${{ github.event_name == 'pull_request' || github.ref == 'refs/heads/main' }} + IS_CLEANUP: ${{ github.event_name == 'pull_request_target' && github.event.action == 'closed' }} + run: | + echo "IS_DEPLOYMENT=${IS_DEPLOYMENT}" >> $GITHUB_OUTPUT + echo "IS_CLEANUP=${IS_CLEANUP}" >> $GITHUB_OUTPUT + - name: Authenticate uses: elastic/docs-builder/.github/actions/aws-auth@main - name: Cleanup - if: ${{ env.IS_CLEANUP }} + if: ${{ steps.type.outputs.IS_CLEANUP }} run: | aws s3 rm "s3://elastic-docs-v3-website-preview/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" --recursive - name: Delete GitHub environment - if: ${{ env.IS_CLEANUP }} + if: ${{ steps.type.outputs.IS_CLEANUP }} uses: actions/github-script@v7 with: script: | @@ -54,7 +61,7 @@ runs: } - name: Create Deployment - if: env.IS_DEPLOYMENT + if: ${{ steps.type.outputs.IS_DEPLOYMENT }} uses: actions/github-script@v7 id: deployment with: @@ -96,7 +103,7 @@ runs: return deployment.data.id - name: Generate Path Prefix - if: env.IS_DEPLOYMENT + if: ${{ steps.type.outputs.IS_DEPLOYMENT }} id: path-prefix shell: bash run: | @@ -107,7 +114,7 @@ runs: fi - name: Build public documentation - if: env.IS_DEPLOYMENT + if: ${{ steps.type.outputs.IS_DEPLOYMENT }} uses: elastic/docs-builder@main continue-on-error: ${{ inputs.strict != 'true' }} # Will be removed after the migration phase with: @@ -115,7 +122,7 @@ runs: strict: ${{ inputs.strict }} - name: Upload artifact - if: env.IS_DEPLOYMENT + if: ${{ steps.type.outputs.IS_DEPLOYMENT }} shell: bash run: | aws s3 sync .artifacts/docs/html s3://elastic-docs-v3-website-preview${{steps.path-prefix.outputs.result}} --delete --quiet @@ -123,7 +130,7 @@ runs: - name: Update deployment status uses: actions/github-script@v7 - if: always() && env.IS_DEPLOYMENT + if: always() && ${{ steps.type.outputs.IS_DEPLOYMENT }} with: script: | await github.rest.repos.createDeploymentStatus({ From 1fbb858f5f7edcf2e5c89bb598dda96292bcbf1a Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 28 Jan 2025 13:38:49 +0100 Subject: [PATCH 04/31] fix --- actions/preview/action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/actions/preview/action.yml b/actions/preview/action.yml index 933f73d59..8b7395f28 100644 --- a/actions/preview/action.yml +++ b/actions/preview/action.yml @@ -19,6 +19,7 @@ runs: - name: Get types id: type + shell: bash env: IS_DEPLOYMENT: ${{ github.event_name == 'pull_request' || github.ref == 'refs/heads/main' }} IS_CLEANUP: ${{ github.event_name == 'pull_request_target' && github.event.action == 'closed' }} @@ -31,6 +32,7 @@ runs: - name: Cleanup if: ${{ steps.type.outputs.IS_CLEANUP }} + shell: bash run: | aws s3 rm "s3://elastic-docs-v3-website-preview/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" --recursive From a7d3f97d74e3bcdd1672b8124ad9a82da927ffb7 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 28 Jan 2025 13:41:06 +0100 Subject: [PATCH 05/31] tes --- actions/preview/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actions/preview/action.yml b/actions/preview/action.yml index 8b7395f28..623ed6644 100644 --- a/actions/preview/action.yml +++ b/actions/preview/action.yml @@ -21,8 +21,8 @@ runs: id: type shell: bash env: - IS_DEPLOYMENT: ${{ github.event_name == 'pull_request' || github.ref == 'refs/heads/main' }} - IS_CLEANUP: ${{ github.event_name == 'pull_request_target' && github.event.action == 'closed' }} + IS_DEPLOYMENT: ${{ toJSON(github.event_name == 'pull_request' || github.ref == 'refs/heads/main') }} + IS_CLEANUP: ${{ toJSON(github.event_name == 'pull_request_target' && github.event.action == 'closed') }} run: | echo "IS_DEPLOYMENT=${IS_DEPLOYMENT}" >> $GITHUB_OUTPUT echo "IS_CLEANUP=${IS_CLEANUP}" >> $GITHUB_OUTPUT From 6e565d1906f0f254a9bef31d3ef3442fb50468e8 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 28 Jan 2025 13:51:00 +0100 Subject: [PATCH 06/31] debug --- actions/preview/action.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/actions/preview/action.yml b/actions/preview/action.yml index 623ed6644..e0556b9a0 100644 --- a/actions/preview/action.yml +++ b/actions/preview/action.yml @@ -30,6 +30,12 @@ runs: - name: Authenticate uses: elastic/docs-builder/.github/actions/aws-auth@main + - name: Debug + shell: bash + run: | + echo "IS_DEPLOYMENT: ${{ steps.type.outputs.IS_DEPLOYMENT }}" + echo "IS_CLEANUP: ${{ steps.type.outputs.IS_CLEANUP }}" + - name: Cleanup if: ${{ steps.type.outputs.IS_CLEANUP }} shell: bash From b12eeb1d464c228fb05196ff7e25d53531a79a1e Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 28 Jan 2025 13:56:29 +0100 Subject: [PATCH 07/31] test --- actions/preview/action.yml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/actions/preview/action.yml b/actions/preview/action.yml index e0556b9a0..1cfbb29d7 100644 --- a/actions/preview/action.yml +++ b/actions/preview/action.yml @@ -11,8 +11,6 @@ inputs: default: true required: false - - runs: using: "composite" steps: @@ -37,13 +35,13 @@ runs: echo "IS_CLEANUP: ${{ steps.type.outputs.IS_CLEANUP }}" - name: Cleanup - if: ${{ steps.type.outputs.IS_CLEANUP }} + if: steps.type.outputs.IS_CLEANUP shell: bash run: | aws s3 rm "s3://elastic-docs-v3-website-preview/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" --recursive - name: Delete GitHub environment - if: ${{ steps.type.outputs.IS_CLEANUP }} + if: steps.type.outputs.IS_CLEANUP uses: actions/github-script@v7 with: script: | @@ -69,7 +67,7 @@ runs: } - name: Create Deployment - if: ${{ steps.type.outputs.IS_DEPLOYMENT }} + if: steps.type.outputs.IS_DEPLOYMENT uses: actions/github-script@v7 id: deployment with: @@ -111,7 +109,7 @@ runs: return deployment.data.id - name: Generate Path Prefix - if: ${{ steps.type.outputs.IS_DEPLOYMENT }} + if: steps.type.outputs.IS_DEPLOYMENT id: path-prefix shell: bash run: | @@ -122,7 +120,7 @@ runs: fi - name: Build public documentation - if: ${{ steps.type.outputs.IS_DEPLOYMENT }} + if: steps.type.outputs.IS_DEPLOYMENT uses: elastic/docs-builder@main continue-on-error: ${{ inputs.strict != 'true' }} # Will be removed after the migration phase with: @@ -130,7 +128,7 @@ runs: strict: ${{ inputs.strict }} - name: Upload artifact - if: ${{ steps.type.outputs.IS_DEPLOYMENT }} + if: steps.type.outputs.IS_DEPLOYMENT shell: bash run: | aws s3 sync .artifacts/docs/html s3://elastic-docs-v3-website-preview${{steps.path-prefix.outputs.result}} --delete --quiet @@ -138,7 +136,7 @@ runs: - name: Update deployment status uses: actions/github-script@v7 - if: always() && ${{ steps.type.outputs.IS_DEPLOYMENT }} + if: always() && steps.type.outputs.IS_DEPLOYMENT with: script: | await github.rest.repos.createDeploymentStatus({ From 5906348480baa817746d0103af90253d33e383c7 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 28 Jan 2025 15:04:08 +0100 Subject: [PATCH 08/31] test --- actions/preview/README.md | 54 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 actions/preview/README.md diff --git a/actions/preview/README.md b/actions/preview/README.md new file mode 100644 index 000000000..348ff203a --- /dev/null +++ b/actions/preview/README.md @@ -0,0 +1,54 @@ + + +# Documentation Preview + + +Builds and publishes documentation to preview environment + + +## Inputs + + +| Name | Description | Required | Default | +|----------|-----------------------------------------------------|----------|---------| +| `strict` | Whether to fail the build if there are any warnings | `false` | `true` | + + + +## Usage + + +```yaml +name: Documentation Preview + +on: + pull_request: ~ + pull_request_target: + types: + - closed + push: + branches: + - main # Depends on the default branch name of the repository + +permissions: + contents: read + id-token: write + deployments: write + +# Ensure only one workflow runs at a time for a given branch/PR +# Cancel any in-progress runs when a new commit is pushed, except on main branch +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} + +jobs: + docs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: elastic/docs-builder/actions/preview@main +``` + From 555861e448e601f88a2a18408bd975b231ce80cf Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 28 Jan 2025 17:38:40 +0100 Subject: [PATCH 09/31] fix --- actions/preview/action.yml | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/actions/preview/action.yml b/actions/preview/action.yml index 1cfbb29d7..c3af086e6 100644 --- a/actions/preview/action.yml +++ b/actions/preview/action.yml @@ -28,20 +28,14 @@ runs: - name: Authenticate uses: elastic/docs-builder/.github/actions/aws-auth@main - - name: Debug - shell: bash - run: | - echo "IS_DEPLOYMENT: ${{ steps.type.outputs.IS_DEPLOYMENT }}" - echo "IS_CLEANUP: ${{ steps.type.outputs.IS_CLEANUP }}" - - name: Cleanup - if: steps.type.outputs.IS_CLEANUP + if: steps.type.outputs.IS_CLEANUP == 'true' shell: bash run: | aws s3 rm "s3://elastic-docs-v3-website-preview/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" --recursive - name: Delete GitHub environment - if: steps.type.outputs.IS_CLEANUP + if: steps.type.outputs.IS_CLEANUP == 'true' uses: actions/github-script@v7 with: script: | @@ -67,7 +61,7 @@ runs: } - name: Create Deployment - if: steps.type.outputs.IS_DEPLOYMENT + if: steps.type.outputs.IS_DEPLOYMENT == 'true' uses: actions/github-script@v7 id: deployment with: @@ -109,7 +103,7 @@ runs: return deployment.data.id - name: Generate Path Prefix - if: steps.type.outputs.IS_DEPLOYMENT + if: steps.type.outputs.IS_DEPLOYMENT == 'true' id: path-prefix shell: bash run: | @@ -120,7 +114,7 @@ runs: fi - name: Build public documentation - if: steps.type.outputs.IS_DEPLOYMENT + if: steps.type.outputs.IS_DEPLOYMENT == 'true' uses: elastic/docs-builder@main continue-on-error: ${{ inputs.strict != 'true' }} # Will be removed after the migration phase with: @@ -128,7 +122,7 @@ runs: strict: ${{ inputs.strict }} - name: Upload artifact - if: steps.type.outputs.IS_DEPLOYMENT + if: steps.type.outputs.IS_DEPLOYMENT == 'true' shell: bash run: | aws s3 sync .artifacts/docs/html s3://elastic-docs-v3-website-preview${{steps.path-prefix.outputs.result}} --delete --quiet @@ -136,7 +130,7 @@ runs: - name: Update deployment status uses: actions/github-script@v7 - if: always() && steps.type.outputs.IS_DEPLOYMENT + if: always() && steps.type.outputs.IS_DEPLOYMENT == 'true' with: script: | await github.rest.repos.createDeploymentStatus({ From 2ec874f3f4084a92337d5ae6f07ed5ebf1363306 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 28 Jan 2025 22:52:06 +0100 Subject: [PATCH 10/31] fix --- actions/preview/action.yml | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/actions/preview/action.yml b/actions/preview/action.yml index c3af086e6..78ed4411b 100644 --- a/actions/preview/action.yml +++ b/actions/preview/action.yml @@ -18,12 +18,25 @@ runs: - name: Get types id: type shell: bash - env: - IS_DEPLOYMENT: ${{ toJSON(github.event_name == 'pull_request' || github.ref == 'refs/heads/main') }} - IS_CLEANUP: ${{ toJSON(github.event_name == 'pull_request_target' && github.event.action == 'closed') }} run: | - echo "IS_DEPLOYMENT=${IS_DEPLOYMENT}" >> $GITHUB_OUTPUT - echo "IS_CLEANUP=${IS_CLEANUP}" >> $GITHUB_OUTPUT + if [[ "${{ github.event_name}}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]]; then + echo "IS_DEPLOYMENT=true" >> $GITHUB_OUTPUT + echo "IS_CLEANUP=false" >> $GITHUB_OUTPUT + else + if [[ "${{ github.event_name }}" == "pull_request_target" && "${{ github.event.action }}" == "closed" ]]; then + echo "IS_CLEANUP=true" >> $GITHUB_OUTPUT + echo "IS_DEPLOYMENT=false" >> $GITHUB_OUTPUT + else + is_deployment=${{ toJSON(github.event_name == 'pull_request' || github.ref == 'refs/heads/main') }} + echo "IS_CLEANUP=false" >> $GITHUB_OUTPUT + echo "IS_DEPLOYMENT=${is_deployment}" >> $GITHUB_OUTPUT + fi + + - name: Debug + shell: bash + run: | + echo "IS_DEPLOYMENT: ${{ steps.type.outputs.IS_DEPLOYMENT }}" + echo "IS_CLEANUP: ${{ steps.type.outputs.IS_CLEANUP }}" - name: Authenticate uses: elastic/docs-builder/.github/actions/aws-auth@main @@ -130,7 +143,7 @@ runs: - name: Update deployment status uses: actions/github-script@v7 - if: always() && steps.type.outputs.IS_DEPLOYMENT == 'true' + if: always() && steps.type.outputs.IS_DEPLOYMENT with: script: | await github.rest.repos.createDeploymentStatus({ From 3fbec4285db7ff09c66c30b1a4ee9584dca8dfe5 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 28 Jan 2025 23:00:43 +0100 Subject: [PATCH 11/31] fix --- actions/preview/action.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/actions/preview/action.yml b/actions/preview/action.yml index 78ed4411b..cf19ac886 100644 --- a/actions/preview/action.yml +++ b/actions/preview/action.yml @@ -19,17 +19,12 @@ runs: id: type shell: bash run: | - if [[ "${{ github.event_name}}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]]; then - echo "IS_DEPLOYMENT=true" >> $GITHUB_OUTPUT - echo "IS_CLEANUP=false" >> $GITHUB_OUTPUT - else if [[ "${{ github.event_name }}" == "pull_request_target" && "${{ github.event.action }}" == "closed" ]]; then echo "IS_CLEANUP=true" >> $GITHUB_OUTPUT echo "IS_DEPLOYMENT=false" >> $GITHUB_OUTPUT - else - is_deployment=${{ toJSON(github.event_name == 'pull_request' || github.ref == 'refs/heads/main') }} + elif [[ ${{ github.event_name }} == 'pull_request' || "${{ github.ref }}" == 'refs/heads/main' ]]; then echo "IS_CLEANUP=false" >> $GITHUB_OUTPUT - echo "IS_DEPLOYMENT=${is_deployment}" >> $GITHUB_OUTPUT + echo "IS_DEPLOYMENT=true" >> $GITHUB_OUTPUT fi - name: Debug From 62635f51751e094a8e0812f7a07e58402cd97bcd Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 28 Jan 2025 23:13:58 +0100 Subject: [PATCH 12/31] Add groups --- actions/preview/action.yml | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/actions/preview/action.yml b/actions/preview/action.yml index cf19ac886..f3d88cc5d 100644 --- a/actions/preview/action.yml +++ b/actions/preview/action.yml @@ -15,6 +15,11 @@ runs: using: "composite" steps: + - name: group-start + shell: bash + run: | + echo ""::group::Determing the type of event" + - name: Get types id: type shell: bash @@ -33,9 +38,32 @@ runs: echo "IS_DEPLOYMENT: ${{ steps.type.outputs.IS_DEPLOYMENT }}" echo "IS_CLEANUP: ${{ steps.type.outputs.IS_CLEANUP }}" + - name: group-end + shell: bash + run: | + echo ""::endgroup::" + + + - name: group-start + shell: bash + run: | + echo ""::group::Authenticate to AWS" + + - name: Authenticate uses: elastic/docs-builder/.github/actions/aws-auth@main + - name: group-end + shell: bash + run: | + echo ""::endgroup::" + + - name: group-start + if: steps.type.outputs.IS_CLEANUP == 'true' + shell: bash + run: | + echo ""::group::Cleanup" + - name: Cleanup if: steps.type.outputs.IS_CLEANUP == 'true' shell: bash @@ -68,6 +96,18 @@ runs: }); } + - name: group-end + shell: bash + if: steps.type.outputs.IS_CLEANUP == 'true' + run: | + echo ""::endgroup::" + + - name: group-start + if: steps.type.outputs.IS_DEPLOYMENT == 'true' + shell: bash + run: | + echo ""::group::Deploy" + - name: Create Deployment if: steps.type.outputs.IS_DEPLOYMENT == 'true' uses: actions/github-script@v7 @@ -150,3 +190,8 @@ runs: log_url: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}', description: "Deployment completed", }) + + - name: group-end + shell: bash + run: | + echo ""::endgroup::" From 1027fedb05268967d6adb6c314fb5a36895f8180 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 28 Jan 2025 23:14:51 +0100 Subject: [PATCH 13/31] fix --- actions/preview/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/preview/action.yml b/actions/preview/action.yml index f3d88cc5d..30f7b5df0 100644 --- a/actions/preview/action.yml +++ b/actions/preview/action.yml @@ -44,7 +44,7 @@ runs: echo ""::endgroup::" - - name: group-start + - name: group-start shell: bash run: | echo ""::group::Authenticate to AWS" From fdfd18f482323d90b2aac8bbf64918b74a639b16 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 28 Jan 2025 23:17:45 +0100 Subject: [PATCH 14/31] ok --- actions/preview/action.yml | 46 -------------------------------------- 1 file changed, 46 deletions(-) diff --git a/actions/preview/action.yml b/actions/preview/action.yml index 30f7b5df0..0f6237ed5 100644 --- a/actions/preview/action.yml +++ b/actions/preview/action.yml @@ -14,12 +14,6 @@ inputs: runs: using: "composite" steps: - - - name: group-start - shell: bash - run: | - echo ""::group::Determing the type of event" - - name: Get types id: type shell: bash @@ -38,32 +32,9 @@ runs: echo "IS_DEPLOYMENT: ${{ steps.type.outputs.IS_DEPLOYMENT }}" echo "IS_CLEANUP: ${{ steps.type.outputs.IS_CLEANUP }}" - - name: group-end - shell: bash - run: | - echo ""::endgroup::" - - - - name: group-start - shell: bash - run: | - echo ""::group::Authenticate to AWS" - - - name: Authenticate uses: elastic/docs-builder/.github/actions/aws-auth@main - - name: group-end - shell: bash - run: | - echo ""::endgroup::" - - - name: group-start - if: steps.type.outputs.IS_CLEANUP == 'true' - shell: bash - run: | - echo ""::group::Cleanup" - - name: Cleanup if: steps.type.outputs.IS_CLEANUP == 'true' shell: bash @@ -96,18 +67,6 @@ runs: }); } - - name: group-end - shell: bash - if: steps.type.outputs.IS_CLEANUP == 'true' - run: | - echo ""::endgroup::" - - - name: group-start - if: steps.type.outputs.IS_DEPLOYMENT == 'true' - shell: bash - run: | - echo ""::group::Deploy" - - name: Create Deployment if: steps.type.outputs.IS_DEPLOYMENT == 'true' uses: actions/github-script@v7 @@ -190,8 +149,3 @@ runs: log_url: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}', description: "Deployment completed", }) - - - name: group-end - shell: bash - run: | - echo ""::endgroup::" From 19c565b51202d3350f75f5d080f1a003f8b025da Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 28 Jan 2025 23:20:37 +0100 Subject: [PATCH 15/31] fix --- actions/preview/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/preview/action.yml b/actions/preview/action.yml index 0f6237ed5..f0cd0bbdc 100644 --- a/actions/preview/action.yml +++ b/actions/preview/action.yml @@ -137,7 +137,7 @@ runs: - name: Update deployment status uses: actions/github-script@v7 - if: always() && steps.type.outputs.IS_DEPLOYMENT + if: always() && steps.deployment.outputs.result with: script: | await github.rest.repos.createDeploymentStatus({ From a1f783315f31100acde94c364fb1e7ced80fda15 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 28 Jan 2025 23:23:42 +0100 Subject: [PATCH 16/31] fix --- actions/preview/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/preview/action.yml b/actions/preview/action.yml index f0cd0bbdc..00504a2e3 100644 --- a/actions/preview/action.yml +++ b/actions/preview/action.yml @@ -50,7 +50,7 @@ runs: const deployments = await github.rest.repos.listDeployments({ owner, repo, - environment: `preview-${context.issue.number}` + environment: `docs-preview-${context.issue.number}` }); for (const deployment of deployments.data) { await github.rest.repos.createDeploymentStatus({ From acc65739adf2c830cce210c05948a4fa10da28ee Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 28 Jan 2025 23:24:53 +0100 Subject: [PATCH 17/31] ok --- actions/preview/action.yml | 41 ++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/actions/preview/action.yml b/actions/preview/action.yml index 00504a2e3..4555b201c 100644 --- a/actions/preview/action.yml +++ b/actions/preview/action.yml @@ -47,24 +47,35 @@ runs: with: script: | const { owner, repo } = context.repo; - const deployments = await github.rest.repos.listDeployments({ - owner, - repo, - environment: `docs-preview-${context.issue.number}` - }); - for (const deployment of deployments.data) { - await github.rest.repos.createDeploymentStatus({ - owner, - repo, - deployment_id: deployment.id, - state: 'inactive', - description: 'Marking deployment as inactive' - }); - await github.rest.repos.deleteDeployment({ + let page = 1; + let hasMore = true; + + while (hasMore) { + const deployments = await github.rest.repos.listDeployments({ owner, repo, - deployment_id: deployment.id + environment: `docs-preview-${context.issue.number}`, + per_page: 100, + page: page }); + + for (const deployment of deployments.data) { + await github.rest.repos.createDeploymentStatus({ + owner, + repo, + deployment_id: deployment.id, + state: 'inactive', + description: 'Marking deployment as inactive' + }); + await github.rest.repos.deleteDeployment({ + owner, + repo, + deployment_id: deployment.id + }); + } + + hasMore = deployments.data.length === 100; + page++; } - name: Create Deployment From 6bf01f0267e6734d7fb42cb9836d0cd423c65749 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 28 Jan 2025 23:28:48 +0100 Subject: [PATCH 18/31] test --- actions/preview/action.yml | 42 +++++++++++++++----------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/actions/preview/action.yml b/actions/preview/action.yml index 4555b201c..5e40ad18b 100644 --- a/actions/preview/action.yml +++ b/actions/preview/action.yml @@ -47,35 +47,25 @@ runs: with: script: | const { owner, repo } = context.repo; - let page = 1; - let hasMore = true; - - while (hasMore) { - const deployments = await github.rest.repos.listDeployments({ + const deployments = await github.rest.repos.listDeployments({ + owner, + repo, + environment: `docs-preview-${context.issue.number}`, + per_page: 100, + }); + for (const deployment of deployments.data) { + await github.rest.repos.createDeploymentStatus({ + owner, + repo, + deployment_id: deployment.id, + state: 'inactive', + description: 'Marking deployment as inactive' + }); + await github.rest.repos.deleteDeployment({ owner, repo, - environment: `docs-preview-${context.issue.number}`, - per_page: 100, - page: page + deployment_id: deployment.id }); - - for (const deployment of deployments.data) { - await github.rest.repos.createDeploymentStatus({ - owner, - repo, - deployment_id: deployment.id, - state: 'inactive', - description: 'Marking deployment as inactive' - }); - await github.rest.repos.deleteDeployment({ - owner, - repo, - deployment_id: deployment.id - }); - } - - hasMore = deployments.data.length === 100; - page++; } - name: Create Deployment From faec95d6dce61d71f6a0cc76ad4b86dcfa284c89 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 28 Jan 2025 23:54:10 +0100 Subject: [PATCH 19/31] test --- .github/workflows/preview.yml | 28 +++++++++++++++++++++++----- actions/preview/action.yml | 4 ++-- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 1fcb79f24..70d3f1c3b 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -1,7 +1,11 @@ name: preview on: - workflow_call: ~ + workflow_call: + inputs: + strict: + type: boolean + default: true permissions: id-token: write @@ -24,7 +28,7 @@ jobs: owner, repo, ref: context.payload.pull_request.head.ref, - environment: `preview-${context.issue.number}`, + environment: `docs-preview-${context.issue.number}`, description: `Preview deployment for PR ${context.issue.number}`, auto_merge: false, required_contexts: [], @@ -42,19 +46,33 @@ jobs: - uses: actions/checkout@v4 - 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: ${{ github.event.pull_request.number }} + PR_NUMBER: run: | chmod +x ./docs-builder - ./docs-builder --strict --path-prefix "/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" + ./docs-builder --strict --path-prefix "/${GITHUB_REPOSITORY}/pull/${{ github.event.pull_request.number }}" + + - name: Build documentation + if: github.repository != 'elastic/docs-builder' + run: | + echo "Building documentation for ${GITHUB_REPOSITORY}" + - name: Build public 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: ./.github/actions/aws-auth + - uses: elastic/docs-builder/.github/actions/aws-auth@main - name: Upload to S3 env: diff --git a/actions/preview/action.yml b/actions/preview/action.yml index 5e40ad18b..af5bc9215 100644 --- a/actions/preview/action.yml +++ b/actions/preview/action.yml @@ -21,7 +21,7 @@ runs: if [[ "${{ github.event_name }}" == "pull_request_target" && "${{ github.event.action }}" == "closed" ]]; then echo "IS_CLEANUP=true" >> $GITHUB_OUTPUT echo "IS_DEPLOYMENT=false" >> $GITHUB_OUTPUT - elif [[ ${{ github.event_name }} == 'pull_request' || "${{ github.ref }}" == 'refs/heads/main' ]]; then + elif [[ ${{ github.event_name }} == 'pull_request' || ("${{ github.event_name }}" == 'push' && "${{ github.ref }}" == 'refs/heads/main') ]]; then echo "IS_CLEANUP=false" >> $GITHUB_OUTPUT echo "IS_DEPLOYMENT=true" >> $GITHUB_OUTPUT fi @@ -118,7 +118,7 @@ runs: if [[ -n "${{ github.event.pull_request }}" ]]; then echo "result=/${GITHUB_REPOSITORY}/pull/${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT else - echo "result=/${GITHUB_REPOSITORY}/${{ github.ref_name }}" >> $GITHUB_OUTPUT + echo "result=/${GITHUB_REPOSITORY}/tree/${{ github.ref_name }}" >> $GITHUB_OUTPUT fi - name: Build public documentation From 42cfb27851520629f988f923040ca8ecb01e0ac9 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 29 Jan 2025 00:00:18 +0100 Subject: [PATCH 20/31] fix --- .github/workflows/preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 70d3f1c3b..62548de9b 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -9,8 +9,8 @@ on: permissions: id-token: write - pull-requests: write deployments: write + contents: read jobs: deploy: From 83955cc92644b6b8be5e49518b9ad20163e8451f Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 29 Jan 2025 00:04:32 +0100 Subject: [PATCH 21/31] refactor --- .github/workflows/preview.yml | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 62548de9b..f9b8717f0 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -83,29 +83,15 @@ jobs: - name: Update deployment status uses: actions/github-script@v7 - if: steps.deployment.outputs.result + 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: "success", + state: "${{ job.status == 'success' && 'success' || 'failure' }}", description: "Deployment completed", 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}`, }) - - - 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}`, - }) From 76f59fe3f09c60da847f861676054c047bfd96a7 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 29 Jan 2025 00:09:09 +0100 Subject: [PATCH 22/31] naming --- .github/workflows/preview-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview-cleanup.yml b/.github/workflows/preview-cleanup.yml index 63295f8f7..63ec86e8a 100644 --- a/.github/workflows/preview-cleanup.yml +++ b/.github/workflows/preview-cleanup.yml @@ -28,7 +28,7 @@ jobs: const deployments = await github.rest.repos.listDeployments({ owner, repo, - environment: `preview-${context.issue.number}` + environment: `docs-preview-${context.issue.number}` }); for (const deployment of deployments.data) { await github.rest.repos.createDeploymentStatus({ From 1add11233b730d19f7fb9dbb77aff4dec53c9bef Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 29 Jan 2025 00:09:53 +0100 Subject: [PATCH 23/31] naming --- .github/workflows/preview-cleanup.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview-cleanup.yml b/.github/workflows/preview-cleanup.yml index 63ec86e8a..24c461fdd 100644 --- a/.github/workflows/preview-cleanup.yml +++ b/.github/workflows/preview-cleanup.yml @@ -9,7 +9,7 @@ permissions: id-token: write jobs: - cleanup: + destroy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 From 0932f06840ac24a46fed46cde8f89bc6a41d3c92 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 29 Jan 2025 00:11:48 +0100 Subject: [PATCH 24/31] Add workflow_call --- .github/workflows/preview-cleanup.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/preview-cleanup.yml b/.github/workflows/preview-cleanup.yml index 24c461fdd..b0240457f 100644 --- a/.github/workflows/preview-cleanup.yml +++ b/.github/workflows/preview-cleanup.yml @@ -1,6 +1,7 @@ name: preview-cleanup on: + workflow_call: ~ pull_request_target: types: [closed] From b1c0c55f9bb3de4ef10e7aa6ea971baad87a7ce4 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 29 Jan 2025 00:18:43 +0100 Subject: [PATCH 25/31] fix --- .github/workflows/preview-cleanup.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/preview-cleanup.yml b/.github/workflows/preview-cleanup.yml index b0240457f..ae43042f6 100644 --- a/.github/workflows/preview-cleanup.yml +++ b/.github/workflows/preview-cleanup.yml @@ -8,13 +8,14 @@ on: permissions: deployments: write id-token: write + contents: read jobs: destroy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: ./.github/actions/aws-auth + - uses: elastic/docs-builder/.github/actions/aws-auth@main - name: Delete s3 objects env: PR_NUMBER: ${{ github.event.pull_request.number }} From 68e37f5895b506342bb1826be9e500a171498064 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 29 Jan 2025 00:32:13 +0100 Subject: [PATCH 26/31] cleanup --- .github/workflows/preview.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index f9b8717f0..233096bd7 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -61,10 +61,6 @@ jobs: ./docs-builder --strict --path-prefix "/${GITHUB_REPOSITORY}/pull/${{ github.event.pull_request.number }}" - name: Build documentation - if: github.repository != 'elastic/docs-builder' - run: | - echo "Building documentation for ${GITHUB_REPOSITORY}" - - name: Build public 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 From b0e7d7b9e9e17edf2116ec57abd0eedddef755ff Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 29 Jan 2025 00:44:24 +0100 Subject: [PATCH 27/31] cleanup --- .github/workflows/preview.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 233096bd7..988376613 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -1,6 +1,9 @@ name: preview on: + push: + branches: + - main workflow_call: inputs: strict: @@ -24,12 +27,10 @@ jobs: script: | const { owner, repo } = context.repo; const deployment = await github.rest.repos.createDeployment({ - issue_number: context.issue.number, owner, repo, ref: context.payload.pull_request.head.ref, environment: `docs-preview-${context.issue.number}`, - description: `Preview deployment for PR ${context.issue.number}`, auto_merge: false, required_contexts: [], }) @@ -38,7 +39,6 @@ jobs: owner, 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 @@ -87,7 +87,6 @@ jobs: repo: context.repo.repo, deployment_id: ${{ steps.deployment.outputs.result }}, state: "${{ job.status == 'success' && 'success' || 'failure' }}", - description: "Deployment completed", 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}`, }) From 124b34feb25574cf418586caf3bda213e25b18c1 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 29 Jan 2025 00:46:48 +0100 Subject: [PATCH 28/31] Remove action again --- actions/preview/README.md | 54 ------------- actions/preview/action.yml | 152 ------------------------------------- 2 files changed, 206 deletions(-) delete mode 100644 actions/preview/README.md delete mode 100644 actions/preview/action.yml diff --git a/actions/preview/README.md b/actions/preview/README.md deleted file mode 100644 index 348ff203a..000000000 --- a/actions/preview/README.md +++ /dev/null @@ -1,54 +0,0 @@ - - -# Documentation Preview - - -Builds and publishes documentation to preview environment - - -## Inputs - - -| Name | Description | Required | Default | -|----------|-----------------------------------------------------|----------|---------| -| `strict` | Whether to fail the build if there are any warnings | `false` | `true` | - - - -## Usage - - -```yaml -name: Documentation Preview - -on: - pull_request: ~ - pull_request_target: - types: - - closed - push: - branches: - - main # Depends on the default branch name of the repository - -permissions: - contents: read - id-token: write - deployments: write - -# Ensure only one workflow runs at a time for a given branch/PR -# Cancel any in-progress runs when a new commit is pushed, except on main branch -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} - -jobs: - docs: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: elastic/docs-builder/actions/preview@main -``` - diff --git a/actions/preview/action.yml b/actions/preview/action.yml deleted file mode 100644 index af5bc9215..000000000 --- a/actions/preview/action.yml +++ /dev/null @@ -1,152 +0,0 @@ -name: 'Documentation Preview' -description: 'Builds and publishes documentation to preview environment' - -branding: - icon: 'filter' - color: 'red' - -inputs: - strict: - description: 'Whether to fail the build if there are any warnings' - default: true - required: false - -runs: - using: "composite" - steps: - - name: Get types - id: type - shell: bash - run: | - if [[ "${{ github.event_name }}" == "pull_request_target" && "${{ github.event.action }}" == "closed" ]]; then - echo "IS_CLEANUP=true" >> $GITHUB_OUTPUT - echo "IS_DEPLOYMENT=false" >> $GITHUB_OUTPUT - elif [[ ${{ github.event_name }} == 'pull_request' || ("${{ github.event_name }}" == 'push' && "${{ github.ref }}" == 'refs/heads/main') ]]; then - echo "IS_CLEANUP=false" >> $GITHUB_OUTPUT - echo "IS_DEPLOYMENT=true" >> $GITHUB_OUTPUT - fi - - - name: Debug - shell: bash - run: | - echo "IS_DEPLOYMENT: ${{ steps.type.outputs.IS_DEPLOYMENT }}" - echo "IS_CLEANUP: ${{ steps.type.outputs.IS_CLEANUP }}" - - - name: Authenticate - uses: elastic/docs-builder/.github/actions/aws-auth@main - - - name: Cleanup - if: steps.type.outputs.IS_CLEANUP == 'true' - shell: bash - run: | - aws s3 rm "s3://elastic-docs-v3-website-preview/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" --recursive - - - name: Delete GitHub environment - if: steps.type.outputs.IS_CLEANUP == 'true' - uses: actions/github-script@v7 - with: - script: | - const { owner, repo } = context.repo; - const deployments = await github.rest.repos.listDeployments({ - owner, - repo, - environment: `docs-preview-${context.issue.number}`, - per_page: 100, - }); - for (const deployment of deployments.data) { - await github.rest.repos.createDeploymentStatus({ - owner, - repo, - deployment_id: deployment.id, - state: 'inactive', - description: 'Marking deployment as inactive' - }); - await github.rest.repos.deleteDeployment({ - owner, - repo, - deployment_id: deployment.id - }); - } - - - name: Create Deployment - if: steps.type.outputs.IS_DEPLOYMENT == 'true' - uses: actions/github-script@v7 - id: deployment - with: - result-encoding: string - script: | - const { owner, repo } = context.repo; - const branch = context.payload.pull_request - ? context.payload.pull_request.head.ref - : context.ref.replace('refs/heads/', ''); - - const repoResponse = await github.rest.repos.get({ - owner, - repo - }) - const defaultBranch = repoResponse.data.default_branch; - const isDefaultBranch = branch === defaultBranch; - - const environment = isDefaultBranch - ? `docs-preview-${defaultBranch}` - : `docs-preview-${context.issue.number}`; - - const logUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; - - const deployment = await github.rest.repos.createDeployment({ - owner, - repo, - ref: branch, - environment, - auto_merge: false, - required_contexts: [], - }) - await github.rest.repos.createDeploymentStatus({ - deployment_id: deployment.data.id, - owner, - repo, - state: "in_progress", - log_url: logUrl, - }) - return deployment.data.id - - - name: Generate Path Prefix - if: steps.type.outputs.IS_DEPLOYMENT == 'true' - id: path-prefix - shell: bash - run: | - if [[ -n "${{ github.event.pull_request }}" ]]; then - echo "result=/${GITHUB_REPOSITORY}/pull/${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT - else - echo "result=/${GITHUB_REPOSITORY}/tree/${{ github.ref_name }}" >> $GITHUB_OUTPUT - fi - - - name: Build public documentation - if: steps.type.outputs.IS_DEPLOYMENT == 'true' - uses: elastic/docs-builder@main - continue-on-error: ${{ inputs.strict != 'true' }} # Will be removed after the migration phase - with: - prefix: ${{ steps.path-prefix.outputs.result }} - strict: ${{ inputs.strict }} - - - name: Upload artifact - if: steps.type.outputs.IS_DEPLOYMENT == 'true' - shell: bash - run: | - aws s3 sync .artifacts/docs/html s3://elastic-docs-v3-website-preview${{steps.path-prefix.outputs.result}} --delete --quiet - aws cloudfront create-invalidation --distribution-id EKT7LT5PM8RKS --paths "${{steps.path-prefix.outputs.result}}/*" - - - 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${{steps.path-prefix.outputs.result}}`, - log_url: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}', - description: "Deployment completed", - }) From f61eeef459dc08772a9f24d7ce326fcebe4d6f54 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 29 Jan 2025 01:02:19 +0100 Subject: [PATCH 29/31] docs --- docs/docset.yml | 1 + docs/quickstart/index.md | 62 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 docs/quickstart/index.md diff --git a/docs/docset.yml b/docs/docset.yml index 814e38237..163873734 100644 --- a/docs/docset.yml +++ b/docs/docset.yml @@ -24,6 +24,7 @@ subs: a-global-variable: "This was defined in docset.yml" toc: - file: index.md + - file: quickstart/index.md - folder: contribute children: - file: index.md diff --git a/docs/quickstart/index.md b/docs/quickstart/index.md new file mode 100644 index 000000000..853368528 --- /dev/null +++ b/docs/quickstart/index.md @@ -0,0 +1,62 @@ +# Quickstart + +## Download the docs-builder binary + +TBD + +## Set up folder structure + +``` +root/ +├── docs/ +│ └── index.md +│ └── docset.yml +└── ... +``` + + + + +## Set up preview environment + +:::{dropdown} .github/workflows/docs.yml +:open: +```markdown +name: docs + +on: + pull_request_target: + types: + - closed + +jobs: + docs-preview: + uses: elastic/docs-builder/.github/workflows/preview-cleanup.yml@main + permissions: # this is needed + contents: read + id-token: write + deployments: write +``` + +::: + +:::{dropdown} .github/workflows/docs-cleanup.yml +:open: +```markdown +name: docs + +on: + pull_request_target: + types: + - closed + +jobs: + docs-preview: + uses: elastic/docs-builder/.github/workflows/preview-cleanup.yml@feature/consumer-preview-action + permissions: + contents: read + id-token: write + deployments: write +``` + +::: From 6657a1f019efc091a0952da3400e5e87155dfe87 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 29 Jan 2025 01:11:04 +0100 Subject: [PATCH 30/31] test --- .github/workflows/preview.yml | 2 ++ docs/quickstart/index.md | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 988376613..c3cd73105 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -44,6 +44,8 @@ jobs: 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' diff --git a/docs/quickstart/index.md b/docs/quickstart/index.md index 853368528..df5ecad4a 100644 --- a/docs/quickstart/index.md +++ b/docs/quickstart/index.md @@ -27,15 +27,26 @@ name: docs on: pull_request_target: types: - - closed + - synchronize + - opened + - reopened + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} jobs: docs-preview: - uses: elastic/docs-builder/.github/workflows/preview-cleanup.yml@main - permissions: # this is needed + uses: elastic/docs-builder/.github/workflows/preview.yml@feature/consumer-preview-action + permissions: contents: read id-token: write deployments: write + with: + strict: false ``` ::: @@ -52,7 +63,7 @@ on: jobs: docs-preview: - uses: elastic/docs-builder/.github/workflows/preview-cleanup.yml@feature/consumer-preview-action + uses: elastic/docs-builder/.github/workflows/preview-cleanup.yml@main permissions: contents: read id-token: write From a579ca416346f46e3583191f1db9f7fa9d744c7d Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Wed, 29 Jan 2025 10:15:55 +0100 Subject: [PATCH 31/31] Revert docs --- docs/docset.yml | 1 - docs/quickstart/index.md | 73 ---------------------------------------- 2 files changed, 74 deletions(-) delete mode 100644 docs/quickstart/index.md diff --git a/docs/docset.yml b/docs/docset.yml index 163873734..814e38237 100644 --- a/docs/docset.yml +++ b/docs/docset.yml @@ -24,7 +24,6 @@ subs: a-global-variable: "This was defined in docset.yml" toc: - file: index.md - - file: quickstart/index.md - folder: contribute children: - file: index.md diff --git a/docs/quickstart/index.md b/docs/quickstart/index.md deleted file mode 100644 index df5ecad4a..000000000 --- a/docs/quickstart/index.md +++ /dev/null @@ -1,73 +0,0 @@ -# Quickstart - -## Download the docs-builder binary - -TBD - -## Set up folder structure - -``` -root/ -├── docs/ -│ └── index.md -│ └── docset.yml -└── ... -``` - - - - -## Set up preview environment - -:::{dropdown} .github/workflows/docs.yml -:open: -```markdown -name: docs - -on: - pull_request_target: - types: - - synchronize - - opened - - reopened - -permissions: - contents: read - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} - -jobs: - docs-preview: - uses: elastic/docs-builder/.github/workflows/preview.yml@feature/consumer-preview-action - permissions: - contents: read - id-token: write - deployments: write - with: - strict: false -``` - -::: - -:::{dropdown} .github/workflows/docs-cleanup.yml -:open: -```markdown -name: docs - -on: - pull_request_target: - types: - - closed - -jobs: - docs-preview: - uses: elastic/docs-builder/.github/workflows/preview-cleanup.yml@main - permissions: - contents: read - id-token: write - deployments: write -``` - -:::