Repository navigation
178 lines (151 loc) · 5.83 KB
/
Copy pathci.yml
File metadata and controls
178 lines (151 loc) · 5.83 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
name: CI
on:
pull_request:
branches: ["**"]
jobs:
changes:
name: Detect Changed File Types
runs-on: ubuntu-latest
outputs:
e2e_required: ${{ steps.decide.outputs.e2e_required }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Detect docs-only changes
id: filter
uses: dorny/paths-filter@v3
with:
filters: |
docs:
- 'README.md'
- 'docs/**'
- '.github/**/*.md'
non_docs:
- '**'
- '!README.md'
- '!docs/**'
- '!.github/**/*.md'
- name: Decide whether E2E is required
id: decide
run: |
if [[ "${{ steps.filter.outputs.docs }}" == "true" && "${{ steps.filter.outputs.non_docs }}" != "true" ]]; then
echo "e2e_required=false" >> "$GITHUB_OUTPUT"
else
echo "e2e_required=true" >> "$GITHUB_OUTPUT"
fi
test:
name: Test & Build
runs-on: ubuntu-latest
needs: changes
env:
HUGO_VERSION: 0.160.0
DART_SASS_VERSION: 1.97.3
HUSKY: 0
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22.22.1
cache: npm
- name: Install dependencies
run: npm ci
- name: Run all tests
if: ${{ needs.changes.outputs.e2e_required == 'true' }}
run: npm test
- name: Create directory for user-specific executable files
run: mkdir -p "${HOME}/.local"
- name: Install Dart Sass
run: |
curl -sLJO "https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz"
tar -C "${HOME}/.local" -xf "dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz"
rm "dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz"
echo "${HOME}/.local/dart-sass" >> "${GITHUB_PATH}"
- name: Install Hugo
run: |
curl -sLJO "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz"
mkdir "${HOME}/.local/hugo"
tar -C "${HOME}/.local/hugo" -xf "hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz"
rm "hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz"
echo "${HOME}/.local/hugo" >> "${GITHUB_PATH}"
echo "Hugo: $(hugo version)"
- name: Hugo production build
run: cd exampleSite && hugo --gc --minify
- name: Validate Algolia JSON outputs
run: |
set -e
cd exampleSite
# Default language JSON (root) must exist and be non-empty
count=$(jq 'length' public/algolia.json)
if [ "$count" -eq 0 ]; then
echo "ERROR: public/algolia.json is empty"
exit 1
fi
echo "public/algolia.json: $count records OK"
# Secondary language JSON must exist and be non-empty
# NOTE: path 'public/en/' is tied to exampleSite's language config.
# Update this path if exampleSite languages change.
count=$(jq 'length' public/en/algolia.json)
if [ "$count" -eq 0 ]; then
echo "ERROR: public/en/algolia.json is empty"
exit 1
fi
echo "public/en/algolia.json: $count records OK"
# Default language JSON must not contain secondary language permalinks
if jq -e '[.[] | .permalink | contains("/en/")] | any' public/algolia.json > /dev/null; then
echo "ERROR: public/algolia.json contains /en/ permalinks (cross-language contamination)"
exit 1
fi
echo "public/algolia.json: no cross-language contamination OK"
# Secondary language JSON must only contain its own language permalinks
if jq -e '[.[] | .permalink | contains("/en/")] | all | not' public/en/algolia.json > /dev/null; then
echo "ERROR: public/en/algolia.json contains non-English permalinks"
exit 1
fi
echo "public/en/algolia.json: all records are English OK"
e2e:
name: E2E Tests
runs-on: ubuntu-latest
needs: [changes, test]
if: ${{ needs.changes.outputs.e2e_required == 'true' }}
env:
HUSKY: 0
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22.22.1
cache: npm
- name: Install dependencies
run: npm ci
- name: Install Playwright browsers
run: npx playwright install --with-deps chromium
- name: Install Hugo and Dart Sass
env:
HUGO_VERSION: 0.160.0
DART_SASS_VERSION: 1.97.3
run: |
mkdir -p "${HOME}/.local"
curl -sLJO "https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz"
tar -C "${HOME}/.local" -xf "dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz"
rm "dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz"
echo "${HOME}/.local/dart-sass" >> "${GITHUB_PATH}"
curl -sLJO "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz"
mkdir "${HOME}/.local/hugo"
tar -C "${HOME}/.local/hugo" -xf "hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz"
rm "hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz"
echo "${HOME}/.local/hugo" >> "${GITHUB_PATH}"
- name: Run E2E tests
run: npm run test:e2e
- name: Upload Playwright report
uses: actions/upload-artifact@v4
if: failure()
with:
name: playwright-report
path: playwright-report/
retention-days: 7