OILS / regtest / aports-update-causes.sh View on Github | oils.pub

148 lines, 45 significant
1#!/usr/local/bin/ysh_
2#
3# Generate a new report, based on the latest report available.
4# Used to update causes in a report without rebuilding any packages.
5#
6# Example usage:
7# regtest/aports-update-causes.sh update-latest main # generate new report for main
8# regtest/aports-update-causes.sh update-latest community # generate new report for community
9
10const REPORTS_PATH="_tmp/aports-report"
11
12proc stdout_to_stderr() {
13 exec 3>&1
14 exec 1>&2
15}
16
17proc restore_stdout() {
18 exec 1>&3
19 exec 3>&-
20}
21
22func useMainReports(kind) {
23 if(kind === 'main') {
24 return (true)
25 }
26 return (false)
27}
28
29func useCommunityReports(kind) {
30 if (kind === 'community') {
31 return (true)
32 }
33 return (false)
34}
35
36func calculateNewEpoch(use_main) {
37 var new_epoch = $(date +%Y-%m-%d)
38 if (use_main === false) {
39 setvar new_epoch = new_epoch ++ "-comm"
40 }
41 return (new_epoch ++ "-cause")
42}
43
44proc get-last-epoch(use_main) {
45 var last_epoch = ""
46 var additional_grep = ""
47 if (use_main === 'true') {
48 setvar additional_grep = " | grep -v comm "
49 } else {
50 setvar additional_grep = " | grep comm "
51 }
52 setvar last_epoch = $(ssh oils@op.oils.pub "ls /home/oils/op.oils.pub/aports-build | grep .wwz $additional_grep | sort -r | head -n 1")
53 setvar last_epoch = ${last_epoch%.wwz}
54 echo $last_epoch
55}
56
57proc rename-editing-epoch(new_epoch) {
58 var pattern = / u'readonly EDITING_APORTS_EPOCH=\'' dot* /
59 var new_value = u'readonly EDITING_APORTS_EPOCH=\'' ++ new_epoch ++ u'.wwz\''
60 sed -i -E "s/$pattern/$new_value/" regtest/aports-html.sh
61}
62
63# adds a new entry with new_epoch right under the entry
64# of original_epoch in the html for published.html
65proc add-report-entry(original_epoch, new_epoch, use_main) {
66 var last_entry = "- [$original_epoch]($original_epoch.wwz/_tmp/aports-report/$original_epoch/diff_merged.html)"
67 var entry = "- [$new_epoch]($new_epoch.wwz/_tmp/aports-report/$new_epoch/diff_merged.html)"
68
69 if(use_main === 'false') {
70 # indent to indicate partial run, which we are assuming for community for now
71 setvar entry = ' ' + entry
72 }
73
74 # get the line number of the entry with original_epoch so we can append our line
75 var insert_line = $(grep -n -F -- "$last_entry" regtest/aports-html.sh | cut -d: -f1)
76
77 sed -i "${insert_line}a\\${entry}" regtest/aports-html.sh
78}
79
80proc download-report(epoch) {
81 rename-editing-epoch "$epoch"
82
83 regtest/aports-html.sh sync-old-wwz
84}
85
86proc prepare-new-report(original_epoch, new_epoch, use_main) {
87 regtest/aports-html.sh extract-old-wwz $new_epoch
88
89 # add-report-entry $original_epoch $new_epoch $use_main
90}
91
92proc generate-new-report(new_epoch, use_main) {
93 # assuming runs from main are full runs and from community partial
94 # this might break, should probably find a better way to do this
95 # Maybe check contents of _tmp/aports-report/$original_epoch?
96 if (use_main === 'true') {
97 regtest/aports-html.sh write-all-reports "_tmp/aports-report/$new_epoch"
98 } else {
99 regtest/aports-html.sh write-disagree-reports "_tmp/aports-report/$new_epoch"
100 }
101}
102
103proc deploy-new-report(new_epoch) {
104 regtest/aports-html.sh make-wwz "_tmp/aports-report/$new_epoch"
105 regtest/aports-html.sh deploy-wwz-op "_tmp/aports-report/$new_epoch.wwz"
106}
107
108proc update-latest(kind) {
109 ### Create a new report based on the most recent published report
110 ### Create the new report using a newer `causes.awk` file
111 ### Does the following steps:
112 ### 0. Determine latest report
113 ### 1. Fetch latest published report
114 ### 2. Add entry of new report to published.html
115 ### 3. Generate report using new causes.awk
116 ### 4. Upload new report
117 ###
118 ### Current limitations:
119 ### Can run only once per day, otherwise $new_epoch already exists
120 ### Assumes community runs are partial runs, and main runs are full.
121 ### If this is not true the script breaks
122 stdout_to_stderr
123
124 var use_main = useMainReports(kind)
125 if (use_main === false and useCommunityReports(kind) === false) {
126 echo "kind should be main or community, got: $kind"
127 exit 1
128 }
129
130 var original_epoch=$(get-last-epoch $use_main)
131 var new_epoch = calculateNewEpoch(use_main)
132
133 echo "Generating new report with epoch $new_epoch based on $original_epoch for $kind"
134
135 download-report $original_epoch
136
137 prepare-new-report $original_epoch $new_epoch $use_main
138
139 generate-new-report $new_epoch $use_main
140
141 deploy-new-report $new_epoch
142
143 restore_stdout
144
145 echo "https://op.oils.pub/aports-build/$new_epoch.wwz/_tmp/aports-report/$new_epoch/diff_merged.html"
146}
147
148runproc @ARGV