Skip to content

Commit 181df2e

Browse files
authored
feat: Add grading checks (#4)
1 parent 0f6c16d commit 181df2e

File tree

6 files changed

+227
-12
lines changed

6 files changed

+227
-12
lines changed

.github/steps/4-copilot-on-github.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ Now, let's see how Copilot can help us finish up with during our pull request.
2424

2525
- Notice the log entry indicating a Copilot review was requested.
2626

27-
1. At the bottom, press the **Green Merge pull request** button.
27+
1. At the bottom, press the green **Merge pull request** button.
2828

2929
1. Wait a moment for Mona to check your work, provide feedback, and post a final review of this lesson! Nice work you are done! :tada:

.github/workflows/0-start-exercise.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ permissions:
1212

1313
env:
1414
EXERCISE_NAME: "Accelerate with GitHub Copilot"
15-
INTRO_MESSAGE: "🎉 Welcome to the exciting world of GitHub Copilot! 🚀 In this exercise, you'll unlock the potential of this AI-powered coding assistant to accelerate your development process. Let's dive in and have some fun exploring the future of coding together! 💻✨"
15+
INTRO_MESSAGE: "Welcome to the exciting world of GitHub Copilot! 🚀 In this exercise, you'll unlock the potential of this AI-powered coding assistant to accelerate your development process. Let's dive in and have some fun exploring the future of coding together! 💻✨"
1616
STEP_1_FILE: ".github/steps/1-preparing.md"
1717

1818
jobs:

.github/workflows/1-preparing.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ jobs:
6767
env:
6868
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6969

70+
# START: Check practical exercise
71+
72+
# Nothing to verify. Creating the branch is enough for now.
73+
# In a future update, we will check that the codepsace is running and that the website is visible.
74+
75+
# END: Check practical exercise
76+
7077
- name: Build message - step finished
7178
id: build-message-step-finish
7279
uses: skills/action-text-variables@v1

.github/workflows/2-first-introduction.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,50 @@ jobs:
6969
env:
7070
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7171

72+
# START: Check practical exercise
73+
74+
# Search for the comment about registration validation
75+
- name: Check contents of 'src/app.py'
76+
run: |
77+
# File and expected phrase
78+
file="src/app.py"
79+
keyphrase="Validate student is not already signed up"
80+
81+
# Fail the workflow if the file content is missing
82+
if ! grep -q "$keyphrase" "$file"; then
83+
message="It seems our registration validation bug has not been fixed. Please try again."
84+
gh issue comment "$ISSUE_URL" \
85+
--body "$message" \
86+
--edit-last
87+
exit 1
88+
fi
89+
env:
90+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
91+
92+
# Check the number of activities in the file by counting the json keys
93+
- name: Check for additional student activities
94+
run: |
95+
# File and phrase to count
96+
file="src/app.py"
97+
keyphrase='"description":'
98+
minimum_occurences=4
99+
100+
# Get the number of occurences of the keyphrase
101+
found_occurences=$(grep -o "$keyphrase" "$file" | wc -l)
102+
103+
# If the number of occurences is less than the minimum, fail the workflow and send a message
104+
if [ "$found_occurences" -lt "$minimum_occurences" ]; then
105+
message="No new student activities were found. Please use Copilot to generate some and try again."
106+
gh issue comment "$ISSUE_URL" \
107+
--body "$message" \
108+
--edit-last
109+
exit 1
110+
fi
111+
env:
112+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
113+
114+
# END: Check practical exercise
115+
72116
- name: Build message - step finished
73117
id: build-message-step-finish
74118
uses: skills/action-text-variables@v1

.github/workflows/3-copilot-edits.yml

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,91 @@ jobs:
6969
env:
7070
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7171

72+
# START: Check practical exercise
73+
74+
- name: Check participant info on activity cards
75+
id: check-user-work
76+
run: |
77+
# Checks to perform
78+
checks='{
79+
"app_js": {
80+
"name": "app.js",
81+
"passed": true,
82+
"message": ""
83+
},
84+
"styles_css": {
85+
"name": "styles.css",
86+
"passed": true,
87+
"message": ""
88+
}
89+
}'
90+
91+
# Check for participants info in app.js
92+
file="src/static/app.js"
93+
keyphrase='participant'
94+
minimum_occurences=5
95+
found_occurences=$(grep -o "$keyphrase" "$file" | wc -l)
96+
if [ "$found_occurences" -lt "$minimum_occurences" ]; then
97+
checks=$(echo $checks | jq '.app_js.passed = false')
98+
checks=$(echo $checks | jq '.app_js.message = "Please use Copilot to update the web application activity cards to show participant info."')
99+
fi
100+
101+
# Check for participants info in styles.css
102+
file="src/static/styles.css"
103+
keyphrase='participant'
104+
minimum_occurences=2
105+
found_occurences=$(grep -o "$keyphrase" "$file" | wc -l)
106+
if [ "$found_occurences" -lt "$minimum_occurences" ]; then
107+
checks=$(echo $checks | jq '.styles_css.passed = false')
108+
checks=$(echo $checks | jq '.styles_css.message = "Please use Copilot to update the web application styling to support participant info."')
109+
fi
110+
111+
# Verify all checks passed
112+
passed=$(echo $checks | jq '. | all(.passed?)')
113+
114+
# Flatten to an array for returning. Allows iteration during rendering.
115+
results=$(echo $checks | jq 'to_entries | map({name: .key} + .value)')
116+
117+
# Save pass status to output
118+
echo "passed=$passed" >> $GITHUB_OUTPUT
119+
120+
# Save results to output
121+
echo 'results<<EOF' >> $GITHUB_OUTPUT
122+
echo $results >> $GITHUB_OUTPUT
123+
echo 'EOF' >> $GITHUB_OUTPUT
124+
env:
125+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
126+
127+
- name: Build message - step results
128+
id: build-message-step-results
129+
uses: skills/action-text-variables@v1
130+
with:
131+
template-file: skills-response-templates/step-feedback/step-results.md
132+
template-vars: '{
133+
"step_number": 3,
134+
"passed": ${{ steps.check-user-work.outputs.passed }},
135+
"results_table": ${{ steps.check-user-work.outputs.results }},
136+
"tips": [
137+
"Copilot is becoming more capable everyday. Make sure to always be experimenting!",
138+
"Try testing what Copilot can do. Something like: Add a dark mode toggle in the top right."
139+
]
140+
}'
141+
142+
- name: Create comment - step results
143+
run: |
144+
gh issue comment "$ISSUE_URL" \
145+
--body "$COMMENT_BODY" \
146+
--edit-last
147+
env:
148+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
149+
COMMENT_BODY: ${{ steps.build-message-step-results.outputs.updated-text }}
150+
151+
- name: Fail job if not all checks passed
152+
if: steps.check-user-work.outputs.passed == 'false'
153+
run: exit 1
154+
155+
# END: Check practical exercise
156+
72157
- name: Build message - step finished
73158
id: build-message-step-finish
74159
uses: skills/action-text-variables@v1
@@ -80,8 +165,7 @@ jobs:
80165
- name: Update comment - step finished
81166
run: |
82167
gh issue comment "$ISSUE_URL" \
83-
--body "$ISSUE_BODY" \
84-
--edit-last
168+
--body "$ISSUE_BODY"
85169
env:
86170
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
87171
ISSUE_BODY: ${{ steps.build-message-step-finish.outputs.updated-text }}

.github/workflows/4-copilot-on-github.yml

Lines changed: 88 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ permissions:
1111
contents: write
1212
actions: write
1313
issues: write
14+
pull-requests: read
15+
repository-projects: read
1416

1517
env:
1618
REVIEW_FILE: ".github/steps/x-review.md"
@@ -67,22 +69,100 @@ jobs:
6769
env:
6870
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6971

70-
- name: Build message - step finished
71-
id: build-message-step-finish
72+
# START: Check practical exercise
73+
- name: Check participant info on activity cards
74+
id: check-user-work
75+
run: |
76+
# Checks to perform
77+
checks='{
78+
"pr_description": {
79+
"name": "PR Description",
80+
"passed": true,
81+
"message": ""
82+
},
83+
"copilot_review": {
84+
"name": "Copilot Review",
85+
"passed": true,
86+
"message": ""
87+
}
88+
}'
89+
90+
# Check if PR has a description and minimum length
91+
min_length=15
92+
body_length=$(echo "$PR_Body" | wc -c)
93+
echo "PR decription length: $body_length"
94+
if [ "$body_length" -lt $min_length ]; then
95+
checks=$(echo $checks | jq '.pr_description.passed = false')
96+
checks=$(echo $checks | jq '.pr_description.message = "Please use Copilot to generate a pull request description."')
97+
fi
98+
99+
# Check for a PR Review from Copilot
100+
reviews=$(gh pr view --repo $REPO $PR_NUMBER --json reviews)
101+
authors=$(echo "$reviews" | jq '.reviews[].author.login')
102+
if echo "$authors" | grep -q "copilot-pull-request-reviewer"; then
103+
echo "Copilot has reviewed this PR."
104+
else
105+
echo "Copilot has NOT reviewed this PR."
106+
checks=$(echo $checks | jq '.copilot_review.passed = false')
107+
checks=$(echo $checks | jq '.copilot_review.message = "Please request a review from Copilot."')
108+
fi
109+
110+
# Verify all checks passed
111+
passed=$(echo $checks | jq '. | all(.passed?)')
112+
113+
# Flatten to an array for returning. Allows iteration during rendering.
114+
results=$(echo $checks | jq 'to_entries | map({name: .key} + .value)')
115+
116+
# Save pass status to output
117+
echo "passed=$passed" >> $GITHUB_OUTPUT
118+
119+
# Save results to output
120+
echo 'results<<EOF' >> $GITHUB_OUTPUT
121+
echo $results >> $GITHUB_OUTPUT
122+
echo 'EOF' >> $GITHUB_OUTPUT
123+
env:
124+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
125+
PR_Body: ${{ github.event.pull_request.body }}
126+
REPO: ${{ github.repository }}
127+
PR_NUMBER: ${{ github.event.pull_request.number }}
128+
129+
- name: Build message - step results
130+
id: build-message-step-results
72131
uses: skills/action-text-variables@v1
73132
with:
74-
template-file: skills-response-templates/step-feedback/step-finished-prepare-next-step.md
75-
template-vars: |
76-
next_step_number=final
133+
template-file: skills-response-templates/step-feedback/step-results.md
134+
template-vars: '{
135+
"step_number": 4,
136+
"passed": ${{ steps.check-user-work.outputs.passed }},
137+
"results_table": ${{ steps.check-user-work.outputs.results }},
138+
"tips": [
139+
"Copilot review will also suggest changes for common mistakes and typos.",
140+
"You can use repository rulesets to automatically require a review from Copilot."
141+
]
142+
}'
143+
144+
- name: Create comment - step results
145+
run: |
146+
gh issue comment "$ISSUE_URL" \
147+
--body "$COMMENT_BODY" \
148+
--edit-last
149+
env:
150+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
151+
COMMENT_BODY: ${{ steps.build-message-step-results.outputs.updated-text }}
152+
153+
- name: Fail job if not all checks passed
154+
if: steps.check-user-work.outputs.passed == 'false'
155+
run: exit 1
156+
157+
# END: Check practical exercise
77158

78-
- name: Update comment - step finished
159+
- name: Update comment - step finished - final review next
79160
run: |
80161
gh issue comment "$ISSUE_URL" \
81-
--body "$ISSUE_BODY" \
162+
--body-file skills-response-templates/step-feedback/lesson-review.md \
82163
--edit-last
83164
env:
84165
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85-
ISSUE_BODY: ${{ steps.build-message-step-finish.outputs.updated-text }}
86166

87167
post_review_content:
88168
name: Post review content

0 commit comments

Comments
 (0)