-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
223 lines (205 loc) · 7.82 KB
/
action.yml
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: "WD201 Action"
description: 'Handles checkout, testing, and grading for WD201 submissions'
author: 'pupilfirst'
inputs:
level_name:
description: "Name of level e.g., l1, l2, etc."
globs:
description: "This contains the list of files that will checked during repo verification"
copy_commands:
description: "Shell commands to execute that copy the required files for running tests"
report_file_path:
description: "It contains the path to report.json file, ex: submission/someFolder/report.json"
test_failure_feedback:
description: "It contains test failure feedback for l1 "
submissionUrl:
description: "It contains the url of live application "
runs:
using: "composite"
steps:
# checkout student's repository and verify its structure
- uses: actions/checkout@v2
- name: Checkout student repo and verify its structure
id: check-student-repo
uses: pupilfirst/check-repo-action@v1
with:
repoPath: submission
globs: ${{ inputs.globs }}
# Report to LMS tests are in progress
- name: Report to LMS that tests in progress
if: ${{ steps.check-student-repo.outputs.result == 'success' }}
uses: pupilfirst/report-action@v1
with:
status: "in_progress"
description: "Automated tests are in progress."
# Checkout the wd201-tests repo
- name: Check out the solutions repo
if: ${{ steps.check-student-repo.outputs.result == 'success' }}
id: checkout-solutions-repo
uses: actions/checkout@v2
with:
repository: pupilfirst/wd201-tests
path: solution
# Copy submission/test files to solution/student's repo
- name: Copy test files to submission repo
if: steps.checkout-solutions-repo.outcome == 'success'
id: copy-submission-files
continue-on-error: true
run: ${{ inputs.copy_commands }}
shell: bash
# Generate output
- name: Setup and Test Submission
if: ${{ steps.check-student-repo.outputs.result == 'success' || steps.copy-submission-files.outcome == 'success' }}
id: check-submission-output
continue-on-error: true
run: |
case ${{ inputs.level_name }} in
"l1")
node submission/hello-world/index.js > output.txt
;;
"l3")
cd solution/l3
node index.js &> output.txt
;;
esac
shell: bash
# Run the app for l9 and l10
- name: Run the app
if: ${{ (inputs.level_name == 'l9' || inputs.level_name == 'l10') && steps.copy-submission-files.outcome == 'success' }}
id: run-app
run: |
cd solution/${{inputs.level_name}}
npm install
npx sequelize-cli db:drop
npx sequelize-cli db:create
npx sequelize-cli db:migrate
PORT=3000 npm start &
sleep 5
shell: bash
# run the tests
- name: Setup and Test Submission
if: ${{ steps.checkout-solutions-repo.outcome == 'success' || steps.copy-submission-files.outcome == 'success' }}
id: run-test
continue-on-error: true
run: |
# Function to handle common tasks
run_tests() {
cd "$1" # Change to the directory specified by the first argument
npm install # Install npm packages
$2 # Execute the command specified by the second argument
}
# Conditional logic to run tests based on the level
case ${{ inputs.level_name }} in
"l2")
run_tests "submission/http-server" "npm run test"
;;
"l3")
cd solution/l3
node test.js
;;
"l4" | "l5" | "l6")
run_tests "solution/${{ inputs.level_name }}" "npm run test"
;;
"l9" | "l10")
cd solution/${{ inputs.level_name }}
npm install cypress cypress-json-results
npx cypress run --env STUDENT_SUBMISSION_URL='http://localhost:3000/'
;;
esac
shell: bash
# Cypress for l7 & l8
- name: Cypress run with env
if: ${{(inputs.level_name == 'l7' || inputs.level_name == 'l8') && steps.checkout-solutions-repo.outcome == 'success'}}
uses: cypress-io/github-action@v6
continue-on-error: true
with:
wait-on: ${{inputs.submissionUrl}}
wait-on-timeout: 540
project: ./solution/${{inputs.level_name}}
env: STUDENT_SUBMISSION_URL=${{inputs.submissionUrl}}
# Report failure
- name: Report failure if tests fails
if: steps.check-submission-output.outcome == 'failure'
uses: pupilfirst/grade-action@v1
with:
fail_submission: true
feedback: ${{inputs.test_failure_feedback}}
# Report Success
- name: Generate feedback Report if all tests passed
id: generate-report
if: ${{steps.check-submission-output.outcome == 'success' && steps.checkout-solutions-repo.outcome == 'success'}}
continue-on-error: true
run: |
case ${{ inputs.level_name }} in
"l1")
echo "const fs = require(\"fs\");
function checkValidString(input) {
return input.toLowerCase().indexOf(\"hello\") > -1;
}
fs.readFile(\"output.txt\", \"utf8\", (err, data) => {
if (err) {
throw err;
} else {
let passed = checkValidString(data);
let reportFile = \"./report.json\";
let feedback = passed
? \"Good work! It looks like your code prints the output according to the specification.\"
: \"Uh oh! It looks like you've missed some parts of the assignment! Please ensure that your `index.js` script outputs the expected message mentioned in the assignment and try again.\";
let report = {
version: 0,
grade: passed ? \"accept\" : \"reject\",
status: passed ? \"success\" : \"failure\",
feedback: feedback,
};
fs.writeFileSync(reportFile, JSON.stringify(report));
}
});" | node
;;
"l2")
cd submission/http-server && node generateReportFromResults.js
;;
"l4")
cd solution/l4 && node generateReportFromResults.js
;;
"l5")
cd solution/l5 && node generateReportFromResults.js
;;
"l6")
cd solution/l6 && node generateReportFromResults.js
;;
# ... Add cases for other levels (L3 to L11)
"l7")
cd solution/l7 && node generateReportFromResults.js
;;
"l8")
cd solution/l8 && node generateReportFromResults.js
;;
"l9")
cd solution/l9 && node generateReportFromResults.js
;;
"l10")
cd solution/l10 && node generateReportFromResults.js
;;
# ... Add cases for other levels (L3 to L11)
esac
shell: bash
# Grade submissions
- name: Grade the submission based on test results
uses: pupilfirst/grade-action@v1
if: steps.generate-report.outcome == 'success'
with:
report_file_path: ${{ inputs.report_file_path }}
# Report outcome of tests to the LMS
- name: Report outcome of tests to LMS
uses: pupilfirst/report-action@v1
if: steps.generate-report.outcome == 'success'
id: report-test-results
with:
report_file_path: ${{ inputs.report_file_path }}
# Report error in testing to LMS
- name: Report error in testing to LMS
uses: pupilfirst/report-action@v1
if: ${{ steps.checkout-solutions-repo.outcome == 'success' && steps.report-test-results.outcome == 'skipped' }}
with:
status: "error"
description: "Automated tests could not be run successfully"