diff --git a/.github/workflows/docs-autogen.yml b/.github/workflows/docs-autogen.yml new file mode 100644 index 000000000..cd7f54f8b --- /dev/null +++ b/.github/workflows/docs-autogen.yml @@ -0,0 +1,456 @@ +name: Docs Autogen + +on: + push: + branches: + - main + tags: + - 'v[0-9]*.[0-9]*.[0-9]*' + - '[0-9]*.[0-9]*.[0-9]*' + workflow_dispatch: + inputs: + task_type: + description: Run Preview docs or Archive docs. + required: true + type: choice + default: preview + options: + - preview + - archive + head_ref: + description: Preview head commit/ref. Defaults to the workflow commit. + required: false + type: string + base_ref: + description: Preview base commit/ref. Defaults to the parent of head_ref for manual runs. + required: false + type: string + release_tag: + description: Archive release tag, for example v1.1.23 or 1.1.23. + required: false + type: string + previous_tag: + description: Previous release tag. Auto-detected when omitted. + required: false + type: string + output_mode: + description: Runtime output mode. + required: false + type: choice + default: commit_and_mr + options: + - commit_and_mr + - commit_only + - commit_mr_and_merge + +permissions: + contents: read + +concurrency: + group: veadk-docs-autogen-${{ github.ref }} + cancel-in-progress: false + +env: + DOCS_RUNTIME_ENDPOINT: ${{ vars.DOCS_RUNTIME_ENDPOINT }} + DOCS_RUNTIME_API_KEY: ${{ secrets.DOCS_RUNTIME_API_KEY }} + DOCS_OUTPUT_MODE: ${{ vars.DOCS_OUTPUT_MODE || 'commit_and_mr' }} + DOCS_TASK_TIMEOUT_SECONDS: ${{ vars.DOCS_TASK_TIMEOUT_SECONDS || '7200' }} + DOCS_TASK_POLL_INTERVAL_SECONDS: ${{ vars.DOCS_TASK_POLL_INTERVAL_SECONDS || '30' }} + DOCS_PREVIEW_METADATA_WAIT_SECONDS: ${{ vars.DOCS_PREVIEW_METADATA_WAIT_SECONDS || '300' }} + DOCS_PREVIEW_METADATA_POLL_INTERVAL_SECONDS: ${{ vars.DOCS_PREVIEW_METADATA_POLL_INTERVAL_SECONDS || '30' }} + SOURCE_REPO_URL: ${{ github.server_url }}/${{ github.repository }}.git + +jobs: + preview: + name: Generate Preview docs + if: > + (github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'volcengine/veadk-python') || + (github.event_name == 'workflow_dispatch' && inputs.task_type == 'preview') + runs-on: ubuntu-latest + timeout-minutes: 240 + steps: + - name: Checkout source metadata + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.event_name == 'workflow_dispatch' && inputs.head_ref || github.sha }} + + - name: Resolve preview refs + id: refs + env: + EVENT_BEFORE: ${{ github.event.before }} + INPUT_HEAD_REF: ${{ inputs.head_ref }} + INPUT_BASE_REF: ${{ inputs.base_ref }} + run: | + set -euo pipefail + + head_ref="${INPUT_HEAD_REF:-HEAD}" + head_sha="$(git rev-parse "${head_ref}^{commit}")" + + base_ref="${INPUT_BASE_REF:-${EVENT_BEFORE:-}}" + if [[ -z "$base_ref" || "$base_ref" =~ ^0+$ ]]; then + base_ref="$(git rev-list --parents -n 1 "$head_sha" | awk '{print $2}')" + fi + if [[ -z "$base_ref" ]]; then + echo "Unable to resolve preview base ref for $head_sha" >&2 + exit 1 + fi + base_sha="$(git rev-parse "${base_ref}^{commit}")" + + echo "head_ref=$head_sha" >> "$GITHUB_OUTPUT" + echo "base_ref=$base_sha" >> "$GITHUB_OUTPUT" + + - name: Submit docs task + env: + DOCS_PROJECT: veadk + TASK_TYPE: autogen + BASE_REF: ${{ steps.refs.outputs.base_ref }} + HEAD_REF: ${{ steps.refs.outputs.head_ref }} + PREVIEW_BASE_REF: ${{ steps.refs.outputs.base_ref }} + REQUEST_ID: ${{ github.run_id }}-${{ github.run_attempt }} + INPUT_OUTPUT_MODE: ${{ inputs.output_mode }} + run: | + set -euo pipefail + + if [[ -z "${DOCS_RUNTIME_ENDPOINT:-}" ]]; then + echo "Repository variable DOCS_RUNTIME_ENDPOINT is required." >&2 + exit 1 + fi + if [[ -z "${DOCS_RUNTIME_API_KEY:-}" ]]; then + echo "Repository secret DOCS_RUNTIME_API_KEY is required." >&2 + exit 1 + fi + + output_mode="${INPUT_OUTPUT_MODE:-$DOCS_OUTPUT_MODE}" + runtime_timeout=$((DOCS_TASK_TIMEOUT_SECONDS + 600)) + runtime_endpoint="${DOCS_RUNTIME_ENDPOINT%/}" + + command="$(cat <