netlify-deploy #1501
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
| # This runs as a separate job because it needs to run on the `workflow_run` event | |
| # in order to access the netlify secrets. | |
| # | |
| # This is safe because this doesn't run arbitrary code from PRs. | |
| name: netlify-deploy | |
| on: | |
| workflow_run: | |
| workflows: ["netlify-build"] | |
| types: | |
| - completed | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| if: github.event.workflow_run.conclusion == 'success' | |
| environment: netlify | |
| steps: | |
| - name: Download Build Artifact | |
| uses: actions/download-artifact@v7 | |
| with: | |
| name: site | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| run-id: ${{ github.event.workflow_run.id }} | |
| - name: Install netlify-cli | |
| run: | | |
| npm install -g netlify-cli | |
| - name: Deploy to Netlify | |
| run: | | |
| ls -la | |
| DEBUG=* netlify deploy \ | |
| --site ${{ secrets.NETLIFY_SITE_ID }} \ | |
| --auth ${{ secrets.NETLIFY_TOKEN }} \ | |
| ${{ ((github.event.workflow_run.head_repository.full_name == 'PyO3/pyo3') && (github.event.workflow_run.head_branch == 'main') && '--prod') || '' }} \ | |
| --json | tee deploy_output.json | |
| # credit: https://www.raulmelo.me/en/blog/deploying-netlify-github-actions-guide | |
| - name: Generate URL Preview | |
| id: url_preview | |
| if: ${{ github.event.workflow_run.event == 'pull_request' }} | |
| run: | | |
| NETLIFY_PREVIEW_URL=$(jq -r '.deploy_url' deploy_output.json) | |
| echo "NETLIFY_PREVIEW_URL=$NETLIFY_PREVIEW_URL" >> "$GITHUB_OUTPUT" | |
| - name: Post Netlify Preview Status to PR | |
| if: ${{ github.event.workflow_run.event == 'pull_request' }} | |
| uses: actions/github-script@v8 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const previewUrl = '${{ steps.url_preview.outputs.NETLIFY_PREVIEW_URL }}'; | |
| const commitSha = '${{ github.event.workflow_run.head_sha }}'; | |
| await github.rest.repos.createCommitStatus({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| sha: commitSha, | |
| state: 'success', | |
| target_url: previewUrl, | |
| description: 'click to view Netlify preview deploy', | |
| context: 'netlify-deploy / preview' | |
| }); |