-
Notifications
You must be signed in to change notification settings - Fork 426
130 lines (116 loc) · 4.61 KB
/
check_task.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
name: Check task
# Controls when the workflow will run
on:
pull_request_target:
types:
- opened
- reopened # good to check canvas again to see if eligibility changed
- edited # we need to check the new description against the README
- synchronize
branches:
- 2024
paths:
- contributions/**
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
check-affected-files:
name: Check affected files
runs-on: ubuntu-latest
outputs:
affected_file: ${{ steps.check-affected-files.outputs.affected_file }}
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v45
- name: Check affected files
id: check-affected-files
env:
# get all affected files (created, modified, deleted, etc.)
FILES: ${{ steps.changed-files.outputs.all_changed_and_modified_files }}
FILES_COUNT: ${{ steps.changed-files.outputs.all_changed_and_modified_files_count }}
run: |
for file in "$FILES"; do
echo "Info: $file was changed"
done
if [ "$FILES_COUNT" -ne 1 ]; then
echo "Error: More than one file affected ($FILES_COUNT)"
exit 1
fi
if [[ "$FILES" =~ ^contributions\/(executable-tutorial|feedback|open-source)\/[^\/]+\/README\.md$ ]]; then
echo "Info: Matches async task"
elif [[ "$FILES" =~ ^contributions\/(demo|presentation|scientific-paper)\/week[2-7]\/[^\/]+\/README\.md$ ]]; then
echo "Info: Matches sync task"
else
echo "Error: File in wrong directory ($FILES)"
exit 1
fi
echo "affected_file=$FILES" >> "$GITHUB_OUTPUT"
check-pr-description:
name: Check whether Pull Request description matches affected file
needs: check-affected-files
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Install wdiff
# we use wdiff (word-diff) instead of plain diff (line-based) to ensure
# that we only enforce *content* to be the same rather than specific
# file formatting that would otherwise be ignored when the markdown is
# rendered. e.g., wdiff allows the README to break lines at col 80 for
# readability while still having the PR description without mid-sentence
# breaks (since GitHub descriptions don't support them)
run: |
sudo apt update
sudo apt install -y wdiff
- name: Check PR description
env:
AFFECTED_FILE: ${{ needs.check-affected-files.outputs.affected_file }}
PR_BODY: ${{ github.event.pull_request.body }}
run: |
BODY_FILE="$(mktemp)"
echo "$PR_BODY" > $BODY_FILE
if wdiff "$AFFECTED_FILE" "$BODY_FILE"; then
echo "Info: PR description matches affected file"
else
echo "Error: PR description does not match affected file!"
exit 1
fi
check-canvas:
name: Check proposal is compatible with previous student task registrations
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: 'Get tools'
uses: actions/checkout@v2.3.4
with:
repository: KTH/github-canvas-integration-devops
ref: main
path: canvas-code
# Setup Python
- name: Setup Python
uses: actions/setup-python@v2.2.1
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f ./canvas-code/requirements.txt ]; then pip install -r ./canvas-code/requirements.txt; fi
# Runs a single command using the runners shell
- name: Update grading in canvas
env:
CANVAS_TOKEN: ${{ secrets.CANVAS_TOKEN }}
CANVAS_COURSE_ID: ${{ secrets.CANVAS_COURSE_ID }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
GH_REPO_FULLNAME: ${{ secrets.GH_REPO_FULLNAME }}
run: |
export PYTHONPATH="$PWD/canvas-code/utils"
python ./canvas-code/update_task.py --mode check --pr ${{github.event.number}}