Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LAB4] 312555001 #619

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
15a32e9
fix: checklist-check workflow's regex
TaiYou-TW Mar 12, 2024
a1dc1e2
fix: install node from setup-node instead of script installation
TaiYou-TW Mar 12, 2024
656d908
feat: fix buggy regex and add changed-files-check in pr.yml
TaiYou-TW Mar 13, 2024
68ee198
feat: use one autograding workflow instead of each lab's
TaiYou-TW Mar 13, 2024
7d4c24a
feat: rewrite source branch's naming rules
AlaRduTP Mar 13, 2024
d44bbe3
feat: use pull_request_target instead of pull_request
AlaRduTP Mar 13, 2024
f02c1ea
fix: multiple errors in workflows
AlaRduTP Mar 13, 2024
2d4b5d3
feat: merge and squash script
AlaRduTP Mar 13, 2024
91270f2
fix: didn't checkout when grading
TaiYou-TW Mar 14, 2024
2c9fd78
feat: add lab3
AlaRduTP Mar 14, 2024
f6b8b88
doc: add lab3 requirements
AlaRduTP Mar 14, 2024
06329c2
fix: wrong GITHUB SHA in workflows
AlaRduTP Mar 14, 2024
ebef053
hotfix: remove changed files
AlaRduTP Mar 14, 2024
9fcdccd
feat: an easy check for changed files
AlaRduTP Mar 21, 2024
e02ce02
feat: add node_modules into gitignore
AlaRduTP Mar 21, 2024
afcb770
feat: specify the strategy of merging
AlaRduTP Mar 21, 2024
28785dd
feat: lab4
AlaRduTP Mar 21, 2024
fdfdb1d
feat: add lab5
YingMuo Apr 18, 2024
9a73059
Add: lab6
YingMuo Apr 25, 2024
ac8ccd3
feat: lab7
AlaRduTP May 2, 2024
2731331
feat: add .gitignore to lab7
TaiYou-TW May 29, 2024
972cce5
feat: add hw4
TaiYou-TW May 29, 2024
8bdc28f
doc: add readme for hw4
TaiYou-TW May 29, 2024
f12d34d
fix: leap year's days
TaiYou-TW May 30, 2024
ec6368c
Finish lab4
YingMuo Jun 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions .github/workflows/PR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,31 @@ jobs:
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#.');
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>.');
}

if (pr.data.head.ref !== pr.data.base.ref) {
core.setFailed('The source branch and target branch must be the same.');
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.');
}

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.');
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
Expand All @@ -49,12 +53,12 @@ jobs:
const pr = await github.rest.pulls.get({ owner, repo, pull_number: issue_number });
const body = pr.data.body;

const checkboxes = body.match(/\- \[[x ]\]/g);
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(/\- \[ \]/g);
const unchecked = body.match(/^ ?(-|\*) \[ \]/gm);
if (unchecked && unchecked.length > 0) {
core.setFailed(`There are ${unchecked.length} unchecked items in the PR description.`);
core.setFailed(`There are ${unchecked.length} unchecked item(s) in the PR description.`);
}
56 changes: 56 additions & 0 deletions .github/workflows/lab-autograding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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$/;
const specialChangedFiles = ["lab5/Answer.md", "lab5/antiasan.c", "lab6/Answer.md", "lab7/sol.py"];
if (!changedFiles.every((file) => (allowedFileRegex.test(file) || specialChangedFiles.includes(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
26 changes: 0 additions & 26 deletions .github/workflows/lab1.yml

This file was deleted.

26 changes: 0 additions & 26 deletions .github/workflows/lab2.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
2 changes: 2 additions & 0 deletions hw4/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
reports/
.stryker-tmp/
15 changes: 15 additions & 0 deletions hw4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# HW4

You can install package through:

```shell
npm i
```

After finish your test code in `tests/calculator_test.js`, you can run `Stryker` by:

```shell
npm run mutate
```

to get your mutation testing result.
Loading
Loading