Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • ii/inf222/v23/assignments/test-runner
1 result
Show changes
Commits on Source (2)
...@@ -33,7 +33,7 @@ for row in rows: ...@@ -33,7 +33,7 @@ for row in rows:
name = row['sortable_name'] name = row['sortable_name']
(lastname, firstname) = [s.strip() for s in name.split(',', 1)] (lastname, firstname) = [s.strip() for s in name.split(',', 1)]
(first_firstname,*more_firstnames) = firstname.split() (first_firstname,*more_firstnames) = firstname.split()
if row.get('userid','') == '': if row.get('gitid','') == '':
row['gituser'] = '' row['gituser'] = ''
users = gl.users.list(username=row['email'].replace('@uib.no','').replace('@student.uib.no','')) users = gl.users.list(username=row['email'].replace('@uib.no','').replace('@student.uib.no',''))
...@@ -41,13 +41,18 @@ for row in rows: ...@@ -41,13 +41,18 @@ for row in rows:
if len(users) == 1: if len(users) == 1:
user = users[0] user = users[0]
else: else:
more_users = gl.users.list(username=f'{first_firstname}.{lastname}') more_users = gl.users.list(username=row['login_id'])
if len(more_users) == 1: if len(more_users) == 1:
user = more_users[0] user = more_users[0]
else:
more_users = gl.users.list(username=f'{first_firstname}.{lastname}')
if len(more_users) == 1:
user = more_users[0]
if user: if user:
row['gituser'] = user.username row['gituser'] = user.username
row['gitid'] = user.id row['gitid'] = user.id
print("Found", format_user(row))
elif len(users) == 0: elif len(users) == 0:
if 'uib.no' in row['email']: if 'uib.no' in row['email']:
missing.append(row) missing.append(row)
...@@ -76,6 +81,8 @@ if 'gituser' not in fieldnames: ...@@ -76,6 +81,8 @@ if 'gituser' not in fieldnames:
fieldnames.append('gituser') fieldnames.append('gituser')
if 'gitid' not in fieldnames: if 'gitid' not in fieldnames:
fieldnames.append('gitid') fieldnames.append('gitid')
if 'gitoverride' not in fieldnames:
fieldnames.append('gitoverride')
with open('students.csv','w') as csvfile: with open('students.csv','w') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames) writer = csv.DictWriter(csvfile, fieldnames)
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
# Usage: run-tests [compile] [test] # Usage: run-tests [compile] [test]
# #
BUILD_SUCCESSES=0
BUILD_FAILURES=0
SUCCESSES=0 SUCCESSES=0
FAILURES=0 FAILURES=0
...@@ -15,18 +17,21 @@ compile() ...@@ -15,18 +17,21 @@ compile()
echo "==========Compiling Test Files==========" echo "==========Compiling Test Files=========="
echo "----------------------------------------" echo "----------------------------------------"
for i in $(cd "$TEST_DIR"; find . -name '*_Test*.hs'); do [ -d "$REPORT_DIR" ] || mkdir -p "$REPORT_DIR"
for i in $(cd "$TEST_DIR"; find . -name 'wip*' -prune -o -name '*_Test*.hs' -print); do
i="${i#./}" # strip leading ./ i="${i#./}" # strip leading ./
o="${i%.hs}" # strip trailing .hs o="${i%.hs}" # strip trailing .hs
r=$(echo "$o" | sed -e 's;/;_;g') # / → _
mkdir -p "$BUILD_DIR/$(dirname $o)" mkdir -p "$BUILD_DIR/$(dirname $o)"
echo "--Compiling $i to $o---" echo "--Compiling $i to $o---"
if ghc -i"$STUDENT_DIR" --make "$TEST_DIR/$i" -o "$BUILD_DIR/$o"; then if ghc -i"$STUDENT_DIR" --make "$TEST_DIR/$i" -o "$BUILD_DIR/$o" | tee "$REPORT_DIR/${r}_ghc.log"; then
SUCCESSES=$(( SUCCESSES + 1 )) BUILD_SUCCESSES=$(( BUILD_SUCCESSES + 1 ))
else else
FAILURES=$(( FAILURES + 1 )) BUILD_FAILURES=$(( BUILD_FAILURES + 1 ))
fi fi
done done
...@@ -83,6 +88,9 @@ while [ $# -gt 0 ]; do ...@@ -83,6 +88,9 @@ while [ $# -gt 0 ]; do
elif [ "$1" = "test" ]; then elif [ "$1" = "test" ]; then
run_tests run_tests
shift shift
elif [ "$1" = "clean" ]; then
rm -rf "$BUILD_DIR"
shift
elif [ "$1" = "-s" ]; then elif [ "$1" = "-s" ]; then
shift shift
STUDENT_DIR="$1" STUDENT_DIR="$1"
...@@ -93,14 +101,16 @@ while [ $# -gt 0 ]; do ...@@ -93,14 +101,16 @@ while [ $# -gt 0 ]; do
shift shift
else else
echo >> /dev/stderr Bad argument: "$1" echo >> /dev/stderr Bad argument: "$1"
echo >> /dev/stderr usage: run-tests [-t TEST_DIR] [-s STUDENT_DIR] [compile] [test] echo >> /dev/stderr usage: run-tests [-t TEST_DIR] [-s STUDENT_DIR] [compile] [test] [clean]
exit 1 exit 1
fi fi
done done
if [ $BUILD_FAILURES -gt 0 ]; then
echo $SUCCESSES successful tests, $FAILURES failures echo $BUILD_FAILURES tests failed to build
fi
echo $SUCCESSES successful tests, $FAILURES test failures
echo "========================================" echo "========================================"
echo "@-----------------DONE-----------------@" echo "@-----------------DONE-----------------@"
echo "========================================" echo "========================================"
[ $FAILURES -eq 0 ] # set exit code [ $FAILURES -eq 0 ] && [ $BUILD_FAILURES -eq 0 ] # set exit code
...@@ -119,6 +119,7 @@ class AssignmentFork: ...@@ -119,6 +119,7 @@ class AssignmentFork:
def check_membership(self, resource: Project | Group, user: User | CurrentUser | int): def check_membership(self, resource: Project | Group, user: User | CurrentUser | int):
user_id = getattr(user, 'id', user) user_id = getattr(user, 'id', user)
#logger.debug('checking membership for %s %s %s', user, resource, user_id)
try: try:
membership = resource.members.get(user_id) membership = resource.members.get(user_id)
if membership.access_level != gitlab.const.OWNER_ACCESS and membership.access_level != self.access_level: if membership.access_level != gitlab.const.OWNER_ACCESS and membership.access_level != self.access_level:
...@@ -238,23 +239,24 @@ class AssignmentFork: ...@@ -238,23 +239,24 @@ class AssignmentFork:
except gitlab.GitlabError as e: except gitlab.GitlabError as e:
self.__failed(e, self.assignment) self.__failed(e, self.assignment)
def check_user_project(self, user: User | CurrentUser | str | int): def check_user_project(self, user: User | CurrentUser | str | int, details = False, override_project_username = None):
try: try:
return self.__check_user_project(self.get_user(user)) return self.__check_user_project(self.get_user(user), details,override_project_username)
except gitlab.GitlabError as e: except gitlab.GitlabError as e:
self.__failed(e, user) self.__failed(e, user)
def __check_user_project(self, user: User | CurrentUser): def __check_user_project(self, user: User | CurrentUser, details:bool, override_project_username:str|None):
config = self.gitlab_config.copy() config = self.gitlab_config.copy()
try: try:
config['name'] = f'{user.username}{self.assignment.name}' config['name'] = f'{user.username}{self.assignment.name}'
project_slug = f'{user.username}_{self.assignment.path}' project_slug = f'{override_project_username or user.username}_{self.assignment.path}'
self._last_user = user self._last_user = user
self._last_project = project = self.gl.projects.get( self._last_project = project = self.gl.projects.get(
f'{self.namespace["full_path"]}/{project_slug}') f'{self.namespace["full_path"]}/{project_slug}')
logger.debug('Found project %s for user %s', project.path_with_namespace, user.username) logger.debug('Found project %s for user %s', project.path_with_namespace, user.username)
except GitlabGetError: except GitlabGetError:
details = True
url = self.assignment.ssh_url_to_repo.replace( url = self.assignment.ssh_url_to_repo.replace(
f'/{self.assignment.path}.git', f'/{project_slug}.git') f'/{self.assignment.path}.git', f'/{project_slug}.git')
desc = self.assignment.description desc = self.assignment.description
...@@ -277,7 +279,7 @@ class AssignmentFork: ...@@ -277,7 +279,7 @@ class AssignmentFork:
else: else:
project = None project = None
self.__change('add_fork', project,source=self.assignment) self.__change('add_fork', project,source=self.assignment)
if project != None: if project != None and details:
self.check_project_setup(user, project, config) self.check_project_setup(user, project, config)
return project return project
...@@ -308,16 +310,29 @@ if __name__ == '__main__': ...@@ -308,16 +310,29 @@ if __name__ == '__main__':
args = sys.argv[1:] args = sys.argv[1:]
file = None file = None
assignment = None assignment = None
while len(args) > 1: details = False
skip = 0
while len(args) > 0:
if args[0] == '-f': if args[0] == '-f':
file = args[1] file = args[1]
print('Students file:', file)
args = args[2:] args = args[2:]
elif args[0] == '-a': elif args[0] == '-a':
assignment = args[1] assignment = args[1]
print('Assignment:', assignment)
args = args[2:]
elif args[0] == '-d':
print('Details enabled!')
details = True
args = args[1:]
elif args[0] == '-s':
skip = int(args[1])
print('Skipping', skip)
args = args[2:] args = args[2:]
else: else:
raise ValueError(args[0]) raise ValueError(args[0])
projects : list[tuple[str, Project|None]] = []
if file == None: if file == None:
print("Missing input file") print("Missing input file")
elif assignment == None: elif assignment == None:
...@@ -331,9 +346,19 @@ if __name__ == '__main__': ...@@ -331,9 +346,19 @@ if __name__ == '__main__':
n = 0 n = 0
for row in reader: for row in reader:
if row['gitid'].isdigit(): if row['gitid'].isdigit():
assignment.check_user_project(int(row['gitid'])) print(n, row)
time.sleep(1) if n >= skip:
proj = assignment.check_user_project(int(row['gitid']), details, row.get('gitoverride'))
projects.append((row.get('gitoverride') or row['gituser'], proj))
if details:
time.sleep(1)
else:
time.sleep(0.01)
n = n + 1 n = n + 1
with open('project-links.txt', 'w') as f:
for u,p in projects:
if p:
f.write(f'{u} {p.ssh_url_to_repo}\n')
finally: finally:
with open('changes.txt', 'w') as f: with open('changes.txt', 'w') as f:
f.write(pformat(assignment.changelog, sort_dicts=False)) f.write(pformat(assignment.changelog, sort_dicts=False))
......