forked from iflastandards/standards-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
235 lines (206 loc) · 8.04 KB
/
deploy-dev.yml
File metadata and controls
235 lines (206 loc) · 8.04 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
name: Development Deployment
# Development environment deployment for dev branch
# Deploys affected sites to development GitHub Pages environment
on:
push:
branches:
- dev
workflow_dispatch:
inputs:
force_build_all:
description: 'Force build all sites (Portal + all standards)'
required: false
default: 'false'
type: boolean
skip_nx_cache:
description: 'Skip Nx cache (force fresh builds)'
required: false
default: 'false'
type: boolean
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages-dev"
cancel-in-progress: false
jobs:
detect-and-build:
runs-on: ubuntu-latest
outputs:
affected-projects: ${{ steps.affected.outputs.projects }}
has-affected: ${{ steps.affected.outputs.has-affected }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Required for NX affected
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'pnpm'
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --no-frozen-lockfile
- name: Setup NX Cloud
uses: nrwl/nx-set-shas@v4
- name: Debug NX setup
run: |
echo "NX_BASE: $NX_BASE"
echo "NX_HEAD: $NX_HEAD"
echo "Current HEAD: $(git rev-parse HEAD)"
echo "Previous commits:"
git log --oneline -5
- name: Detect affected projects
id: affected
run: |
# Check for force build flag (handle empty string as false)
FORCE_BUILD="${{ inputs.force_build_all }}"
if [ "$FORCE_BUILD" = "true" ]; then
echo "Force building all projects..."
projects=$(pnpm nx show projects --type=app | tr '\n' ' ')
echo "projects=$projects" >> $GITHUB_OUTPUT
echo "has-affected=true" >> $GITHUB_OUTPUT
else
echo "Detecting affected projects..."
echo "Base SHA: $NX_BASE"
echo "Head SHA: $NX_HEAD"
# Show what would be affected (including libraries for debugging)
echo "All affected projects:"
pnpm nx show projects --affected || echo "Failed to get affected projects"
# Get affected apps for deployment
affected=$(pnpm nx show projects --affected --type=app 2>/dev/null | tr '\n' ' ' || echo "")
if [ -z "$affected" ]; then
echo "No affected app projects found"
echo "Trying with explicit base SHA..."
if [ -n "$NX_BASE" ]; then
affected=$(pnpm nx show projects --affected --type=app --base=$NX_BASE 2>/dev/null | tr '\n' ' ' || echo "")
fi
# Special handling for theme changes - if theme is affected, all apps should rebuild
if [ -z "$affected" ]; then
echo "Checking if theme package is affected..."
theme_affected=$(pnpm nx show projects --affected | grep "@ifla/theme" || echo "")
if [ -n "$theme_affected" ]; then
echo "Theme package is affected - rebuilding all sites"
affected=$(pnpm nx show projects --type=app | tr '\n' ' ')
echo "All projects due to theme change: $affected"
echo "projects=$affected" >> $GITHUB_OUTPUT
echo "has-affected=true" >> $GITHUB_OUTPUT
else
echo "No affected projects found - setting has-affected=false"
echo "has-affected=false" >> $GITHUB_OUTPUT
fi
else
echo "Found affected projects with explicit base: $affected"
echo "projects=$affected" >> $GITHUB_OUTPUT
echo "has-affected=true" >> $GITHUB_OUTPUT
fi
else
echo "Affected projects: $affected"
echo "projects=$affected" >> $GITHUB_OUTPUT
echo "has-affected=true" >> $GITHUB_OUTPUT
fi
fi
- name: Build affected projects
if: steps.affected.outputs.has-affected == 'true'
run: |
FORCE_BUILD="${{ inputs.force_build_all }}"
SKIP_CACHE="${{ inputs.skip_nx_cache }}"
# Add skip cache flag if requested
CACHE_FLAG=""
if [ "$SKIP_CACHE" = "true" ]; then
echo "Skipping Nx cache for fresh builds"
CACHE_FLAG="--skip-nx-cache"
fi
if [ "$FORCE_BUILD" = "true" ]; then
echo "Force building all projects"
pnpm nx run-many --target=build --all --parallel=1 --configuration=development $CACHE_FLAG
else
echo "Building affected projects"
pnpm nx affected --target=build --parallel=1 --configuration=development $CACHE_FLAG
fi
env:
DOCS_ENV: development
NODE_ENV: production
BASE_URL_PREFIX: /standards-dev/
NX_SKIP_NX_CACHE: ${{ inputs.skip_nx_cache == 'true' && 'true' || '' }}
- name: Upload artifacts for each built project
if: steps.affected.outputs.has-affected == 'true'
run: |
# Upload each built project as a separate artifact
for project in ${{ steps.affected.outputs.projects }}; do
if [ "$project" = "portal" ]; then
project_path="portal"
else
project_path="standards/${project}"
fi
if [ -d "${project_path}/build" ]; then
echo "Uploading artifact for $project..."
# Use actions/upload-artifact@v4 programmatically
mkdir -p /tmp/artifacts
cp -r ${project_path}/build /tmp/artifacts/${project}
fi
done
- name: Upload combined artifact
if: steps.affected.outputs.has-affected == 'true'
uses: actions/upload-artifact@v4
with:
name: all-builds
path: |
portal/build
standards/*/build
retention-days: 1
deploy:
runs-on: ubuntu-latest
needs: detect-and-build
if: needs.detect-and-build.outputs.has-affected == 'true'
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: all-builds
path: .
- name: Combine builds
run: |
mkdir -p combined-build
# Copy portal to root if it exists
if [ -d "portal/build" ]; then
cp -r portal/build/* combined-build/
mkdir -p combined-build/portal
cp -r portal/build/* combined-build/portal/
fi
# Copy all standards builds
for standard_dir in standards/*/build; do
if [ -d "$standard_dir" ]; then
standard_name=$(basename $(dirname "$standard_dir"))
mkdir -p combined-build/${standard_name}
cp -r $standard_dir/* combined-build/${standard_name}/
fi
done
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload to Pages
uses: actions/upload-pages-artifact@v3
with:
path: combined-build
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4