Skip to content

Rename docs-mover to Elastic.Markdown.Refactor #185

Rename docs-mover to Elastic.Markdown.Refactor

Rename docs-mover to Elastic.Markdown.Refactor #185

Workflow file for this run

name: preview-build
on:
pull_request:
types:
- opened
- synchronize
- reopened
- labeled
- unlabeled
push:
branches:
- main
workflow_call:
inputs:
strict:
description: 'Treat warnings as errors'
type: string
default: 'true'
continue-on-error:
description: 'Do not fail to publish if build fails'
type: string
required: false
default: 'true'
path-pattern:
description: 'Path pattern to filter files. Only if changed files match the pattern, the workflow will continue.'
type: string
default: '**'
required: false
permissions:
contents: read
pull-requests: read
jobs:
build:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
runs-on: ubuntu-latest
steps:
- name: Get changed files
if: github.event_name == 'pull_request'
id: check-files
uses: tj-actions/changed-files@d6e91a2266cdb9d62096cebf1e8546899c6aa18f # v45.0.6
with:
files: ${{ inputs.path-pattern != '' && inputs.path-pattern || '**' }}
- name: Checkout
if: github.event_name != 'pull_request' || steps.check-files.outputs.any_changed == 'true'
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Generate path prefix
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
case "${GITHUB_EVENT_NAME}" in
"pull_request")
echo "PATH_PREFIX=/${GITHUB_REPOSITORY}/pull/${PR_NUMBER}" >> $GITHUB_ENV
;;
"push")
echo "PATH_PREFIX=/${GITHUB_REPOSITORY}/tree/${GITHUB_REF_NAME}" >> $GITHUB_ENV
if [[ ! "${GITHUB_REF_NAME}" =~ ^(main|master|16\.x)$ ]]; then
echo "Unsupported ref name: ${GITHUB_REF_NAME}";
exit 1;
fi
;;
*)
echo "Unsupported event: ${GITHUB_EVENT_NAME}";
exit 1;
;;
esac
- name: Store deployment metadata
id: metadata
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
SHOULD_DEPLOY: ${{ github.event_name == 'pull_request' && steps.check-files.outputs.any_changed || 'true' }}
run: |
cat << EOF > deployment_metadata.json
{
"pr_number": "${PR_NUMBER}",
"ref": "${REF}",
"should_deploy": "${SHOULD_DEPLOY}",
"path_prefix": "${PATH_PREFIX}"
}
EOF
echo "should_deploy=${SHOULD_DEPLOY}" >> "${GITHUB_OUTPUT}"
- name: Upload deployment metadata
uses: actions/upload-artifact@v4
with:
name: deployment_metadata
path: deployment_metadata.json
if-no-files-found: error
retention-days: 1
compression-level: 1
- name: Bootstrap Action Workspace
if: github.repository == 'elastic/docs-builder' && steps.metadata.outputs.should_deploy == 'true'
uses: ./.github/actions/bootstrap
- name: Set REDESIGN feature flag
if: contains(github.event.pull_request.labels.*.name, 'redesign')
run: echo "REDESIGN=true" >> $GITHUB_ENV
# 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' && steps.metadata.outputs.should_deploy == 'true'
run: |
dotnet run --project src/docs-builder -- --strict --path-prefix "${PATH_PREFIX}"
- name: Build documentation
if: github.repository != 'elastic/docs-builder' && steps.metadata.outputs.should_deploy == 'true'
uses: elastic/docs-builder@main
continue-on-error: ${{ fromJSON(inputs.continue-on-error != '' && inputs.continue-on-error || 'false') }}
with:
prefix: ${{ env.PATH_PREFIX }}
strict: ${{ fromJSON(inputs.strict != '' && inputs.strict || 'true') }}
- uses: actions/upload-artifact@v4
if: steps.metadata.outputs.should_deploy == 'true'
with:
name: docs
path: .artifacts/docs/html/
if-no-files-found: error
retention-days: 1
# The lower the compression-level, the faster the artifact will be uploaded.
# But the size of the artifact will be larger.
compression-level: 1