Skip to content

Commit 82f2dd3

Browse files
committed
feat(Deploy): allow gh-pages deploy action to work in forks
1 parent 70a0378 commit 82f2dd3

1 file changed

Lines changed: 26 additions & 6 deletions

File tree

‎.github/workflows/deploy-ghpages.yml‎

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
# Deploys the static app to GitHub Pages.
2-
# Triggered on push to `main`.
2+
# Triggered on push to `main`, or can be triggered manually with specific branch.
33
# Requires the secrets (`CI_APP_ID`, `CI_APP_PRIVATE_KEY`) to be configured.
44

55
name: Deploy to GitHub Pages
66
on:
77
push:
88
branches:
99
- main
10+
- deploy-to-php
11+
workflow_dispatch:
12+
inputs:
13+
branch:
14+
description: "Branch to deploy"
15+
required: false
16+
default: "main"
17+
18+
permissions:
19+
contents: write
1020

1121
env:
1222
NODE_VERSION: 24.x
@@ -17,7 +27,16 @@ jobs:
1727
env:
1828
NODE_OPTIONS: "--max_old_space_size=8192"
1929
steps:
20-
- name: Generate Github Token for CI Bot
30+
- name: Check GitHub App secrets
31+
id: check-secrets
32+
env:
33+
CI_APP_ID: ${{ secrets.CI_APP_ID }}
34+
CI_APP_PRIVATE_KEY: ${{ secrets.CI_APP_PRIVATE_KEY }}
35+
if: ${{ env.CI_APP_ID != '' && env.CI_APP_PRIVATE_KEY != '' }}
36+
run: echo "available=true" >> $GITHUB_OUTPUT
37+
38+
- name: Generate GitHub App token
39+
if: ${{ steps.check-secrets.outputs.available == 'true' }}
2140
uses: actions/create-github-app-token@v1
2241
id: generate-token
2342
with:
@@ -27,7 +46,8 @@ jobs:
2746
- name: Checkout code
2847
uses: actions/checkout@v4
2948
with:
30-
token: ${{ steps.generate-token.outputs.token }}
49+
ref: ${{ github.event.inputs.branch || 'main' }}
50+
token: ${{ steps.generate-token.outputs.token || github.token }}
3151

3252
- name: Use Node.js
3353
uses: actions/setup-node@v4
@@ -40,8 +60,8 @@ jobs:
4060
run: npm ci
4161

4262
- name: Deploy
63+
env:
64+
DEPLOY_TOKEN: ${{ steps.generate-token.outputs.token || github.token }}
4365
run: |
44-
git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/${{github.repository}}.git
66+
git remote set-url origin https://git:${DEPLOY_TOKEN}@github.com/${{github.repository}}.git
4567
npm run deploy -- -u "github-actions-bot <support+actions@github.com>"
46-
env:
47-
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}

0 commit comments

Comments
 (0)