Add PR docs preview lifecycle via gh-pages #582
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: Docs | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '*/5 * * * *' | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - src/** | |
| - .github/scripts/** | |
| - .github/actions/update-index/** | |
| - .github/workflows/Docs.yml | |
| pull_request: | |
| types: | |
| - opened | |
| - reopened | |
| - synchronize | |
| - closed | |
| branches: | |
| - main | |
| paths: | |
| - src/** | |
| - .github/scripts/** | |
| - .github/workflows/Docs.yml | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| jobs: | |
| lint: | |
| name: Lint | |
| if: github.event_name == 'pull_request' && github.event.action != 'closed' | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| contents: read | |
| packages: read # super-linter: read packages | |
| statuses: write # super-linter: report status checks | |
| pull-requests: write # super-linter: post PR summary comment | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| - name: Lint code base | |
| uses: super-linter/super-linter@4ce20838b8ab83717e78138c5b3a1407148e0918 # v8.7.0 | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| ENABLE_GITHUB_ACTIONS_STEP_SUMMARY: true | |
| ENABLE_GITHUB_PULL_REQUEST_SUMMARY_COMMENT: true | |
| SAVE_SUPER_LINTER_SUMMARY: true | |
| VALIDATE_BIOME_LINT: false | |
| VALIDATE_BIOME_FORMAT: false | |
| VALIDATE_JSCPD: false | |
| VALIDATE_JSON_PRETTIER: false | |
| VALIDATE_MARKDOWN_PRETTIER: false | |
| VALIDATE_YAML_PRETTIER: false | |
| VALIDATE_HTML_PRETTIER: false | |
| publish: | |
| name: Publish | |
| if: github.event_name != 'pull_request' | |
| runs-on: ubuntu-24.04 | |
| environment: | |
| name: github-pages | |
| url: https://psmodule.io/docs/ | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | |
| with: | |
| persist-credentials: false | |
| - name: Create GitHub App token | |
| id: app-token | |
| uses: actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2 | |
| with: | |
| app-id: ${{ secrets.SCRIBBLER_BOT_CLIENT_ID }} | |
| private-key: ${{ secrets.SCRIBBLER_BOT_PRIVATE_KEY }} | |
| permission-contents: write | |
| - name: Update index | |
| uses: ./.github/actions/update-index | |
| with: | |
| ClientID: ${{ secrets.SCRIBBLER_BOT_CLIENT_ID }} # zizmor: ignore[secrets-outside-env] | |
| PrivateKey: ${{ secrets.SCRIBBLER_BOT_PRIVATE_KEY }} # zizmor: ignore[secrets-outside-env] | |
| - name: Set up Python | |
| uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0 | |
| with: | |
| python-version: 3.x | |
| - name: Install Zensical | |
| run: pip install zensical | |
| - name: Build Zensical project | |
| run: zensical build --clean | |
| working-directory: src | |
| - name: Publish live docs | |
| id: publish-live | |
| shell: pwsh | |
| env: | |
| REPOSITORY: ${{ github.repository }} | |
| APP_TOKEN: ${{ steps.app-token.outputs.token }} | |
| COMMIT_SHA: ${{ github.sha }} | |
| run: | | |
| ./.github/scripts/docs/Publish-LiveDocs.ps1 ` | |
| -Repository $env:REPOSITORY ` | |
| -Token $env:APP_TOKEN ` | |
| -BuildDirectory "$PWD/src/site" ` | |
| -CommitSha $env:COMMIT_SHA | |
| preview: | |
| name: Preview | |
| if: github.event_name == 'pull_request' && github.event.action != 'closed' | |
| needs: [lint] | |
| runs-on: ubuntu-24.04 | |
| environment: | |
| name: pr-preview-${{ github.event.number }} | |
| url: ${{ steps.preview-url.outputs.url }} | |
| permissions: | |
| contents: write | |
| deployments: write | |
| issues: write | |
| env: | |
| PREVIEW_URL: https://psmodule.io/docs/previews/pr-${{ github.event.number }}/ | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | |
| with: | |
| persist-credentials: false | |
| - name: Create GitHub App token | |
| id: app-token | |
| uses: actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2 | |
| with: | |
| app-id: ${{ secrets.SCRIBBLER_BOT_CLIENT_ID }} | |
| private-key: ${{ secrets.SCRIBBLER_BOT_PRIVATE_KEY }} | |
| permission-contents: write | |
| permission-issues: write | |
| - name: Update index | |
| uses: ./.github/actions/update-index | |
| with: | |
| ClientID: ${{ secrets.SCRIBBLER_BOT_CLIENT_ID }} # zizmor: ignore[secrets-outside-env] | |
| PrivateKey: ${{ secrets.SCRIBBLER_BOT_PRIVATE_KEY }} # zizmor: ignore[secrets-outside-env] | |
| - name: Set up Python | |
| uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0 | |
| with: | |
| python-version: 3.x | |
| - name: Install Zensical | |
| run: pip install zensical | |
| - name: Build preview site | |
| shell: pwsh | |
| env: | |
| PREVIEW_SITE_URL: ${{ env.PREVIEW_URL }} | |
| run: | | |
| ./.github/scripts/docs/Set-ZensicalSiteUrl.ps1 -ConfigPath "$PWD/zensical.toml" -SiteUrl $env:PREVIEW_SITE_URL | |
| zensical build --clean | |
| working-directory: src | |
| - name: Publish preview docs | |
| id: preview-url | |
| shell: pwsh | |
| env: | |
| REPOSITORY: ${{ github.repository }} | |
| APP_TOKEN: ${{ steps.app-token.outputs.token }} | |
| PR_NUMBER: ${{ github.event.number }} | |
| PREVIEW_SITE_URL: ${{ env.PREVIEW_URL }} | |
| run: | | |
| ./.github/scripts/docs/Publish-PreviewDocs.ps1 ` | |
| -Repository $env:REPOSITORY ` | |
| -Token $env:APP_TOKEN ` | |
| -PullRequestNumber $env:PR_NUMBER ` | |
| -PreviewUrl $env:PREVIEW_SITE_URL ` | |
| -BuildDirectory "$PWD/src/site" | |
| preview-cleanup: | |
| name: Preview cleanup | |
| if: github.event_name == 'pull_request' && github.event.action == 'closed' | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| contents: write | |
| deployments: write | |
| issues: write | |
| env: | |
| PREVIEW_URL: https://psmodule.io/docs/previews/pr-${{ github.event.number }}/ | |
| PREVIEW_ENVIRONMENT: pr-preview-${{ github.event.number }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | |
| with: | |
| persist-credentials: false | |
| - name: Create GitHub App token | |
| id: app-token | |
| uses: actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2 | |
| with: | |
| app-id: ${{ secrets.SCRIBBLER_BOT_CLIENT_ID }} | |
| private-key: ${{ secrets.SCRIBBLER_BOT_PRIVATE_KEY }} | |
| permission-administration: write | |
| permission-contents: write | |
| permission-deployments: write | |
| permission-issues: write | |
| - name: Cleanup preview resources | |
| shell: pwsh | |
| env: | |
| REPOSITORY: ${{ github.repository }} | |
| APP_TOKEN: ${{ steps.app-token.outputs.token }} | |
| PR_NUMBER: ${{ github.event.number }} | |
| PREVIEW_SITE_URL: ${{ env.PREVIEW_URL }} | |
| PREVIEW_ENV: ${{ env.PREVIEW_ENVIRONMENT }} | |
| run: | | |
| ./.github/scripts/docs/Cleanup-PreviewDocs.ps1 ` | |
| -Repository $env:REPOSITORY ` | |
| -Token $env:APP_TOKEN ` | |
| -PullRequestNumber $env:PR_NUMBER ` | |
| -PreviewUrl $env:PREVIEW_SITE_URL ` | |
| -EnvironmentName $env:PREVIEW_ENV |