-
Notifications
You must be signed in to change notification settings - Fork 12
223 lines (194 loc) · 7.49 KB
/
edge-app-checks.yml
File metadata and controls
223 lines (194 loc) · 7.49 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
name: Edge App Checks
on:
push:
branches:
- master
paths:
- "edge-apps/**"
pull_request:
branches:
- "**"
paths:
- "edge-apps/**"
jobs:
detect-changes:
name: Detect Changed Edge Apps
runs-on: ubuntu-latest
outputs:
changed-apps: ${{ steps.extract-changes.outputs.changed-apps }}
apps-with-build-system: ${{ steps.build-system-check.outputs.apps-with-build-system }}
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v47
with:
files: |
edge-apps/**
files_ignore: |
edge-apps/**/node_modules/**
edge-apps/**/dist/**
edge-apps/**/.git/**
edge-apps/**/*.log
- name: Extract changed Edge Apps
id: extract-changes
run: |
# Get list of changed files
CHANGED_FILES="${{ steps.changed-files.outputs.all_changed_files }}"
# Read CHANGED_FILES into an array
read -ra FILES_ARRAY <<< "$CHANGED_FILES"
# Function to add app to list if it has build system and isn't already included
add_app_if_valid() {
local app="$1"
if [[ -n "$app" && "$app" != "helpers" && "$app" != ".bun-create" && "$app" != "blueprint" ]]; then
if [[ -f "edge-apps/$app/package.json" ]]; then
if [[ ! " $CHANGED_APPS " =~ $app ]]; then
CHANGED_APPS="$CHANGED_APPS $app"
fi
fi
fi
}
# Check if blueprint or edge-apps-library has changes and extract unique Edge App directories
BLUEPRINT_CHANGED=false
EDGE_APPS_LIBRARY_CHANGED=false
CHANGED_APPS=""
for file in "${FILES_ARRAY[@]}"; do
if [[ "$file" == edge-apps/* ]]; then
# Check for blueprint changes
if [[ "$file" == edge-apps/blueprint/* ]]; then
BLUEPRINT_CHANGED=true
fi
# Check for edge-apps-library changes
if [[ "$file" == edge-apps/edge-apps-library/* ]]; then
EDGE_APPS_LIBRARY_CHANGED=true
fi
# Extract the app name (first directory after edge-apps/)
APP_NAME=$(echo "$file" | cut -d'/' -f2)
add_app_if_valid "$APP_NAME"
fi
done
# If blueprint or edge-apps-library changed, add all apps with build systems
if [[ "$BLUEPRINT_CHANGED" == "true" || "$EDGE_APPS_LIBRARY_CHANGED" == "true" ]]; then
if [[ "$BLUEPRINT_CHANGED" == "true" ]]; then
echo "Blueprint changed, adding all apps with build systems..."
fi
if [[ "$EDGE_APPS_LIBRARY_CHANGED" == "true" ]]; then
echo "edge-apps-library changed, adding all apps with build systems..."
fi
# Dynamically discover all Edge Apps with build systems
for app_dir in edge-apps/*/; do
if [[ -d "$app_dir" ]]; then
app=$(basename "$app_dir")
add_app_if_valid "$app"
fi
done
fi
# Remove leading space and set output
CHANGED_APPS="${CHANGED_APPS# }"
echo "changed-apps=$CHANGED_APPS" >> "$GITHUB_OUTPUT"
echo "Changed Edge Apps: $CHANGED_APPS"
- name: Check which apps have build systems
id: build-system-check
run: |
CHANGED_APPS="${{ steps.extract-changes.outputs.changed-apps }}"
APPS_WITH_BUILD_SYSTEM=""
# Read CHANGED_APPS into an array
read -ra APPS_ARRAY <<< "$CHANGED_APPS"
for app in "${APPS_ARRAY[@]}"; do
if [[ -f "edge-apps/$app/package.json" ]]; then
APPS_WITH_BUILD_SYSTEM="$APPS_WITH_BUILD_SYSTEM $app"
fi
done
# Remove leading space and convert to JSON array
APPS_WITH_BUILD_SYSTEM="${APPS_WITH_BUILD_SYSTEM# }"
if [[ -n "$APPS_WITH_BUILD_SYSTEM" ]]; then
# Convert space-separated string to JSON array
JSON_ARRAY=$(echo "$APPS_WITH_BUILD_SYSTEM" | tr ' ' '\n' | jq -R . | jq -s -c .)
echo "apps-with-build-system=$JSON_ARRAY" >> "$GITHUB_OUTPUT"
else
echo "apps-with-build-system=[]" >> "$GITHUB_OUTPUT"
fi
echo "Apps with build system: $APPS_WITH_BUILD_SYSTEM"
run-checks:
name: Run Checks for ${{ matrix.app }}
runs-on: ubuntu-latest
needs: detect-changes
strategy:
matrix:
app: ${{ fromJSON(needs.detect-changes.outputs.apps-with-build-system) }}
fail-fast: false
if: needs.detect-changes.outputs.apps-with-build-system != '[]'
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.2.2
- name: Build edge-apps-library if needed
run: |
if [[ -d "edge-apps/edge-apps-library" ]] && grep -q "edge-apps-library" "edge-apps/${{ matrix.app }}/package.json"; then
echo "Building edge-apps-library dependency..."
cd edge-apps/edge-apps-library
bun install
bun run build
fi
- name: Install dependencies
working-directory: edge-apps/${{ matrix.app }}
run: bun install
- name: Run linting
working-directory: edge-apps/${{ matrix.app }}
run: bun run lint
- name: Run formatting check
working-directory: edge-apps/${{ matrix.app }}
run: bun run format:check
- name: Run unit tests
working-directory: edge-apps/${{ matrix.app }}
run: bun run test:unit
- name: Build application
working-directory: edge-apps/${{ matrix.app }}
run: bun run build
- name: Check for E2E tests
id: check-e2e
working-directory: edge-apps/${{ matrix.app }}
run: |
if grep -q '"test:e2e"' package.json; then
echo "has-e2e=true" >> "$GITHUB_OUTPUT"
else
echo "has-e2e=false" >> "$GITHUB_OUTPUT"
fi
- name: Install E2E dependencies
if: steps.check-e2e.outputs.has-e2e == 'true'
working-directory: edge-apps/${{ matrix.app }}
run: npx playwright install --with-deps
- name: Run E2E tests
if: steps.check-e2e.outputs.has-e2e == 'true'
uses: nick-fields/retry@v3
with:
timeout_minutes: 5
max_attempts: 5
retry_on: error
command: cd edge-apps/${{ matrix.app }} && bun run test:e2e
summary:
name: Summary
runs-on: ubuntu-latest
needs: [detect-changes, run-checks]
if: always()
steps:
- name: Check if any apps were processed
run: |
if [[ "${{ needs.detect-changes.outputs.changed-apps }}" == "" ]]; then
echo "No Edge Apps were changed."
elif [[ "${{ needs.detect-changes.outputs.apps-with-build-system }}" == "[]" ]]; then
echo "Changed Edge Apps don't have build systems: ${{ needs.detect-changes.outputs.changed-apps }}"
else
echo "Processed Edge Apps with build systems: ${{ needs.detect-changes.outputs.apps-with-build-system }}"
fi
- name: Check for failures
if: needs.run-checks.result == 'failure'
run: |
echo "Some Edge App checks failed. Please review the logs above."
exit 1