sync-documentation #355
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: Sync Documentation Receiver | |
| on: | |
| repository_dispatch: | |
| types: [sync-documentation] | |
| permissions: {} | |
| jobs: | |
| sync-documentation: | |
| name: Sync Documentation | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| persist-credentials: false | |
| - name: Validate input | |
| id: validate | |
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | |
| with: | |
| script: | | |
| const payload = context.payload.client_payload || {}; | |
| const required = ['artifact-id', 'repository', 'run-id']; | |
| const missing = required.filter(field => !payload[field]); | |
| if (missing.length) { | |
| return core.setFailed(`Missing required inputs: ${missing.join(', ')}`); | |
| } | |
| if (typeof payload.repository !== 'string' || !payload.repository.includes('/')) { | |
| return core.setFailed(`Invalid repository slug: ${payload.repository}`); | |
| } | |
| core.debug(`Repository: ${payload.repository}`); | |
| core.setOutput('repository', payload.repository); | |
| core.debug(`Run ID: ${payload['run-id']}`); | |
| core.setOutput('run-id', payload['run-id']); | |
| core.debug(`Artifact ID: ${payload['artifact-id']}`); | |
| core.setOutput('artifact-id', payload['artifact-id']); | |
| - name: Resolve documentation target | |
| id: resolve | |
| uses: ./.github/actions/resolve-docs-target | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| repository: ${{ steps.validate.outputs.repository }} | |
| - name: Download documentation artifact | |
| id: download-artifact | |
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| artifact-ids: ${{ steps.validate.outputs.artifact-id }} | |
| path: ${{ runner.temp }}/documentation-download-${{ github.run_id }} | |
| repository: ${{ steps.validate.outputs.repository }} | |
| run-id: ${{ steps.validate.outputs.run-id }} | |
| - name: Prepare documentation content | |
| id: prepare-docs | |
| uses: ./.github/actions/prepare-docs | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| artifact-path: ${{ steps.download-artifact.outputs.download-path }} | |
| source-repository: ${{ steps.validate.outputs.repository }} | |
| run-id: ${{ steps.validate.outputs.run-id }} | |
| docs-path: ${{ steps.resolve.outputs.docs-path }} | |
| static-path: ${{ steps.resolve.outputs.static-path }} | |
| - name: Inject documentation | |
| uses: ./.github/actions/inject-docs | |
| with: | |
| source-repository: ${{ steps.validate.outputs.repository }} | |
| docs-path: ${{ steps.resolve.outputs.docs-path }} | |
| static-path: ${{ steps.resolve.outputs.static-path }} | |
| prepared-dir: ${{ steps.prepare-docs.outputs.output-path }} | |
| - name: Generate Documentation | |
| uses: ./.github/actions/generate-docs | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| - uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3.0.0 | |
| id: generate_token | |
| with: | |
| app-id: ${{ vars.CI_BOT_APP_ID }} | |
| private-key: ${{ secrets.CI_BOT_APP_PRIVATE_KEY }} | |
| - uses: hoverkraft-tech/ci-github-common/actions/create-and-merge-pull-request@4b53189212d5810f710bed89711002626977215b # 0.30.21 | |
| with: | |
| github-token: ${{ steps.generate_token.outputs.token }} | |
| branch: docs/sync-documentation-${{ github.event.client_payload.repository }} | |
| title: "docs(${{ github.event.client_payload.repository }}): update documentation" | |
| body: Update documentation for ${{ github.event.client_payload.repository }} | |
| commit-message: | | |
| docs(${{ github.event.client_payload.repository }}): update documentation | |
| - name: Summary | |
| if: always() | |
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | |
| env: | |
| STATUS: ${{ job.status }} | |
| SOURCE_REPOSITORY: ${{ steps.validate.outputs.repository }} | |
| ARTIFACT_ID: ${{ steps.validate.outputs.artifact-id }} | |
| DOCS_PATH: ${{ steps.resolve.outputs.docs-path }} | |
| STATIC_PATH: ${{ steps.resolve.outputs.static-path }} | |
| CATEGORY_NAME: ${{ steps.resolve.outputs.category-name }} | |
| CATEGORY_SLUG: ${{ steps.resolve.outputs.category-slug }} | |
| SOURCE_BRANCH: ${{ steps.prepare-docs.outputs.source-branch }} | |
| PROCESSED_FILES: ${{ steps.prepare-docs.outputs.processed-files }} | |
| with: | |
| script: | | |
| const files = process.env.PROCESSED_FILES ? JSON.parse(process.env.PROCESSED_FILES) : []; | |
| const statusText = process.env.STATUS === 'success' | |
| ? 'Documentation committed to public-docs' | |
| : 'Error occurred during documentation sync'; | |
| const filesSummary = files.length | |
| ? `Processed files:\n${files.join('\n')}` | |
| : 'No files were processed.'; | |
| const summaryBuilder = core.summary | |
| .addHeading('Documentation Sync Summary', 2) | |
| .addRaw('\n') | |
| .addList([ | |
| `Source Repository: ${process.env.SOURCE_REPOSITORY}`, | |
| `Source Branch: ${process.env.SOURCE_BRANCH}`, | |
| `Category: ${process.env.CATEGORY_NAME} (${process.env.CATEGORY_SLUG})`, | |
| `Docs Path: ${process.env.DOCS_PATH}`, | |
| `Static Path: ${process.env.STATIC_PATH}`, | |
| `Processed file(s): ${files.length}`, | |
| `Artifact: ${process.env.ARTIFACT_ID}`, | |
| `Status: ${statusText}` | |
| ]) | |
| .addRaw('\n'); | |
| if (files.length > 0) { | |
| summaryBuilder | |
| .addRaw("Processed files:") | |
| .addList(files); | |
| } else { | |
| summaryBuilder.addRaw("Processed files: no files were processed."); | |
| } | |
| summaryBuilder | |
| .addRaw('\n\n') | |
| .addRaw('Build and deployment will be handled by the push to main workflow.'); | |
| await summaryBuilder.write(); |