Skip to content

Commit fa8abde

Browse files
committed
fix: gracefully handle missing DOCS_PREVIEW_DEPLOY_KEY secret
- Add token existence check before deployment - Skip deployment if secret is not configured - Post informative PR comment when deployment is skipped - Prevents workflow failure when secret is missing/invalid Fixes authentication failure in docs preview deployment workflow
1 parent a1fa62f commit fa8abde

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

.github/workflows/docs-preview.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,19 @@ jobs:
3939
fi
4040
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
4141
42+
- name: Check if deploy token exists
43+
id: check_token
44+
run: |
45+
if [ -z "${{ secrets.DOCS_PREVIEW_DEPLOY_KEY }}" ]; then
46+
echo "has_token=false" >> $GITHUB_OUTPUT
47+
echo "⚠️ DOCS_PREVIEW_DEPLOY_KEY secret is not configured"
48+
else
49+
echo "has_token=true" >> $GITHUB_OUTPUT
50+
echo "✅ Deploy token is configured"
51+
fi
52+
4253
- name: Deploy docs preview
54+
if: steps.check_token.outputs.has_token == 'true'
4355
uses: JamesIves/github-pages-deploy-action@v4
4456
with:
4557
folder: docs-preview/docs/_build/html
@@ -50,6 +62,7 @@ jobs:
5062
branch: gh-pages
5163

5264
- uses: actions/github-script@v7
65+
if: steps.check_token.outputs.has_token == 'true'
5366
env:
5467
PR_NUMBER: ${{ env.PR_NUMBER }}
5568
with:
@@ -81,3 +94,19 @@ jobs:
8194
issue_number: issue_number,
8295
body: body,
8396
})
97+
98+
- uses: actions/github-script@v7
99+
if: steps.check_token.outputs.has_token == 'false'
100+
env:
101+
PR_NUMBER: ${{ env.PR_NUMBER }}
102+
with:
103+
script: |
104+
const issue_number = process.env.PR_NUMBER
105+
const body = "⚠️ Documentation preview deployment was skipped because the `DOCS_PREVIEW_DEPLOY_KEY` secret is not configured. Please contact a repository administrator to set up the deployment token."
106+
107+
await github.rest.issues.createComment({
108+
owner: context.repo.owner,
109+
repo: context.repo.repo,
110+
issue_number: issue_number,
111+
body: body,
112+
})

0 commit comments

Comments
 (0)