Skip to content

Commit e7a2c65

Browse files
committed
fix: Skip Netlify deployment for Dependabot PRs
Dependabot PRs cannot access repository secrets due to GitHub's security model. This causes the Netlify preview deployment to fail with 'Unauthorized' errors. Changes: - Add conditional check to skip Netlify deploy when actor is dependabot[bot] - Also skip for PRs from forks or when secrets are unavailable - Add informative skip message step for transparency - Only post PR comment when deployment actually succeeds - Move secrets to job-level env for proper conditional access This ensures: - Dependabot PRs pass CI without Netlify preview (acceptable trade-off) - Regular contributor PRs continue to get Netlify previews - No security risks from exposing secrets to untrusted actors - Clear logging when deployment is skipped Fixes the issue reported in PR #659
1 parent 6e967af commit e7a2c65

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ on:
1111
jobs:
1212
preview:
1313
runs-on: "runs-on=${{ github.run_id }}/family=g4dn.2xlarge/image=quantecon_ubuntu2404/disk=large"
14+
env:
15+
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
16+
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
1417
steps:
1518
- uses: actions/checkout@v5
1619
with:
@@ -168,6 +171,11 @@ jobs:
168171
fi
169172
- name: Preview Deploy to Netlify
170173
id: netlify-deploy
174+
if: >
175+
github.actor != 'dependabot[bot]' &&
176+
(github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) &&
177+
env.NETLIFY_AUTH_TOKEN != '' &&
178+
env.NETLIFY_SITE_ID != ''
171179
shell: bash -l {0}
172180
run: |
173181
if [ "${{ github.event_name }}" = "pull_request" ]; then
@@ -238,11 +246,16 @@ jobs:
238246
echo "🎯 Preview page: ${deploy_url}/${{ github.event.inputs.preview_page }}"
239247
fi
240248
fi
241-
env:
242-
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
243-
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
249+
- name: Skip Netlify Deploy (no secrets or untrusted actor)
250+
if: >
251+
!(github.actor != 'dependabot[bot]' &&
252+
(github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) &&
253+
env.NETLIFY_AUTH_TOKEN != '' &&
254+
env.NETLIFY_SITE_ID != '')
255+
run: |
256+
echo "Skipping Netlify preview deploy: secrets unavailable or actor not trusted (actor=${{ github.actor }})"
244257
- name: Post PR Comment with Preview Links
245-
if: github.event_name == 'pull_request'
258+
if: github.event_name == 'pull_request' && steps.netlify-deploy.outputs.deploy_url != ''
246259
uses: actions/github-script@v7
247260
with:
248261
script: |

0 commit comments

Comments
 (0)