-
-
Notifications
You must be signed in to change notification settings - Fork 34
239 lines (193 loc) · 9.18 KB
/
main.yml
File metadata and controls
239 lines (193 loc) · 9.18 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
236
237
238
239
name: PWA Lint & Test
on:
push:
branches: ['*']
pull_request:
branches: ['*']
jobs:
check-appbuilders-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get AppBuilder Version
run: |
# Get tag from GHCR
TOKEN_JSON=$(curl https://ghcr.io/token\?scope\="repository:sillsdev/app-builders:pull")
TOKEN=$(echo "$TOKEN_JSON" | jq -r ".token")
TAG_DATA=$(curl -H "Authorization: Bearer $TOKEN" https://ghcr.io/v2/sillsdev/app-builders/tags/list)
NUM_TAGS=$(echo "$TAG_DATA" | jq -r '.tags | length')
FROM_GHCR=$(echo "$TAG_DATA" | jq -r ".tags[$(("$NUM_TAGS" - 1))]")
echo "Latest tag of sillsdev/app-builders is: $FROM_GHCR"
# Get version from package.json
FROM_PACKAGE=$(jq -r ".version" "package.json")
echo "Latest version of sillsdev/appbuilder-pwa is: $FROM_PACKAGE"
if [ "$FROM_GHCR" != "$FROM_PACKAGE" ]; then
echo "version in package.json does not match latest version from ghcr"
exit 1
fi
setup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: volta-cli/action@v4
- name: Get environment info
run: |
node --version
npm --version
- name: Restore node_modules cache
id: restore-node-cache
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: steps.restore-node-cache.outputs.cache-hit != 'true'
run: |
echo "Installing dependencies..."
npm ci
- name: Cache node_modules
if: steps.restore-node-cache.outputs.cache-hit != 'true'
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}
- name: Restore Projects cache
id: restore-projects-cache
uses: actions/cache@v4
with:
path: project_data
key: ${{ runner.os }}-projects-${{ hashFiles('test_data/projects', 'convert/*.ts') }}
- name: Setup Java
if: steps.restore-projects-cache.outputs.cache-hit != 'true'
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
java-package: 'jdk'
- name: Install JFX
if: steps.restore-projects-cache.outputs.cache-hit != 'true'
uses: ConorMacBride/install-package@v1
with:
apt: openjfx libopenjfx-jni
- name: App Builders Install
if: steps.restore-projects-cache.outputs.cache-hit != 'true'
run: |
docker pull ghcr.io/sillsdev/app-builders:latest
container_id=$(docker create ghcr.io/sillsdev/app-builders:latest bash)
mkdir $HOME/app-builders
docker cp "$container_id:/" $HOME/app-builders
docker rm "$container_id"
chmod +x $HOME/app-builders/*.sh
java -version
$HOME/app-builders/sab.sh -? | head -n 4
- name: Convert Projects
if: steps.restore-projects-cache.outputs.cache-hit != 'true'
run: |
WORK_DIR=$(pwd)
mkdir project_data
for PROGRAM in sab dab; do
echo "Processing projects for $PROGRAM"
mkdir -p "$HOME/projects/$PROGRAM"
# Get all projects as JSON array
PROJECTS_JSON=$(jq -r ".${PROGRAM}.projects" "test_data/projects/index.json")
# Get number of projects
NUM_PROJECTS=$(echo "$PROJECTS_JSON" | jq '. | length')
# Iterate through projects using index
for ((i=0; i<$NUM_PROJECTS; i++)); do
# Get project path
PROJECT_ZIP=$(echo "$PROJECTS_JSON" | jq -r ".[$i].path")
PROJECT_NAME=$(basename "$PROJECT_ZIP" .zip)
echo "Project: $PROJECT_NAME"
PROJECT_DIR="$HOME/projects/${PROGRAM}/$PROJECT_NAME"
mkdir -p "$PROJECT_DIR"
unzip -q "test_data/projects/${PROGRAM}/$PROJECT_ZIP" -d "$PROJECT_DIR"
npm run clean:all > /dev/null
pushd "$PROJECT_DIR" > /dev/null
PROJECT_FILE=$(find . -type f -name "*.appDef")
"$HOME/app-builders/${PROGRAM}.sh" -load "$PROJECT_FILE" -build-modern-pwa-data-files -no-save -fp pwa-repo="$WORK_DIR" > /dev/null
popd > /dev/null
mkdir "project_data/$PROJECT_NAME"
mv data/* "project_data/$PROJECT_NAME"
du -h "project_data/$PROJECT_NAME"
done
done
du -h project_data
- name: Cache Extracted Projects
if: steps.restore-projects-cache.outputs.cache-hit != 'true'
uses: actions/cache@v4
with:
path: project_data
key: ${{ runner.os }}-projects-${{ hashFiles('test_data/projects', 'convert/*.ts') }}
lint:
runs-on: ubuntu-latest
needs: setup
steps:
- uses: actions/checkout@v4
- uses: volta-cli/action@v4
- name: Restore node_modules cache
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}
- name: Restore Projects cache
uses: actions/cache@v4
with:
path: project_data
key: ${{ runner.os }}-projects-${{ hashFiles('test_data/projects', 'convert/*.ts') }}
- name: Convert minimal project
run: |
npm run convert -- --data-dir=project_data/web_gospels
- name: TypeScript/Svelte Check
run: |
npm list --depth=0 typescript
npm run check
- name: ESLint
run: |
npm list --depth=0 eslint eslint-plugin-import prettier
npm run lint
- name: Run minimal build
run: |
npx vite build
test:
runs-on: ubuntu-latest
needs: setup
steps:
- uses: actions/checkout@v4
- uses: volta-cli/action@v4
- name: Restore node_modules cache
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json') }}
- name: Restore Projects cache
uses: actions/cache@v4
with:
path: project_data
key: ${{ runner.os }}-projects-${{ hashFiles('test_data/projects', 'convert/*.ts') }}
- name: Run Tests
run: |
WORK_DIR=$(pwd)
for PROGRAM in sab dab; do
echo "Processing projects for $PROGRAM"
mkdir -p "$HOME/projects/$PROGRAM"
# Get all projects as JSON array
PROJECTS_JSON=$(jq -r ".${PROGRAM}.projects" "test_data/projects/index.json")
# Get number of projects
NUM_PROJECTS=$(echo "$PROJECTS_JSON" | jq '. | length')
# Iterate through projects using index
for ((i=0; i<$NUM_PROJECTS; i++)); do
# Get project path and test directories
PROJECT_ZIP=$(echo "$PROJECTS_JSON" | jq -r ".[$i].path")
TEST_DIRS=$(echo "$PROJECTS_JSON" | jq -r ".[$i].tests[]")
PROJECT_NAME=$(basename "$PROJECT_ZIP" .zip)
echo "Project: $PROJECT_NAME"
npm run clean:all > /dev/null
cp -r "project_data/$PROJECT_NAME/." data
npm run build
# Run tests for each specified directory
for TEST_DIR in $TEST_DIRS; do
echo "Running tests in directory: $TEST_DIR"
npm run test "$TEST_DIR"
done
done
done