|
| 1 | +name: Deploy to GitHub Pages |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["docs", "Code Coverage"] |
| 6 | + types: |
| 7 | + - completed |
| 8 | + branches: |
| 9 | + - main |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + pages: write |
| 14 | + id-token: write |
| 15 | + |
| 16 | +concurrency: |
| 17 | + group: pages-${{ github.ref }} |
| 18 | + cancel-in-progress: true |
| 19 | + |
| 20 | +jobs: |
| 21 | + deploy: |
| 22 | + name: Deploy Combined Site |
| 23 | + runs-on: ubuntu-latest |
| 24 | + if: github.event.workflow_run.conclusion == 'success' |
| 25 | + |
| 26 | + environment: |
| 27 | + name: github-pages |
| 28 | + url: ${{ steps.deployment.outputs.page_url }} |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Setup Pages |
| 32 | + uses: actions/configure-pages@v4 |
| 33 | + |
| 34 | + - name: Find latest successful workflow runs |
| 35 | + id: find-runs |
| 36 | + uses: actions/github-script@v7 |
| 37 | + with: |
| 38 | + script: | |
| 39 | + // Find latest successful docs run |
| 40 | + const { data: runs } = await github.rest.actions.listWorkflowRuns({ |
| 41 | + owner: context.repo.owner, |
| 42 | + repo: context.repo.repo, |
| 43 | + workflow_id: 'docs.yml', |
| 44 | + status: 'completed', |
| 45 | + conclusion: 'success', |
| 46 | + branch: 'main', |
| 47 | + per_page: 1 |
| 48 | + }); |
| 49 | + const docsRun = runs.workflow_runs[0]; |
| 50 | +
|
| 51 | + // Find latest successful coverage run |
| 52 | + const { data: coverageRuns } = await github.rest.actions.listWorkflowRuns({ |
| 53 | + owner: context.repo.owner, |
| 54 | + repo: context.repo.repo, |
| 55 | + workflow_id: 'coverage.yml', |
| 56 | + status: 'completed', |
| 57 | + conclusion: 'success', |
| 58 | + branch: 'main', |
| 59 | + per_page: 1 |
| 60 | + }); |
| 61 | + const coverageRun = coverageRuns.workflow_runs[0]; |
| 62 | +
|
| 63 | + if (!docsRun && !coverageRun) { |
| 64 | + core.setFailed('No successful runs found for either workflow'); |
| 65 | + return; |
| 66 | + } |
| 67 | +
|
| 68 | + if (docsRun) { |
| 69 | + core.setOutput('docs-run-id', docsRun.id); |
| 70 | + core.setOutput('has-docs', 'true'); |
| 71 | + console.log(`Found docs run: ${docsRun.id}`); |
| 72 | + } else { |
| 73 | + core.setOutput('has-docs', 'false'); |
| 74 | + console.log('No successful docs run found, skipping docs'); |
| 75 | + } |
| 76 | +
|
| 77 | + if (coverageRun) { |
| 78 | + core.setOutput('coverage-run-id', coverageRun.id); |
| 79 | + core.setOutput('has-coverage', 'true'); |
| 80 | + console.log(`Found coverage run: ${coverageRun.id}`); |
| 81 | + } else { |
| 82 | + core.setOutput('has-coverage', 'false'); |
| 83 | + console.log('No successful coverage run found, skipping coverage'); |
| 84 | + } |
| 85 | +
|
| 86 | + - name: Download docs artifact |
| 87 | + if: steps.find-runs.outputs.has-docs == 'true' |
| 88 | + uses: actions/download-artifact@v4 |
| 89 | + with: |
| 90 | + name: docs-reports |
| 91 | + path: ./site/ |
| 92 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 93 | + run-id: ${{ steps.find-runs.outputs.docs-run-id }} |
| 94 | + |
| 95 | + - name: Download coverage artifact |
| 96 | + if: steps.find-runs.outputs.has-coverage == 'true' |
| 97 | + uses: actions/download-artifact@v4 |
| 98 | + with: |
| 99 | + name: coverage-reports |
| 100 | + path: ./site/coverage/ |
| 101 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 102 | + run-id: ${{ steps.find-runs.outputs.coverage-run-id }} |
| 103 | + |
| 104 | + - name: Upload combined site |
| 105 | + uses: actions/upload-pages-artifact@v4 |
| 106 | + with: |
| 107 | + path: ./site/ |
| 108 | + |
| 109 | + - name: Deploy to GitHub Pages |
| 110 | + id: deployment |
| 111 | + uses: actions/deploy-pages@v4 |
0 commit comments