|
| 1 | +name: Upload Preview Build to Netlify |
| 2 | +on: |
| 3 | + workflow_run: |
| 4 | + workflows: ["Layered Preview Build"] |
| 5 | + types: |
| 6 | + - completed |
| 7 | +jobs: |
| 8 | + build: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + if: > |
| 11 | + ${{ github.event.workflow_run.conclusion == 'success' }} |
| 12 | + steps: |
| 13 | + # There's a 'download artifact' action but it hasn't been updated for the |
| 14 | + # workflow_run action (https://github.com/actions/download-artifact/issues/60) |
| 15 | + # so instead we get this mess: |
| 16 | + - name: 'Download artifact' |
| 17 | + |
| 18 | + with: |
| 19 | + script: | |
| 20 | + var artifacts = await github.actions.listWorkflowRunArtifacts({ |
| 21 | + owner: context.repo.owner, |
| 22 | + repo: context.repo.repo, |
| 23 | + run_id: ${{github.event.workflow_run.id }}, |
| 24 | + }); |
| 25 | + var matchArtifact = artifacts.data.artifacts.filter((artifact) => { |
| 26 | + return artifact.name == "previewbuild" |
| 27 | + })[0]; |
| 28 | + var download = await github.actions.downloadArtifact({ |
| 29 | + owner: context.repo.owner, |
| 30 | + repo: context.repo.repo, |
| 31 | + artifact_id: matchArtifact.id, |
| 32 | + archive_format: 'zip', |
| 33 | + }); |
| 34 | + var fs = require('fs'); |
| 35 | + fs.writeFileSync('${{github.workspace}}/previewbuild.zip', Buffer.from(download.data)); |
| 36 | + - run: unzip previewbuild.zip && rm previewbuild.zip |
| 37 | + - name: Deploy to Netlify |
| 38 | + |
| 39 | + with: |
| 40 | + publish-dir: . |
| 41 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + deploy-message: "Deploy from GitHub Actions" |
| 43 | + enable-pull-request-comment: true |
| 44 | + enable-commit-comment: false |
| 45 | + overwrites-pull-request-comment: true |
| 46 | + env: |
| 47 | + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} |
| 48 | + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} |
| 49 | + timeout-minutes: 1 |
| 50 | + |
0 commit comments