@suffolklitlab/alkiln 5.4.1-feat-github-server-18 → 5.4.1-feat-github-server-19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,17 +2,11 @@ name: GitHub server tests
2
2
 
3
3
  on:
4
4
  push:
5
- # `workflow dispatch` isn't showing up in github because it's not the default branch
6
- # See https://stackoverflow.com/a/75250828
7
5
  workflow_dispatch:
8
6
  inputs:
9
7
  tags:
10
8
  required: False
11
9
  description: 'Optional. Use a "tag expression" specify which tagged tests to run (https://cucumber.io/docs/cucumber/api/#tag-expressions)'
12
- # # Only test 2 tests - one uses an env var, the other uses AL.
13
- # # They test if env vars get set correctly and depencencies get
14
- # # pulled in correctly.
15
- # default: '@al1'
16
10
  enable_tmate:
17
11
  type: boolean
18
12
  description: 'Run the build with tmate debugging enabled (https://github.com/marketplace/actions/debugging-with-tmate)'
@@ -29,11 +23,10 @@ jobs:
29
23
  node-version: [18.x]
30
24
 
31
25
  env:
32
- # How would a dev make another user/password if they wanted to?
26
+ # TODO: Must solve - how would a dev make another user/password if they wanted to?
33
27
  SECRET_VAR1: secret-var1-value
34
28
  SECRET_VAR2: secret-var2-value
35
29
  SECRET_FOR_MISSING_FIELD: secret for missing field
36
- #_ALKILN_DANGEROUS_DEBUG: true
37
30
 
38
31
  steps:
39
32
  # Place the root directory in this branch
@@ -64,10 +57,9 @@ jobs:
64
57
  run: |
65
58
  echo "USER1_EMAIL=${{ steps.github_server.outputs.DA_ADMIN_EMAIL }}" >> $GITHUB_ENV
66
59
  echo "USER1_PASSWORD=${{ steps.github_server.outputs.DA_ADMIN_PASSWORD }}" >> $GITHUB_ENV
60
+ ## Example of working with the docker container after it's been started
67
61
  #- name: Work with docker
68
62
  # run: |
69
- # # Authors can use this to do more with the docker container.
70
- # # There may be a better way. Would take research. A docker action?
71
63
  # container_name=$(docker ps --format '{{.Names}}' | head -n 1)
72
64
  # echo "container_name is $container_name"
73
65
 
@@ -80,6 +72,6 @@ jobs:
80
72
  INSTALL_METHOD: "server"
81
73
  # TODO: See what happens if this is an empty string
82
74
  ALKILN_VERSION: "server"
83
- ALKILN_TAG_EXPRESSION: "@al1"
75
+ #ALKILN_TAG_EXPRESSION: "@al1"
84
76
  - run: echo "Finished running ALKiln tests"
85
77
 
@@ -1,17 +1,6 @@
1
1
  name: "ALKiln/github_server: Isolated docassemble tests"
2
2
  description: "Download and start up a temporary docassemble server on GitHub's servers, in an isolated environment. Avoids docassemble reload errors and other external factors."
3
3
 
4
- # Bug? Race condition? Exit with 52 when waiting for container to finish starting
5
- # https://github.com/SuffolkLITLab/ALKiln/actions/runs/5912900256/job/16036751264#step:4:188
6
- # Had no completion messages, but it exited with an error anyway
7
- # Took 121 seconds
8
- # The rerun of the test completed that step just fine, though it took less time
9
- # Took 120 and was fine: https://github.com/SuffolkLITLab/ALKiln/actions/runs/5913167036/job/16037288791
10
- # 150 secs with exit code 56:
11
- # https://github.com/SuffolkLITLab/ALKiln/actions/runs/5914677262/job/16040233419#step:4:196
12
- # 120 sec with exit code 56:
13
- # https://github.com/SuffolkLITLab/ALKiln/actions/runs/5914963614/job/16040773624#step:4:206
14
-
15
4
  # If we want to control the version of the docassemble image, we'd have
16
5
  # to make our own image:
17
6
  # You can build your own image by doing git clone jhpyle/docassemble and then
@@ -69,7 +58,7 @@ runs:
69
58
  mkdir /tmp/config
70
59
  echo "${{ inputs.CONFIG_CONTENTS }}" > /tmp/config/myconfig.yml
71
60
  docker pull jhpyle/docassemble
72
- docker run --env DA_ADMIN_EMAIL="${{ env.DA_ADMIN_EMAIL }}" --env DA_ADMIN_PASSWORD="${{ env.DA_ADMIN_PASSWORD }}" --env DA_ADMIN_API_KEY="${{ env.DA_ADMIN_API_KEY }}" --env DA_CONFIG=/tmp/config/myconfig.yml --volume /tmp/config:/tmp/config --cap-add SYS_PTRACE --memory="4gb" -d -p 80:80 jhpyle/docassemble
61
+ docker run --name docassemble_container --env DA_ADMIN_EMAIL="${{ env.DA_ADMIN_EMAIL }}" --env DA_ADMIN_PASSWORD="${{ env.DA_ADMIN_PASSWORD }}" --env DA_ADMIN_API_KEY="${{ env.DA_ADMIN_API_KEY }}" --env DA_CONFIG=/tmp/config/myconfig.yml --volume /tmp/config:/tmp/config --cap-add SYS_PTRACE --memory="4gb" -d -p 80:80 jhpyle/docassemble
73
62
  shell: bash
74
63
  - name: "ALKiln github_server: Wait for server to start"
75
64
  run: |
@@ -80,18 +69,15 @@ runs:
80
69
  # Wait 1 minute before pinging the server constantly
81
70
  sleep 60
82
71
 
83
- # Use a variable instead of checking $response so we can control to avoid race
84
- # conditions from preventing the success log message.
85
- ready="false"
72
+ response="start"
86
73
 
87
- while [[ $ready == "false" ]]; do
88
- echo "Time ellapsed: $SECONDS seconds"
74
+ while [[ $response != *"200"* ]]; do
75
+ echo "Time elapsed: $SECONDS seconds"
89
76
 
90
77
  # Check if max seconds till loading has passed
91
78
  if [[ $SECONDS -ge $MAX_SECONDS_FOR_DOCKER ]]; then
92
79
  echo "ALKiln GitHub Server Error: Timed out waiting for docker container to serve the site. If you want to give your docker container more timem to install, set the MAX_SECONDS_FOR_DOCKER input for this action."
93
- # Exit with failure, or allow this to keep going?
94
- break
80
+ exit 1
95
81
  fi
96
82
 
97
83
  # Set the variable to a new string value in each iteration
@@ -101,7 +87,6 @@ runs:
101
87
  # Check if the string includes the desired text
102
88
  if [[ $response == *"200"* ]]; then
103
89
  echo "Success! The docker container is ready!"
104
- ready="true"
105
90
  else
106
91
  echo "The docker container isn't ready yet. Will check again in 30 seconds."
107
92
  sleep 30
@@ -117,41 +102,17 @@ runs:
117
102
  - run: pip install docassemblecli
118
103
  shell: bash
119
104
  # Install the current directory onto the docassemble server
120
-
121
- #- name: Setup tmate session
122
- # uses: mxschmitt/action-tmate@v3
123
-
124
- ## da doesn't need to know the name of the folder
125
- ## alkiln does so it can locate the Project or package installed on the server
126
- - run: |
127
- # if `docassemble` cd `docassemble`
128
- #cd docassemble
129
- ## Get the name of the package folder
130
- #dirs2=(*/)
131
- #len=${#dirs2[@]}
132
- #if (( $len > 1 ));
133
- #then echo There are multiple files in your repo's `docassemble` folder. ALkiln will use the first one;
134
- #fi
135
- #folder=5
136
- #
137
- #
138
- ## Get back out of the docassemble folder
139
- #cd ..
140
- ## Install on server
141
-
142
- dainstall . --apiurl http://localhost --apikey $DA_ADMIN_API_KEY
105
+ - run: dainstall . --apiurl http://localhost --apikey $DA_ADMIN_API_KEY
143
106
  shell: bash
144
107
 
145
- # Upload artifacts that subscribers can download on the Actions summary page
108
+ # TODO: Upload artifacts that subscribers can download on the Actions summary page
146
109
  - name: "ALKiln github_server: Docker logs"
147
110
  if: ${{ always() }}
148
111
  run: |
149
- docker_logs=$(docker logs $(docker ps --filter "ancestor=jhpyle/docassemble" --format {{.ID}}))
150
112
  # Should this name have a date/time attached? The logs themselves have timestamps
151
- echo "$docker_logs" > /tmp/alkiln_docker_logs.txt
113
+ echo "$(docker logs docassemble_container)" > /tmp/alkiln_docker_logs.txt
152
114
  shell: bash
153
-
154
- # Should this date/time be created at the start of this action?
115
+
155
116
  - name: "ALKiln github_server: Get folder name with date and time"
156
117
  if: ${{ always() }}
157
118
  run: |
@@ -13,7 +13,7 @@ let get_base_interview_url = async function () {
13
13
 
14
14
  let server_url = session_vars.get_da_server_url();
15
15
 
16
- if (session_vars.get_install_type() === `server`) {
16
+ if (session_vars.get_install_method() === `server`) {
17
17
 
18
18
  return `${ server_url }/interview?new_session=1&i=docassemble.${session_vars.get_repo_folder_name()}%3Adata/questions/`;
19
19
 
@@ -5,7 +5,7 @@ const log = require('../utils/log');
5
5
  const fg = require('fast-glob');
6
6
 
7
7
  const server_install = async () => {
8
- session_vars.save_install_type(`server`);
8
+ session_vars.save_install_method(`server`);
9
9
 
10
10
  let current_dir = process.cwd();
11
11
  let path = `${ current_dir }/docassemble/*`;
@@ -178,72 +178,118 @@ session_vars.delete_project_name = function () {
178
178
  const artifacts_path_key = `artifacts_path`;
179
179
  session_vars.save_artifacts_path_name = function ( path_name ) {
180
180
  /* Save a key with the name of the current artifacts folder in case it doesn't exist. */
181
-
182
- // Ensure artifacts path file exists
183
- if ( !fs.existsSync( runtime_config_path ) ) {
184
- // If the file doesn't exist, make one because next we need to read it
185
- fs.writeFileSync( runtime_config_path, JSON.stringify( {}, null, 2 ) );
186
- }
187
-
188
- // Get the json, changing it, and re-write the file from scratch
189
- let json = JSON.parse( fs.readFileSync( runtime_config_path ) );
190
- json[ artifacts_path_key ] = path_name;
191
- let file = fs.writeFileSync( runtime_config_path, JSON.stringify( json, null, 2 ) );
192
-
193
- if ( session_vars.get_debug() ) {
194
- console.log( `ALKiln debug: Stored name of artifacts directory "${ path_name }" locally.` );
195
- }
196
- return file;
181
+ return session_vars.save_runtime_config_var({ key: artifacts_path_key, value: path_name });
182
+
183
+ // // Ensure artifacts path file exists
184
+ // if ( !fs.existsSync( runtime_config_path ) ) {
185
+ // // If the file doesn't exist, make one because next we need to read it
186
+ // fs.writeFileSync( runtime_config_path, JSON.stringify( {}, null, 2 ) );
187
+ // }
188
+
189
+ // // Get the json, changing it, and re-write the file from scratch
190
+ // let json = JSON.parse( fs.readFileSync( runtime_config_path ) );
191
+ // json[ artifacts_path_key ] = path_name;
192
+ // let file = fs.writeFileSync( runtime_config_path, JSON.stringify( json, null, 2 ) );
193
+
194
+ // if ( session_vars.get_debug() ) {
195
+ // console.log( `ALKiln debug: Stored name of artifacts directory "${ path_name }" locally.` );
196
+ // }
197
+ // return file;
197
198
  }; // Ends save_artifacts_path_name()
198
199
 
199
200
  session_vars.get_artifacts_path_name = function () {
200
201
  /* Get the name of the current artifacts path. */
201
- try {
202
- let json = JSON.parse( fs.readFileSync( runtime_config_path ));
203
- let path_name = json[ artifacts_path_key ];
204
-
205
- if ( session_vars.get_debug() ) { console.log( `ALKiln debug: Artifacts directory is "${ path_name }".` ); }
206
- return path_name;
207
- } catch ( error ) {
208
- return null;
209
- }
202
+ return session_vars.get_runtime_config_var( artifacts_path_key );
203
+ // try {
204
+ // let json = JSON.parse( fs.readFileSync( runtime_config_path ));
205
+ // let path_name = json[ artifacts_path_key ];
206
+
207
+ // if ( session_vars.get_debug() ) { console.log( `ALKiln debug: Artifacts directory is "${ path_name }".` ); }
208
+ // return path_name;
209
+ // } catch ( error ) {
210
+ // return null;
211
+ // }
210
212
  }; // Ends get_artifacts_path_name()
211
213
 
212
214
 
213
- const install_type_key = `da_install_type`;
214
- session_vars.save_install_type = function (install_type) {
215
+ const install_method_key = `da_install_method`;
216
+ session_vars.save_install_method = function (install_method) {
215
217
  /* Save a key with the name of the current artifacts folder in case it doesn't exist. */
218
+ return session_vars.save_runtime_config_var({ key: install_method_key, value: install_method });
216
219
 
217
- // Ensure artifacts path file exists
218
- if ( !fs.existsSync( runtime_config_path ) ) {
219
- // If the file doesn't exist, make one because next we need to read it
220
- fs.writeFileSync( runtime_config_path, JSON.stringify( {}, null, 2 ) );
221
- }
220
+ // // Ensure artifacts path file exists
221
+ // if ( !fs.existsSync( runtime_config_path ) ) {
222
+ // // If the file doesn't exist, make one because next we need to read it
223
+ // fs.writeFileSync( runtime_config_path, JSON.stringify( {}, null, 2 ) );
224
+ // }
222
225
 
223
- // Get the json, changing it, and re-write the file from scratch
224
- let json = JSON.parse( fs.readFileSync( runtime_config_path ) );
225
- json[ install_type_key ] = install_type;
226
- let file = fs.writeFileSync( runtime_config_path, JSON.stringify( json, null, 2 ) );
226
+ // // Get the json, changing it, and re-write the file from scratch
227
+ // let json = JSON.parse( fs.readFileSync( runtime_config_path ) );
228
+ // json[ install_method_key ] = install_method;
229
+ // let file = fs.writeFileSync( runtime_config_path, JSON.stringify( json, null, 2 ) );
227
230
 
228
- return file;
229
- }; // Ends save_install_type()
231
+ // return file;
232
+ }; // Ends save_install_method()
230
233
 
231
- session_vars.get_install_type = function () {
232
- /* Get the name of the current artifacts path. */
233
- try {
234
- let json = JSON.parse( fs.readFileSync( runtime_config_path ));
235
- let install_type = json[ install_type_key ];
234
+ session_vars.get_install_method = function () {
235
+ /* Get the name of the current install method. */
236
+ return session_vars.get_runtime_config_var( install_method_key );
237
+ // try {
238
+ // let json = JSON.parse( fs.readFileSync( runtime_config_path ));
239
+ // let install_method = json[ install_method_key ];
236
240
 
237
- return install_type;
238
- } catch ( error ) {
239
- return null;
240
- }
241
- }; // Ends get_install_type()
241
+ // return install_method;
242
+ // } catch ( error ) {
243
+ // return null;
244
+ // }
245
+ }; // Ends get_install_method()
242
246
 
243
247
 
244
248
  const repo_folder_key = `da_repo_folder_name`;
245
249
  session_vars.save_repo_folder_name = function (repo_folder_name) {
246
250
  /** Save a key with the name of the main package folder in the repository. */
251
+ return session_vars.save_runtime_config_var({ key: repo_folder_key, value: repo_folder_name });
252
+
253
+ // // Ensure runtime config file exists
254
+ // if ( !fs.existsSync( runtime_config_path ) ) {
255
+ // // If the file doesn't exist, make one because next we need to read it
256
+ // fs.writeFileSync( runtime_config_path, JSON.stringify( {}, null, 2 ) );
257
+ // }
258
+
259
+ // // Get the json, changing it, and re-write the file from scratch
260
+ // let json = JSON.parse( fs.readFileSync( runtime_config_path ) );
261
+ // json[ repo_folder_key ] = repo_folder_name;
262
+ // let file = fs.writeFileSync( runtime_config_path, JSON.stringify( json, null, 2 ) );
263
+
264
+ // return file;
265
+ }; // Ends session_vars.save_repo_folder_name()
266
+
267
+ session_vars.get_repo_folder_name = function () {
268
+ /** Get the name of the main folder in the repository. */
269
+ return session_vars.get_runtime_config_var( repo_folder_key );
270
+ // try {
271
+ // let json = JSON.parse( fs.readFileSync( runtime_config_path ));
272
+ // let name = json[ repo_folder_key ];
273
+
274
+ // return name;
275
+ // } catch ( error ) {
276
+ // return null;
277
+ // }
278
+ }; // Ends session_vars.get_repo_folder_name()
279
+
280
+
281
+ // TODO: Should we replace the other method calls with this one?
282
+ // i.e. `save_repo_folder_name`, etc. It would clarify exactly
283
+ // what those calls are doing, but would lock in implementation
284
+ session_vars.save_runtime_config_var = function ({ key, value }) {
285
+ /** Write to the runtime config file by adding a key/value pair to
286
+ * the json object there.
287
+ *
288
+ * @param key {str} Key to use to store `value` in runtime config file
289
+ * @param value {any} Value to store in runtime config file
290
+ *
291
+ * @returns file {binary?} Runtime config file
292
+ */
247
293
 
248
294
  // Ensure runtime config file exists
249
295
  if ( !fs.existsSync( runtime_config_path ) ) {
@@ -253,23 +299,34 @@ session_vars.save_repo_folder_name = function (repo_folder_name) {
253
299
 
254
300
  // Get the json, changing it, and re-write the file from scratch
255
301
  let json = JSON.parse( fs.readFileSync( runtime_config_path ) );
256
- json[ repo_folder_key ] = repo_folder_name;
302
+ json[ key ] = value;
257
303
  let file = fs.writeFileSync( runtime_config_path, JSON.stringify( json, null, 2 ) );
258
304
 
305
+ if ( session_vars.get_debug() ) {
306
+ console.log( `ALKiln debug runtime config var: Stored "${key}" locally as "${value}".` );
307
+ }
259
308
  return file;
260
- }; // Ends session_vars.save_repo_folder_name()
309
+ }; // Ends session_vars.save_runtime_config_var()
261
310
 
262
- session_vars.get_repo_folder_name = function () {
263
- /** Get the name of the main folder in the repository. */
311
+ session_vars.get_runtime_config_var = function ( key ) {
312
+ /** Get the value of the given key from the runtime config file.
313
+ *
314
+ * @param key {str} Key in runtime config file that contains the desired value
315
+ * @returns value | null {any} Value of key in runtime config file. If it
316
+ * doesn't exist, returns null.
317
+ */
264
318
  try {
265
319
  let json = JSON.parse( fs.readFileSync( runtime_config_path ));
266
- let name = json[ repo_folder_key ];
320
+ let value = json[ key ];
321
+ if ( session_vars.get_debug() ) {
322
+ console.log( `ALKiln debug runtime config var: "${key}"" is "${value}".` );
323
+ }
267
324
 
268
- return name;
325
+ return value;
269
326
  } catch ( error ) {
270
327
  return null;
271
328
  }
272
- }; // Ends session_vars.get_repo_folder_name()
329
+ }; // Ends session_vars.get_runtime_config_var()
273
330
 
274
331
 
275
332
  session_vars.set_sources_paths = function ( paths ) {
@@ -320,7 +377,7 @@ session_vars.set_sources_paths = function ( paths ) {
320
377
  // Otherwise, store valid paths
321
378
  session_vars._sources_paths = existing_paths;
322
379
  return true;
323
- };
380
+ }; // End session_vars.set_sources_paths()
324
381
 
325
382
  session_vars.get_sources_paths = function () {
326
383
  /** Get the "sources" folder path. Should never be undefined during
@@ -331,6 +388,7 @@ session_vars.get_sources_paths = function () {
331
388
  return session_vars._sources_paths;
332
389
  };
333
390
 
391
+
334
392
  session_vars.validateEnvironment = function() {
335
393
  /** Throw a useful error for the developer if any of the env vars
336
394
  * required by absolutely all tests are missing. Gather all
@@ -395,36 +453,3 @@ session_vars.validateEnvironment = function() {
395
453
  };
396
454
 
397
455
  session_vars.validateEnvironment();
398
-
399
-
400
- const save_runtime_config_var = function (key, value) {
401
- /** Save a key and its value in the runtime config file. */
402
-
403
- // Ensure runtime config file exists
404
- if ( !fs.existsSync( runtime_config_path ) ) {
405
- // If the file doesn't exist, make one because next we need to read it
406
- fs.writeFileSync( runtime_config_path, JSON.stringify( {}, null, 2 ) );
407
- }
408
-
409
- // Get the json, changing it, and re-write the file from scratch
410
- let json = JSON.parse( fs.readFileSync( runtime_config_path ) );
411
- json[ key ] = value;
412
- let file = fs.writeFileSync( runtime_config_path, JSON.stringify( json, null, 2 ) );
413
-
414
- if ( session_vars.get_debug() ) {
415
- console.log( `ALKiln debug: Stored "${key}" locally as "${value}".` );
416
- }
417
- return file;
418
- }; // Ends save_runtime_config_var()
419
-
420
- const get_runtime_config_var = function (key) {
421
- /** Get the value of the given key from the runtime config file. */
422
- try {
423
- let json = JSON.parse( fs.readFileSync( runtime_config_path ));
424
- let value = json[ key ];
425
-
426
- return value;
427
- } catch ( error ) {
428
- return null;
429
- }
430
- }; // Ends get_runtime_config_var()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suffolklitlab/alkiln",
3
- "version": "5.4.1-feat-github-server-18",
3
+ "version": "5.4.1-feat-github-server-19",
4
4
  "description": "Integrated automated end-to-end testing with docassemble, puppeteer, and cucumber.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {