Skip to content

Commit f911fe0

Browse files
ziesskipowe97bmcutler
authored
[Feature:RainbowGrades] Display RainbowGrades version (#56)
This update allows all users of RainbowGrades (i.e. instructors and students) to see the build version at the bottom of the RainbowGrades page. This version info is vital as it allows instructors to know which version they are currently using. Having this version information readily available will enable instructors to provide accurate details when reporting any issues or errors they encounter. In turn, developers can use this version information to identify any potential discrepancies caused by outdated versions and assist instructors more efficiently in resolving their concerns. [Instructor view] ![Screen Shot 2023-07-28 at 11 49 10 AM](https://github.com/Submitty/RainbowGrades/assets/123261952/81ce995a-0086-4ead-9f0b-0d3686017d77) [student view] ![Screen Shot 2023-07-28 at 1 39 52 PM](https://github.com/Submitty/RainbowGrades/assets/123261952/0776a2e8-6f9d-4567-bf6a-e38c6142300f) --------- Co-authored-by: William Powe <[email protected]> Co-authored-by: Barb Cutler <[email protected]> Co-authored-by: Barb Cutler <Barb Cutler>
1 parent d2a0118 commit f911fe0

File tree

4 files changed

+94
-4
lines changed

4 files changed

+94
-4
lines changed

MakefileHelper

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: default pull push all compile overall section lab hw test quiz final zone clean src_clean remove_json_comments
1+
.PHONY: default pull push all compile overall section lab hw test quiz final zone clean src_clean remove_json_comments version
22

33
default: overall
44

@@ -26,6 +26,9 @@ endif
2626

2727
nlohmann_json_dir=${RAINBOW_GRADES_DIRECTORY}/../vendor/nlohmann/json
2828

29+
export RAINBOW_GRADES_DIRECTORY
30+
export REPORTS_DIRECTORY
31+
2932
${nlohmann_json_dir}:
3033
mkdir -p ${nlohmann_json_dir}
3134
wget https://github.com/nlohmann/json/releases/download/v3.1.2/include.zip -O ${RAINBOW_GRADES_DIRECTORY}/../vendor/nlohmann_json.zip
@@ -75,6 +78,8 @@ endif
7578

7679
json_include = -I${nlohmann_json_dir}/include/
7780

81+
version:
82+
python3 ${RAINBOW_GRADES_DIRECTORY}/track_Rainbow_version.py
7883

7984
remove_json_comments: customization.json
8085
cpp -xc++ $< | sed -e '/^#/d' > customization_no_comments.json
@@ -93,12 +98,12 @@ process_grades.out: \
9398
individual_summary_html all_students_summary_csv all_students_summary_html:
9499
mkdir -p $@
95100

96-
compile: remove_json_comments process_grades.out individual_summary_html all_students_summary_html all_students_summary_csv
101+
compile: remove_json_comments version process_grades.out individual_summary_html all_students_summary_html all_students_summary_csv
97102

98103
clean:
99104
rm -rf *~ *.dSYM
100105
rm -f process_grades.out
101-
rm -f customization_no_comments.json files_json.txt
106+
rm -f customization_no_comments.json files_json.txt RG_version.json
102107

103108
src_clean: clean
104109
rm -f ${json_syntax_checker.py}

main.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ std::vector<std::string> OMIT_SECTION_FROM_STATS;
3737
std::string OUTPUT_FILE = "./output.html";
3838
std::string OUTPUT_CSV_FILE = "./output.csv";
3939
std::string CUSTOMIZATION_FILE = "./customization_no_comments.json";
40+
std::string RG_VERSION_FILE = "./RG_version.json";
4041

4142
std::string RAW_DATA_DIRECTORY = "./raw_data/all_grades/";
4243
std::string INDIVIDUAL_FILES_OUTPUT_DIRECTORY = "./individual_summary_html/";
4344
std::string ALL_STUDENTS_OUTPUT_DIRECTORY = "./all_students_summary_html/";
44-
std::string ALL_STUDENTS_OUTPUT_DIRECTORY_CSV = "./all_students_summary_csv/";
45+
std::string ALL_STUDENTS_OUTPUT_DIRECTORY_CSV = "./all_students_summary_csv/";
4546

4647
nlohmann::json GLOBAL_CUSTOMIZATION_JSON;
4748

output.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
extern std::string OUTPUT_FILE;
2626
extern std::string OUTPUT_CSV_FILE;
27+
extern std::string RG_VERSION_FILE;
28+
2729
extern std::string ALL_STUDENTS_OUTPUT_DIRECTORY;
2830
extern std::string ALL_STUDENTS_OUTPUT_DIRECTORY_CSV;
2931

@@ -1389,5 +1391,34 @@ void end_table(std::ofstream &ostr, bool for_instructor, Student *s) {
13891391

13901392
}
13911393

1394+
// RAINBOW GRADE VERSION DISPLAY
1395+
std::ifstream istr(RG_VERSION_FILE.c_str());
1396+
assert (istr.good());
1397+
nlohmann::json j = nlohmann::json::parse(istr);
1398+
// current_commit_hash_rg (Full hash) is not used, parsing just for possible future use
1399+
nlohmann::json current_commit_hash_rg = j["installed_commit_rg"];
1400+
nlohmann::json current_short_commit_hash_rg = j["short_installed_commit_rg"];
1401+
nlohmann::json current_git_tag_rg = j["most_recent_git_tag_rg"];
1402+
1403+
// Remove double quotation
1404+
std::string rainbow_short_hash = current_short_commit_hash_rg;
1405+
std::string rainbow_git_tag = current_git_tag_rg;
1406+
rainbow_git_tag.erase(std::remove(rainbow_git_tag.begin(), rainbow_git_tag.end(), '\"'), rainbow_git_tag.end());
1407+
rainbow_short_hash.erase(std::remove(rainbow_short_hash.begin(), rainbow_short_hash.end(), '\"'), rainbow_short_hash.end());
1408+
1409+
std::time_t currentTime = std::time(nullptr);
1410+
// Convert the time to the local time struct
1411+
std::tm* localTime = std::localtime(&currentTime);
1412+
// Extract the current year from the local time struct
1413+
int currentYear = localTime->tm_year + 1900;
1414+
1415+
1416+
ostr << "<p>&copy; " << currentYear << " <a href=\"https://submitty.org/instructor/course_settings/rainbow_grades/index\" target=\"_blank\" class=\"black-btn\">Submitty/RainbowGrades</a> <a href=\"https://github.com/Submitty/RainbowGrades/releases/tag/" << rainbow_git_tag
1417+
<< "\" target=\"_blank\" title=\"" << rainbow_git_tag << " " << rainbow_short_hash
1418+
<< "\" class=\"black-btn\">" << rainbow_git_tag << "</a></p>" << std::endl;
1419+
1420+
1421+
1422+
13921423
ostr.close();
13931424
}

track_Rainbow_version.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import json
5+
import subprocess
6+
7+
CURRENT_PATH = os.path.dirname(os.path.realpath(__file__))
8+
RG_DIR = os.environ.get('RAINBOW_GRADES_DIRECTORY')
9+
REPORT_DIR = os.environ.get('REPORTS_DIRECTORY')
10+
WORKING_DIRECTORY = "."
11+
12+
if __name__ == "__main__":
13+
14+
json_dir = os.path.join(WORKING_DIRECTORY, "RG_version.json")
15+
output_dict = {}
16+
current_commit_hash_rg = 'unknown'
17+
current_short_commit_hash_rg = 'unknown'
18+
current_git_tag_rg = 'unknown'
19+
20+
try:
21+
#run the command 'git rev-parse HEAD' from the RainbowGrades repository directory
22+
current_commit_hash_rg = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=RG_DIR)
23+
current_commit_hash_rg = current_commit_hash_rg.decode('ascii').strip()
24+
current_short_commit_hash_rg = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'], cwd=RG_DIR)
25+
current_short_commit_hash_rg = current_short_commit_hash_rg.decode('ascii').strip()
26+
print("Commit {0} is currently installed on this system.".format(current_commit_hash_rg))
27+
except:
28+
print("ERROR: could not determine commit hash.")
29+
current_commit_hash_rg = 'unknown'
30+
31+
try:
32+
#run the command 'git describe --tag --abbrev=0' from the RainbowGrades repository directory
33+
current_git_tag_rg = subprocess.check_output(['git', 'describe', '--tag', '--abbrev=0'], cwd=RG_DIR)
34+
current_git_tag_rg = current_git_tag_rg.decode('ascii').strip()
35+
print("Tag {0} is the most recent git tag.".format(current_git_tag_rg))
36+
except:
37+
print("ERROR: could not determine current git tag.")
38+
current_git_tag_rg = 'unknown'
39+
40+
41+
#remove newline at the end of the hash and tag and convert them from bytes to ascii.
42+
43+
output_dict["installed_commit_rg"] = current_commit_hash_rg
44+
output_dict["short_installed_commit_rg"] = current_short_commit_hash_rg
45+
output_dict["most_recent_git_tag_rg"] = current_git_tag_rg
46+
47+
48+
try:
49+
#Update rainbow_grades/RG_version.json to reflect the current commit hash.
50+
with open(json_dir, 'w') as outfile:
51+
json.dump(output_dict, outfile, indent=2)
52+
except:
53+
print("ERROR: could not write to {0}".format(json_dir))

0 commit comments

Comments
 (0)