Skip to content

Commit 6034f8d

Browse files
committed
extended GH-Actions
1 parent 60175be commit 6034f8d

2 files changed

Lines changed: 64 additions & 7 deletions

File tree

.github/workflows/pr-preview-surge.yml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
types: [opened, reopened, synchronize, ready_for_review, edited, labeled]
66
pull_request:
77
types: [closed] # for teardown
8+
push:
9+
branches: [main]
810

911
# Token perms needed for commenting + reading artifacts
1012
permissions:
@@ -19,22 +21,29 @@ env:
1921

2022
jobs:
2123
build:
22-
# Build untrusted PR code WITHOUT secrets
23-
if: github.event_name == 'pull_request_target' && github.event.pull_request.draft == false
24+
# Build PRs (without secrets) and main branch pushes
25+
if: ${{ (github.event_name == 'pull_request_target' && github.event.pull_request.draft == false) || (github.event_name == 'push' && github.ref == 'refs/heads/main') }}
2426
name: Build PR
2527
runs-on: ubuntu-latest
2628
defaults:
2729
run:
2830
working-directory: ./website
2931
steps:
3032
- name: Checkout PR head (read-only)
33+
if: github.event_name == 'pull_request_target'
3134
uses: actions/checkout@v4
3235
with:
3336
repository: ${{ github.event.pull_request.head.repo.full_name }}
3437
ref: ${{ github.event.pull_request.head.ref }}
3538
persist-credentials: false
3639
fetch-depth: 0
3740

41+
- name: Checkout main commit
42+
if: github.event_name == 'push'
43+
uses: actions/checkout@v4
44+
with:
45+
fetch-depth: 0
46+
3847
- name: Use Node.js
3948
uses: actions/setup-node@v4
4049
with:
@@ -57,13 +66,13 @@ jobs:
5766
retention-days: 5
5867

5968
deploy:
60-
# Pauses at Environment gate until a member approves
61-
if: github.event_name == 'pull_request_target' && github.event.pull_request.draft == false
62-
name: Deploy Preview to Surge (requires approval)
69+
# Deploy PR previews (with gate) and automatic main previews
70+
if: ${{ (github.event_name == 'pull_request_target' && github.event.pull_request.draft == false) || (github.event_name == 'push' && github.ref == 'refs/heads/main') }}
71+
name: Deploy Preview to Surge
6372
needs: build
6473
runs-on: ubuntu-latest
6574
environment:
66-
name: preview
75+
name: ${{ github.event_name == 'pull_request_target' && 'preview' || 'main-preview' }}
6776
url: ${{ steps.deployed.outputs.preview_url }}
6877

6978
steps:
@@ -79,7 +88,12 @@ jobs:
7988
- name: Compute preview domain + path
8089
id: dom
8190
run: |
82-
echo "domain=${{ env.SURGE_DOMAIN_BASE }}-pr-${{ github.event.number }}.surge.sh" >> $GITHUB_OUTPUT
91+
if [ "${{ github.event_name }}" = "pull_request_target" ]; then
92+
domain="${{ env.SURGE_DOMAIN_BASE }}-pr-${{ github.event.number }}.surge.sh"
93+
else
94+
domain="${{ env.SURGE_DOMAIN_BASE }}.surge.sh"
95+
fi
96+
echo "domain=$domain" >> $GITHUB_OUTPUT
8397
echo "path=/${{ env.BASE_PATH }}/" >> $GITHUB_OUTPUT
8498
8599
# Stage the Docusaurus output under the baseUrl path (so it serves at /<BASE_PATH>/)
@@ -104,6 +118,7 @@ jobs:
104118
105119
# Comment using a purpose-built action (more robust than raw API for forked PRs)
106120
- name: Comment with preview URL
121+
if: github.event_name == 'pull_request_target'
107122
uses: peter-evans/create-or-update-comment@v4
108123
with:
109124
token: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Release Docs to GitHub Pages
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
deploy:
12+
name: Build and Deploy
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout release tag
16+
uses: actions/checkout@v4
17+
with:
18+
ref: ${{ github.event.release.tag_name }}
19+
fetch-depth: 0
20+
21+
- name: Use Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: 22
25+
cache: yarn
26+
cache-dependency-path: website/yarn.lock
27+
28+
- name: Install dependencies
29+
working-directory: ./website
30+
run: yarn install --frozen-lockfile
31+
32+
- name: Build website
33+
working-directory: ./website
34+
run: yarn build
35+
36+
- name: Deploy to gh-pages
37+
uses: peaceiris/actions-gh-pages@v3
38+
with:
39+
github_token: ${{ secrets.GITHUB_TOKEN }}
40+
publish_branch: gh-pages
41+
publish_dir: website/build
42+
full_commit_message: "docs: deploy ${{ github.event.release.tag_name }}"

0 commit comments

Comments
 (0)