|
| 1 | +# Integrating with docs-preview-link Workflow |
| 2 | + |
| 3 | +This guide shows how to integrate the `docs-analysis` composite action with the existing `docs-preview-link.yml` workflow, eliminating duplication and consolidating documentation processing. |
| 4 | + |
| 5 | +## Current State |
| 6 | + |
| 7 | +The docs-preview-link.yml workflow currently embeds document analysis functionality directly in the workflow steps, which leads to: |
| 8 | +- Code duplication across workflows |
| 9 | +- Harder maintenance when metrics need to be updated |
| 10 | +- Inconsistent reporting between workflows |
| 11 | + |
| 12 | +## Integration Strategy |
| 13 | + |
| 14 | +We can refactor the `docs-preview-link.yml` workflow to use our new composite action, bringing these benefits: |
| 15 | +- Single source of truth for document analysis |
| 16 | +- Consistent metrics across all documentation workflows |
| 17 | +- Easier maintenance and feature additions |
| 18 | +- Improved security and error handling |
| 19 | + |
| 20 | +## Example Integration |
| 21 | + |
| 22 | +Here's how to replace the verify-docs-changes job in the docs-preview-link.yml workflow with our composite action: |
| 23 | + |
| 24 | +```yaml |
| 25 | +verify-docs-changes: |
| 26 | + needs: [validate-workflow, delay-start] |
| 27 | + runs-on: ubuntu-latest |
| 28 | + timeout-minutes: 3 # Reduced timeout for verification step |
| 29 | + if: | |
| 30 | + always() && |
| 31 | + (needs.validate-workflow.result == 'success' || needs.validate-workflow.result == 'skipped') |
| 32 | + permissions: |
| 33 | + contents: read |
| 34 | + pull-requests: read |
| 35 | + checks: write # For creating check runs |
| 36 | + statuses: write # For creating commit statuses |
| 37 | + if: | |
| 38 | + always() && ( |
| 39 | + (github.event_name == 'pull_request_target' && |
| 40 | + (github.event.pull_request.draft == false || contains(github.event.pull_request.labels.*.name, 'run-checks-on-draft'))) || |
| 41 | + (github.event_name == 'workflow_dispatch') || |
| 42 | + (github.event_name == 'issue_comment' && github.event.issue.pull_request && |
| 43 | + (contains(github.event.comment.body, '/docs-preview') || contains(github.event.comment.body, '/docs-help'))) |
| 44 | + ) |
| 45 | + outputs: |
| 46 | + docs_changed: ${{ steps.docs-analysis.outputs.docs-changed }} |
| 47 | + pr_number: ${{ steps.pr_info.outputs.pr_number }} |
| 48 | + branch_name: ${{ steps.pr_info.outputs.branch_name }} |
| 49 | + repo_owner: ${{ steps.pr_info.outputs.repo_owner }} |
| 50 | + is_fork: ${{ steps.pr_info.outputs.is_fork }} |
| 51 | + is_comment: ${{ steps.pr_info.outputs.is_comment }} |
| 52 | + is_manual: ${{ steps.pr_info.outputs.is_manual }} |
| 53 | + skip: ${{ steps.pr_info.outputs.skip }} |
| 54 | + execution_start_time: ${{ steps.timing.outputs.start_time }} |
| 55 | + has_non_docs_changes: ${{ steps.docs-analysis.outputs.has-non-docs-changes }} |
| 56 | + words_added: ${{ steps.docs-analysis.outputs.words-added }} |
| 57 | + words_removed: ${{ steps.docs-analysis.outputs.words-removed }} |
| 58 | + docs_files_count: ${{ steps.docs-analysis.outputs.docs-files-count }} |
| 59 | + images_added: ${{ steps.docs-analysis.outputs.images-added }} |
| 60 | + manifest_changed: ${{ steps.docs-analysis.outputs.manifest-changed }} |
| 61 | + format_only: ${{ steps.docs-analysis.outputs.format-only }} |
| 62 | + steps: |
| 63 | + # Start timing the execution for performance tracking |
| 64 | + - name: Capture start time |
| 65 | + id: timing |
| 66 | + run: | |
| 67 | + echo "start_time=$(date +%s)" >> $GITHUB_OUTPUT |
| 68 | + echo "::notice::Starting docs preview workflow at $(date)" |
| 69 | +
|
| 70 | + # Apply security hardening to the runner |
| 71 | + - name: Harden Runner |
| 72 | + uses: step-security/harden-runner@latest |
| 73 | + with: |
| 74 | + egress-policy: audit |
| 75 | + |
| 76 | + - name: Create verification check run |
| 77 | + id: create_check |
| 78 | + uses: actions/github-script@latest |
| 79 | + with: |
| 80 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 81 | + script: | |
| 82 | + // [existing script code...] |
| 83 | +
|
| 84 | + - name: Get PR info |
| 85 | + id: pr_info |
| 86 | + run: | |
| 87 | + # [existing script code to get PR number, branch, etc.] |
| 88 | +
|
| 89 | + # Only check out the DEFAULT branch (not the PR code) to verify changes safely |
| 90 | + - name: Check out base repository code |
| 91 | + if: steps.pr_info.outputs.skip != 'true' |
| 92 | + uses: actions/checkout@latest |
| 93 | + with: |
| 94 | + ref: main # Always use the main branch |
| 95 | + fetch-depth: 5 # Reduce checkout depth for faster runs |
| 96 | + sparse-checkout: | |
| 97 | + ${{ env.DOCS_PRIMARY_PATH }} |
| 98 | + *.md |
| 99 | + README.md |
| 100 | + sparse-checkout-cone-mode: false |
| 101 | + |
| 102 | + # NEW: Use our composite action instead of duplicate logic |
| 103 | + - name: Analyze documentation changes |
| 104 | + id: docs-analysis |
| 105 | + if: steps.pr_info.outputs.skip != 'true' |
| 106 | + uses: ./.github/actions/docs-analysis |
| 107 | + with: |
| 108 | + docs-path: ${{ env.DOCS_PRIMARY_PATH }} |
| 109 | + pr-ref: ${{ steps.pr_info.outputs.branch_name }} |
| 110 | + base-ref: 'main' |
| 111 | + significant-words-threshold: ${{ env.SIGNIFICANT_WORDS_THRESHOLD }} |
| 112 | + throttle-large-repos: 'true' |
| 113 | + debug-mode: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug == 'true' || 'false' }} |
| 114 | + |
| 115 | + # Remaining steps can use the outputs from docs-analysis |
| 116 | + - name: Update verification status |
| 117 | + if: github.event_name == 'pull_request_target' || (github.event_name == 'workflow_dispatch' && steps.pr_info.outputs.skip != 'true') |
| 118 | + uses: actions/github-script@latest |
| 119 | + with: |
| 120 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 121 | + script: | |
| 122 | + // [script modified to use step.docs-analysis outputs] |
| 123 | +``` |
| 124 | +
|
| 125 | +## Benefits of Integration |
| 126 | +
|
| 127 | +1. **Reduced Duplication**: The core document analysis logic is maintained in one place |
| 128 | +2. **Consistent Features**: All documentation workflows get the same analysis capabilities |
| 129 | +3. **Better Versioning**: Can pin to specific versions of the docs-analysis action |
| 130 | +4. **Cleaner Workflow Files**: Simplified workflow YAML with better separation of concerns |
| 131 | +5. **Improved Maintenance**: Changes to analysis logic only need to be made in one place |
| 132 | +6. **Common Security Model**: Same input validation and security practices across workflows |
| 133 | +
|
| 134 | +## Implementation Plan |
| 135 | +
|
| 136 | +1. Create a small PR with the composite action (completed) |
| 137 | +2. Test the action in isolation on sample PRs |
| 138 | +3. Create a new PR that refactors docs-preview-link.yml to use the composite action |
| 139 | +4. Refactor any other documentation workflows to use the same action |
| 140 | +5. Establish a process for maintaining the shared action |
0 commit comments