-
Notifications
You must be signed in to change notification settings - Fork 37
147 lines (124 loc) · 5.15 KB
/
deploy-ui-docs-pr.yml
File metadata and controls
147 lines (124 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: Deploy UI Docs (PR Preview)
on:
pull_request:
branches:
- main
paths:
- 'projects/orcid-ui-docs/**'
- 'projects/orcid-ui/**'
- 'projects/orcid-tokens/**'
- 'package.json'
- 'angular.json'
- '.github/workflows/deploy-ui-docs-pr.yml'
workflow_dispatch:
# Allows manual triggering for testing
jobs:
build-and-deploy-preview:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write # To comment on PR with preview URL
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract ticket ID from branch name
id: extract-ticket
env:
HEAD_REF: ${{ github.head_ref }}
REF_NAME: ${{ github.ref_name }}
run: |
BRANCH_NAME="${HEAD_REF:-$REF_NAME}"
echo "Branch name: $BRANCH_NAME"
# Extract ticket ID (e.g., PD-1234 from lmendoza/PD-1234)
TICKET_ID=$(echo "$BRANCH_NAME" | grep -oE '[A-Z]+-[0-9]+' || echo "")
if [ -z "$TICKET_ID" ]; then
echo "WARNING: No ticket ID found in branch name, using full branch name"
# Sanitize branch name for URL (replace / with -)
TICKET_ID=$(echo "$BRANCH_NAME" | sed 's/\//-/g')
fi
echo "ticket_id=$TICKET_ID" >> "$GITHUB_OUTPUT"
echo "Extracted ticket ID: $TICKET_ID"
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'yarn'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build orcid-ui-docs with dynamic base-href
run: |
TICKET_ID="${{ steps.extract-ticket.outputs.ticket_id }}"
BASE_HREF="/orcid-angular/runway/$TICKET_ID/"
echo "Building with base-href: $BASE_HREF"
yarn build:ui-docs --base-href "$BASE_HREF"
continue-on-error: false
- name: Determine build output directory
id: set-output
run: |
if [ -d "dist/orcid-ui-docs/browser" ]; then
echo "directory=dist/orcid-ui-docs/browser" >> "$GITHUB_OUTPUT"
elif [ -d "dist/orcid-ui-docs" ]; then
echo "directory=dist/orcid-ui-docs" >> "$GITHUB_OUTPUT"
else
echo "ERROR: Build output directory not found" >&2
ls -la dist/ >&2
exit 1
fi
- name: Setup SPA support for GitHub Pages
run: |
BUILD_DIR="${{ steps.set-output.outputs.directory }}"
# Copy index.html to 404.html for SPA routing support
# This 404.html will handle routes within THIS specific PR preview SPA
cp "$BUILD_DIR/index.html" "$BUILD_DIR/404.html"
# Note: .nojekyll is already in the repo root and applies to all subdirectories
echo "✅ SPA support configured: 404.html created for PR preview"
- name: Deploy to GitHub Pages (PR Preview)
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ${{ steps.set-output.outputs.directory }}
destination_dir: runway/${{ steps.extract-ticket.outputs.ticket_id }}
keep_files: true # Keep other PR previews and main deployment
cname: false
- name: Comment on PR with preview URL
uses: actions/github-script@v7
if: github.event_name == 'pull_request'
with:
script: |
const ticketId = '${{ steps.extract-ticket.outputs.ticket_id }}';
const previewUrl = `https://orcid.github.io/orcid-angular/runway/${ticketId}/`;
const comment = `## 🚀 Preview Deployment
Your UI docs preview is ready!
**Preview URL:** ${previewUrl}
This preview will be updated automatically when you push new commits to this PR.
---
*Deployed from commit: \`${context.sha.substring(0, 7)}\`*`;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('🚀 Preview Deployment')
);
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: comment
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: comment
});
}