-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fixes date comparison and test exec
- Loading branch information
Showing
1 changed file
with
32 additions
and
21 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,8 +1,10 @@ | ||
''' Presentation Configuration | ||
''' | ||
import datetime as dt | ||
import os | ||
import shlex | ||
import subprocess | ||
from typing import Dict, List, Set, Tuple | ||
from typing import Dict, List, Sequence, Set | ||
|
||
import pytz | ||
import schema | ||
|
@@ -42,7 +44,7 @@ def main(): | |
key): value for key, value in raw_schedule.items()} | ||
future_schedule = {date: sequence | ||
for date, sequence in full_schedule.items() | ||
if date > exec_timestamp} | ||
if date > exec_timestamp.date()} | ||
assert len(future_schedule) > 0 | ||
next_date = min(future_schedule.keys()) | ||
|
||
|
@@ -52,17 +54,17 @@ def main(): | |
all_call_projects: Set[str] = set( | ||
projects.keys()).difference(current_projects) | ||
print(all_call_projects) | ||
subprocess.check_call( | ||
_exec_cmd( | ||
['git', 'config', 'user.email', '[email protected]'] | ||
) | ||
subprocess.check_call( | ||
_exec_cmd( | ||
['git', 'config', 'user.name', 'E4E GitHub Actions'] | ||
) | ||
|
||
__update_latex(current_projects, projects, all_call_projects) | ||
|
||
# Create the appropriate branches | ||
__create_branches(current_projects, projects, next_date.isocalendar()) | ||
__create_branches(current_projects, projects, next_date) | ||
|
||
|
||
def __update_latex(current_projects: List[str], projects: Dict, all_call_projects: Set[str]): | ||
|
@@ -79,52 +81,50 @@ def __update_latex(current_projects: List[str], projects: Dict, all_call_project | |
handle.write(f'\\section{{{projects[project]["name"]}}}\n') | ||
handle.write(f'\\include{{{projects[project]["latex"]}}}\n') | ||
|
||
subprocess.check_call( | ||
_exec_cmd( | ||
[ | ||
'git', 'add', | ||
'active_all_call.tex', | ||
'active_order.tex', | ||
'active_sections.tex' | ||
] | ||
) | ||
subprocess.check_call([ | ||
_exec_cmd([ | ||
'git', 'commit', | ||
'-m', f'feat!: Configures presentation for {current_projects}' | ||
'-m', f'feat!: Configures presentation for {", ".join(current_projects)}' | ||
]) | ||
subprocess.check_call([ | ||
_exec_cmd([ | ||
'git', 'push' | ||
]) | ||
|
||
|
||
def __create_branches(current_projects: List[str], | ||
projects: Dict, | ||
calendar_tuple: Tuple): | ||
current_year = calendar_tuple[0] | ||
next_weeknum = calendar_tuple[1] + 1 | ||
presentation_date: dt.date): | ||
|
||
for project in current_projects: | ||
project_params = projects[project] | ||
branch_name = f'{project_params["branch"]}_{current_year}_{next_weeknum}' | ||
subprocess.check_call( | ||
branch_name = f'{project_params["branch"]}_{presentation_date.isoformat()}' | ||
_exec_cmd( | ||
['git', 'checkout', 'main'] | ||
) | ||
subprocess.check_call( | ||
_exec_cmd( | ||
['git', 'checkout', '-b', branch_name] | ||
) | ||
# Reset the slides | ||
with open('base_project.tex', 'r', encoding='utf-8') as reference_handle, \ | ||
open(project_params['latex'] + '.tex', 'w', encoding='utf-8') as target_handle: | ||
target_handle.write( | ||
f'% Slides for {current_year} Week {next_weeknum}\n') | ||
f'% Slides for {presentation_date.isoformat()}\n') | ||
for line in reference_handle: | ||
target_handle.write(line) | ||
subprocess.check_call( | ||
_exec_cmd( | ||
['git', 'add', project_params['latex'] + '.tex'] | ||
) | ||
subprocess.check_call( | ||
_exec_cmd( | ||
['git', 'commit', '-m', 'fix: Resetting slides'] | ||
) | ||
subprocess.check_call( | ||
_exec_cmd( | ||
['git', 'push', '--set-upstream', 'origin', branch_name] | ||
) | ||
command = [ | ||
|
@@ -133,14 +133,25 @@ def __create_branches(current_projects: List[str], | |
'-t', project_params['name'], | ||
'-d', | ||
'-H', branch_name, | ||
'-b', f'Weekly presentation slides for {project_params["name"]}' | ||
'-b', (f'Weekly presentation slides for {project_params["name"]} for ' | ||
f'{presentation_date.isoformat()}') | ||
] | ||
for assignee in project_params['assignees']: | ||
command.extend(('-a', assignee)) | ||
subprocess.check_call( | ||
_exec_cmd( | ||
command | ||
) | ||
|
||
|
||
def _exec_cmd(cmd: Sequence[str]): | ||
# only exec if GH_TOKEN is defined, i.e. in GitHub Actions | ||
if 'GH_TOKEN' in os.environ: | ||
subprocess.check_call( | ||
args=cmd | ||
) | ||
else: | ||
print(shlex.join(cmd)) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |