|
| 1 | +# Triggers after the documentation build has finished, |
| 2 | +# taking the artifact and uploading it to netlify |
| 3 | +name: Publish documentation |
| 4 | + |
| 5 | +on: |
| 6 | + workflow_run: |
| 7 | + workflows: ["Build documentation"] |
| 8 | + types: |
| 9 | + - completed |
| 10 | + |
| 11 | +permissions: |
| 12 | + statuses: write |
| 13 | + checks: write |
| 14 | + pull-requests: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + upload-docs: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + if: github.event.workflow_run.conclusion == 'success' |
| 20 | + steps: |
| 21 | + - name: Get information about workflow origin |
| 22 | + uses: potiuk/get-workflow-origin@v1_5 |
| 23 | + id: source-run-info |
| 24 | + with: |
| 25 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 26 | + sourceRunId: ${{ github.event.workflow_run.id }} |
| 27 | + |
| 28 | + # Once https://github.com/actions/download-artifact/issues/172 and/or https://github.com/actions/download-artifact/issues/60 is implemented, we can use the official download-artifact action |
| 29 | + # For now use the solution from https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#using-data-from-the-triggering-workflow |
| 30 | + - name: Download docs |
| 31 | + |
| 32 | + with: |
| 33 | + script: | |
| 34 | + var artifacts = await github.actions.listWorkflowRunArtifacts({ |
| 35 | + owner: context.repo.owner, |
| 36 | + repo: context.repo.repo, |
| 37 | + run_id: ${{github.event.workflow_run.id }}, |
| 38 | + }); |
| 39 | + var matchArtifact = artifacts.data.artifacts.filter((artifact) => { |
| 40 | + return artifact.name == "docs" |
| 41 | + })[0]; |
| 42 | + var download = await github.actions.downloadArtifact({ |
| 43 | + owner: context.repo.owner, |
| 44 | + repo: context.repo.repo, |
| 45 | + artifact_id: matchArtifact.id, |
| 46 | + archive_format: 'zip', |
| 47 | + }); |
| 48 | + var fs = require('fs'); |
| 49 | + fs.writeFileSync('${{github.workspace}}/docs.zip', Buffer.from(download.data)); |
| 50 | + |
| 51 | + - name: Extract docs |
| 52 | + run: unzip docs.zip -d docs && unzip docs/docs.zip -d docs/docs |
| 53 | + |
| 54 | + - name: Deploy to Netlify |
| 55 | + id: deploy-netlify |
| 56 | + uses: netlify/actions/cli@master |
| 57 | + with: |
| 58 | + args: deploy --dir=docs/docs/docs ${NETLIFY_PRODUCTION:+"--prod"} --message ${NETLIFY_MESSAGE} --alias ${NETLIFY_ALIAS} |
| 59 | + env: |
| 60 | + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} |
| 61 | + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} |
| 62 | + NETLIFY_PRODUCTION: ${{ github.ref == 'refs/heads/develop' }} |
| 63 | + NETLIFY_MESSAGE: ${{ steps.source-run-info.outputs.pullRequestNumber }} |
| 64 | + NETLIFY_ALIAS: deploy-preview-${{ steps.source-run-info.outputs.pullRequestNumber }} |
| 65 | + |
| 66 | + # Add deployment as status check, PR comment and annotation |
| 67 | + # we could use the nwtgck/actions-netlify action for that, except for that it is not (yet) working in workflow_run context: https://github.com/nwtgck/actions-netlify/issues/545 |
| 68 | + - name: Add/Update deployment status PR comment |
| 69 | + uses: marocchino/sticky-pull-request-comment@v2 |
| 70 | + with: |
| 71 | + number: ${{ steps.source-run-info.outputs.pullRequestNumber }} |
| 72 | + header: preview-comment |
| 73 | + recreate: true |
| 74 | + message: | |
| 75 | + [Documentation preview for this PR](${{ steps.deploy-netlify.outputs.NETLIFY_URL }}) is ready! :tada: |
| 76 | + Built with commit: ${{ steps.source-run-info.outputs.sourceHeadSha }} |
| 77 | + |
| 78 | + - name: Update deployment status PR check |
| 79 | + uses: myrotvorets/[email protected] |
| 80 | + if: ${{ always() }} |
| 81 | + env: |
| 82 | + DEPLOY_SUCCESS: Successfully deployed preview. |
| 83 | + DEPLOY_FAILURE: Failed to deploy preview. |
| 84 | + with: |
| 85 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 86 | + status: ${{ job.status == 'success' && 'success' || 'failure' }} |
| 87 | + sha: ${{ github.event.workflow_run.head_sha }} |
| 88 | + context: Deploy Documentation |
| 89 | + targetUrl: ${{ steps.deploy-netlify.outputs.NETLIFY_URL }} |
| 90 | + description: ${{ job.status == 'success' && env.DEPLOY_SUCCESS || env.DEPLOY_FAILURE }} |
| 91 | + |
| 92 | + - name: Report deployment url |
| 93 | + run: | |
| 94 | + echo "::notice::The documentation has being automatically deployed to Netlify. %0A ✅ Preview: ${{ steps.deploy-netlify.outputs.NETLIFY_URL }}" |
| 95 | +
|
0 commit comments