-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,530 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,64 @@ | ||
name: PR automation | ||
on: | ||
pull_request_target: | ||
types: [opened, reopened, edited, ready_for_review] | ||
|
||
jobs: | ||
labeler: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Label PR | ||
uses: actions/github-script@v5 | ||
with: | ||
github-token: ${{ secrets.PAT }} | ||
script: | | ||
const { owner, repo, number: issue_number } = context.issue; | ||
const pr = await github.rest.pulls.get({ owner, repo, pull_number: issue_number }); | ||
const title = pr.data.title; | ||
const labRegex = /\[LAB(\d+)\]/; | ||
const titleRegex = /^\[LAB\d+\] [\da-zA-Z]+$/; | ||
if (!titleRegex.test(title)) { | ||
core.setFailed('PR title does not match the required format. Please use the format [LAB#] student#.'); | ||
} | ||
if (pr.data.head.ref !== pr.data.base.ref) { | ||
core.setFailed('The source branch and target branch must be the same.'); | ||
} | ||
if (pr.data.base.ref === 'main') { | ||
core.setFailed('The target branch cannot be main.'); | ||
} | ||
const match = title.match(labRegex); | ||
if (match) { | ||
const labelToAdd = 'lab' + match[1]; | ||
await github.rest.issues.addLabels({ owner, repo, issue_number, labels: [labelToAdd] }); | ||
} else { | ||
core.setFailed('No match found in PR title. Please add a label in the format [LAB#] to the PR title.'); | ||
} | ||
checklist-check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check PR description | ||
uses: actions/github-script@v5 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const { owner, repo, number: issue_number } = context.issue; | ||
const pr = await github.rest.pulls.get({ owner, repo, pull_number: issue_number }); | ||
const body = pr.data.body; | ||
const checkboxes = body.match(/\- \[[x ]\]/g); | ||
if (!checkboxes || checkboxes.length !== 5) { | ||
core.setFailed('The PR description must contain exactly 5 checkboxes.'); | ||
} | ||
const unchecked = body.match(/\- \[ \]/g); | ||
if (unchecked && unchecked.length > 0) { | ||
core.setFailed(`There are ${unchecked.length} unchecked items in the PR description.`); | ||
} | ||
name: PR automation | ||
on: | ||
pull_request_target: | ||
types: [opened, reopened, edited, ready_for_review] | ||
|
||
jobs: | ||
labeler: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Label PR | ||
uses: actions/github-script@v5 | ||
with: | ||
github-token: ${{ secrets.PAT }} | ||
script: | | ||
const { owner, repo, number: issue_number } = context.issue; | ||
const pr = await github.rest.pulls.get({ owner, repo, pull_number: issue_number }); | ||
const title = pr.data.title; | ||
const titleRegex = /^\[LAB(\d+)\] [a-zA-Z]?\d+$/; | ||
const match = title.match(titleRegex); | ||
let labNumberStr = undefined; | ||
if (match) { | ||
labNumberStr = match[1]; | ||
} else { | ||
core.setFailed('PR title does not match the required format. Please use the format: [LAB#] <studentId>.'); | ||
} | ||
const labelToAdd = `lab${labNumberStr}`; | ||
if (labNumberStr) { | ||
await github.rest.issues.addLabels({ owner, repo, issue_number, labels: [labelToAdd] }); | ||
} | ||
if (pr.data.base.ref === 'main') { | ||
core.setFailed('The target branch cannot be main.'); | ||
} | ||
if (labNumberStr < 3 && pr.data.head.ref !== pr.data.base.ref) { | ||
core.setFailed('The source branch and target branch must be the same.'); | ||
} | ||
if (labNumberStr >= 3 && pr.data.head.ref !== labelToAdd) { | ||
core.setFailed(`The source branch must be '${labelToAdd}'`); | ||
} | ||
checklist-check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check PR description | ||
uses: actions/github-script@v5 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const { owner, repo, number: issue_number } = context.issue; | ||
const pr = await github.rest.pulls.get({ owner, repo, pull_number: issue_number }); | ||
const body = pr.data.body; | ||
const checkboxes = body.match(/^ ?(-|\*) \[[x ]\]/gmi); | ||
if (!checkboxes || checkboxes.length !== 5) { | ||
core.setFailed('The PR description must contain exactly 5 checkboxes.'); | ||
} | ||
const unchecked = body.match(/^ ?(-|\*) \[ \]/gm); | ||
if (unchecked && unchecked.length > 0) { | ||
core.setFailed(`There are ${unchecked.length} unchecked item(s) in the PR description.`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: Autograding | ||
|
||
on: | ||
pull_request_target: | ||
types: [labeled, synchronize, opened, reopened, ready_for_review] | ||
|
||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-22.04] | ||
fail-fast: false | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: "${{ github.event.pull_request.merge_commit_sha }}" | ||
fetch-depth: 1 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: latest | ||
- name: Extract lab number and Check no changes other than specific files | ||
uses: actions/github-script@v5 | ||
id: lab | ||
with: | ||
result-encoding: string | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const { owner, repo, number: issue_number } = context.issue; | ||
const pr = await github.rest.pulls.get({ owner, repo, pull_number: issue_number }); | ||
const labels = pr.data.labels; | ||
const lab = labels.find((label) => label.name.startsWith('lab')); | ||
if (!lab) { | ||
core.setFailed('No lab label found on the PR.'); | ||
return { number: 0 }; | ||
} | ||
const labNumberMatch = lab.name.match(/lab(\d+)/); | ||
if (!labNumberMatch) { | ||
core.setFailed('Invalid lab label found on the PR.'); | ||
return { number: 0 }; | ||
} | ||
const labNumber = labNumberMatch[1]; | ||
console.log(`Lab number: ${labNumber}`) | ||
const files = await github.rest.pulls.listFiles({ owner, repo, pull_number: issue_number }); | ||
const changedFiles = files.data.map((file) => file.filename); | ||
const allowedFileRegex = /^lab\d+\/main_test.js$/; | ||
if (!changedFiles.every((file) => allowedFileRegex.test(file))) { | ||
core.setFailed('The PR contains changes to files other than the allowed files.'); | ||
} | ||
return labNumber; | ||
- name: Grading | ||
run: | | ||
cd lab${{ steps.lab.outputs.result }} | ||
./validate.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +0,0 @@ | ||
name: lab1 autograding | ||
|
||
on: | ||
pull_request: | ||
types: [labeled, synchronize, opened, reopened, ready_for_review] | ||
|
||
jobs: | ||
build: | ||
if: contains(github.event.pull_request.labels.*.name, 'lab1') | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-22.04] | ||
fail-fast: false | ||
steps: | ||
- uses: actions/checkout@v1 | ||
with: | ||
fetch-depth: 1 | ||
- name: dependency (ubuntu) | ||
run: | | ||
curl -fsSL https://deb.nodesource.com/setup_21.x | sudo -E bash - &&\ | ||
sudo apt-get install -y nodejs | ||
- name: grading | ||
run: | | ||
cd lab1 | ||
./validate.sh | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +0,0 @@ | ||
name: lab2 autograding | ||
|
||
on: | ||
pull_request: | ||
types: [labeled, synchronize, opened, reopened, ready_for_review] | ||
|
||
jobs: | ||
build: | ||
if: contains(github.event.pull_request.labels.*.name, 'lab2') | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-22.04] | ||
fail-fast: false | ||
steps: | ||
- uses: actions/checkout@v1 | ||
with: | ||
fetch-depth: 1 | ||
- name: dependency (ubuntu) | ||
run: | | ||
curl -fsSL https://deb.nodesource.com/setup_21.x | sudo -E bash - &&\ | ||
sudo apt-get install -y nodejs | ||
- name: grading | ||
run: | | ||
cd lab2 | ||
./validate.sh | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Lab3 | ||
|
||
## Introduction | ||
|
||
In this lab, you will write unit tests for functions implemented in `main.js`. You can learn how to use classes and functions in it by uncommenting the code in it. (But remember don't commit them on GitHub) | ||
|
||
## Preparation (Important!!!) | ||
|
||
1. Sync fork on GitHub | ||
2. `git checkout -b lab3` (**NOT** your student ID !!!) | ||
|
||
## Requirement | ||
|
||
1. (40%) Write test cases in `main_test.js` and achieve 100% code coverage. | ||
2. (30%) For each function, parameterize their testcases to test the error-results. | ||
3. (30%) For each function, use at least 3 parameterized testcases to test the non-error-results. | ||
|
||
You can run `validate.sh` in your local to test if you satisfy the requirements. | ||
|
||
Please note that you must not alter files other than `main_test.js`. You will get 0 points if | ||
|
||
1. you modify other files to achieve requirements. | ||
2. you can't pass all CI on your PR. | ||
|
||
## Submission | ||
|
||
You need to open a pull request to your branch (e.g. 311XXXXXX, your student number) and contain the code that satisfies the abovementioned requirements. | ||
|
||
Moreover, please submit the URL of your PR to E3. Your submission will only be accepted when you present at both places. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class Calculator { | ||
exp(x) { | ||
if (!Number.isFinite(x)) { | ||
throw Error('unsupported operand type'); | ||
} | ||
const result = Math.exp(x); | ||
if (result === Infinity) { | ||
throw Error('overflow'); | ||
} | ||
return result; | ||
} | ||
|
||
log(x) { | ||
if (!Number.isFinite(x)) { | ||
throw Error('unsupported operand type'); | ||
} | ||
const result = Math.log(x); | ||
if (result === -Infinity) { | ||
throw Error('math domain error (1)'); | ||
} | ||
if (Number.isNaN(result)) { | ||
throw Error('math domain error (2)'); | ||
} | ||
return result; | ||
} | ||
} | ||
|
||
// const calculator = new Calculator(); | ||
// console.log(calculator.exp(87)); | ||
// console.log(calculator.log(48763)); | ||
|
||
module.exports = { | ||
Calculator | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const {describe, it} = require('node:test'); | ||
const assert = require('assert'); | ||
const { Calculator } = require('./main'); | ||
|
||
// TODO: write your tests here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash | ||
|
||
# Check for unwanted files | ||
for file in *; do | ||
if [[ $file != "main.js" && $file != "main_test.js" && $file != "README.md" && $file != "validate.sh" ]]; then | ||
echo "[!] Unwanted file detected: $file." | ||
exit 1 | ||
fi | ||
done | ||
|
||
node=$(which node) | ||
test_path="${BASH_SOURCE[0]}" | ||
solution_path="$(realpath .)" | ||
tmp_dir=$(mktemp -d -t lab3-XXXXXXXXXX) | ||
|
||
cd $tmp_dir | ||
|
||
rm -rf * | ||
cp $solution_path/*.js . | ||
result=$($"node" --test --experimental-test-coverage) ; ret=$? | ||
if [ $ret -ne 0 ] ; then | ||
echo "[!] testing fails" | ||
exit 1 | ||
else | ||
coverage=$(echo "$result" | grep 'all files' | awk -F '|' '{print $2}' | sed 's/ //g') | ||
if (( $(echo "$coverage < 100" | bc -l) )); then | ||
echo "[!] Coverage is only $coverage%" | ||
exit 1 | ||
else | ||
echo "[V] Coverage is 100%" | ||
fi | ||
fi | ||
|
||
rm -rf $tmp_dir | ||
|
||
exit 0 | ||
|
||
# vim: set fenc=utf8 ff=unix et sw=2 ts=2 sts=2: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Lab4 | ||
|
||
## Introduction | ||
|
||
In this lab, you will write tests in `main_test.js`. You can learn how to use [Puppeteer](https://pptr.dev/) to tests a web UI. | ||
|
||
## Preparation (Important!!!) | ||
|
||
1. Sync fork your branch (e.g., `SQLab:311XXXXXX`) | ||
2. `git checkout -b lab4` (**NOT** your student ID !!!) | ||
|
||
## Requirement | ||
|
||
1. (100%) Goto https://pptr.dev/, type `chipi chipi chapa chapa` into the search box, click on **1st** result in the **Docs** section, and print the title. | ||
|
||
For the detailed steps and hints, please check the slide of this lab. | ||
|
||
You can run `validate.sh` in your local to test if you satisfy the requirements. | ||
|
||
Please note that you must not alter files other than `main_test.js`. You will get 0 points if | ||
|
||
1. you modify other files to achieve requirements. | ||
2. you can't pass all CI on your PR. | ||
|
||
## Submission | ||
|
||
You need to open a pull request to your branch (e.g. 311XXXXXX, your student number) and contain the code that satisfies the abovementioned requirements. | ||
|
||
Moreover, please submit the URL of your PR to E3. Your submission will only be accepted when you present at both places. |
Oops, something went wrong.