]> Git — Sourcephile - julm/rezine-rfcs.git/blob - scripts/lib.sh
scripts: init
[julm/rezine-rfcs.git] / scripts / lib.sh
1 #!/usr/bin/env bash
2 # SPDX-FileCopyrightText: 2024 Julien Moutinho (adh14) <julm+rezine@autogeree.net>
3 # SPDX-License-Identifier: AGPL-3.0-or-later
4 # shellcheck disable=SC2034
5 # shellcheck disable=SC2046
6 # shellcheck disable=SC2086
7 # shellcheck disable=SC2119
8 # shellcheck disable=SC2154
9 rfcOrga=Rézine
10 rfcRepo=rezine-rfcs
11 rfcList=rfcs
12 rfcDomain=rezine.org
13 # FIXME: host it on rezine.org?
14 rfcGitweb="https://git.sourcephile.fr/julm/$rfcRepo.git"
15
16 rfcDirMetadata () {
17 rfcRoot=$(realpath --relative-to . "${0%/*}"/..)
18 rfcDir=$(realpath --relative-to "$rfcRoot" "$rfcDir")
19 rfcBranch=$(realpath --relative-to "$rfcRoot"/rfcs "$rfcDir")
20 rfcYear=$(git log -1 --pretty=%cd --date=format:%Y "$rfcDir/advocacy.md")
21 rfcDate=$(git log -1 --pretty=%cd --date=short "$rfcDir/advocacy.md")
22 }
23
24 rfcRevision () {
25 local advocacyLatestCommit criticismsLatestCommit
26 advocacyLatestCommit=$(git rev-list --max-count=1 HEAD -- "$rfcDir/advocacy.html")
27 criticismsLatestCommit=$(git rev-list --max-count=1 HEAD -- "$rfcDir/criticisms.html")
28 rfcTagAdvocacyOld="$(git describe --tags "$advocacyLatestCommit")" || true
29 rfcTagCriticismsOld="$(git describe --tags "$criticismsLatestCommit")" || true
30 if test "${rfcTagAdvocacyOld#"${rfcBranch}v"}" != "$rfcTagAdvocacyOld"
31 then IFS=psvc read -r _num rfcRevAdvocacy _ <<<"$rfcTagAdvocacyOld"
32 else rfcRevAdvocacy=0; rfcTagAdvocacyOld=init
33 fi
34 if test "${rfcTagCriticismsOld#"${rfcBranch}v"}" != "$rfcTagCriticismsOld"
35 then IFS=psvc read -r _num _rfcRevAdvocacy rfcRevCriticisms _ <<<"$rfcTagCriticismsOld"
36 else rfcRevCriticisms=0; rfcTagCriticismsOld=init
37 fi
38 rfcRevision=v"$rfcRevAdvocacy"c"$rfcRevCriticisms"
39 rfcTag="$rfcBranch$rfcRevision"
40 }
41
42 rfcSource () {
43 if test ! "${rfcNoAdvocacy:+set}"; then
44 cat - "$rfcDir"/advocacy.md <<EOF
45 ::: information
46 Ce document est publié sous licence
47 [\${SPDX-License-Identifier}](https://spdx.org/licenses/\${SPDX-License-Identifier}.html).
48
49 Pour le citer :
50
51 > \${rfcOrga} <[RFC\${rfcTag}](mailto:\${rfcList}+\${rfcTag}@\${rfcDomain})>
52 > — « *\${title}* » — \${rfcDate} — série *Requests for Criticisms*
53 > — \${RFC-Category} « \` \${rfcBranch}\` »,
54 > plaidoirie « \` \${rfcRevisionAdvocacy}\` »,
55 > critiques « \` \${rfcRevisionCriticisms}\` »
56 > — \${for(RFC-Compasses)}boussole \${it}\${sep} & \${endfor}
57 > — <<\${rfcGitweb}/blob_plain/\${rfcTag}:/rfcs/\${rfcBranch}/index.html>>.
58
59 Vous _devriez_ consulter en priorité sa dernière version
60 qui est disponible en ligne à l'adresse :
61 <<\${rfcGitweb}/blob_plain/\${rfcBranch}:/rfcs/\${rfcBranch}/index.html>>
62 :::
63
64 EOF
65 printf '\n'
66 fi
67 if test ! "${rfcNoCriticisms:+set}"; then
68 cat "$rfcDir"/criticisms.md
69 fi
70 cat <<EOF
71
72 # Références
73
74 ::: {#refs}
75 :::
76
77 EOF
78 }
79
80 rfcMetadata () {
81 printf ' --metadata %s' \
82 rfcBranch="$rfcBranch" \
83 rfcDate="$rfcDate" \
84 rfcDir="$rfcDir" \
85 rfcDomain="$rfcDomain" \
86 rfcGitweb="$rfcGitweb" \
87 rfcList="$rfcList" \
88 rfcOrga="$rfcOrga" \
89 rfcRepo="$rfcRepo" \
90 rfcRevision="$rfcRevision" \
91 rfcRevisionAdvocacy="v$rfcRevAdvocacy" \
92 rfcRevisionCriticisms="c$rfcRevCriticisms" \
93 rfcTag="$rfcTag" \
94 rfcYear="$rfcYear"
95 }
96
97 rfcTemplate () {
98 local src
99 src=$(mktemp --suffix ".md")
100 rfcSource >"$src"
101 pandoc \
102 --wrap none \
103 $(rfcMetadata) \
104 --template "$src" \
105 "$src"
106 rm "$src"
107 }
108
109 rfcPlain () {
110 rfcTemplate |
111 pandoc --from markdown+emoji --to plain \
112 --citeproc \
113 --csl "$rfcRoot"/styles/rfc.csl \
114 $(printf " --bibliography %s" "$rfcRoot"/refs/*.json) \
115 --lua-filter "$rfcRoot"/styles/rfc.lua \
116 --variable lang=fr-FR \
117 "$@"
118 }
119
120 rfcMarkdown () {
121 rfcTemplate |
122 pandoc --from markdown+emoji --to markdown+emoji \
123 --table-of-contents \
124 --toc-depth 6 \
125 --number-sections \
126 --citeproc \
127 --csl "$rfcRoot"/styles/rfc.csl \
128 $(printf " --bibliography %s" "$rfcRoot"/refs/*.json) \
129 --lua-filter "$rfcRoot"/styles/rfc.lua \
130 --variable lang=fr-FR \
131 "$@"
132 }
133
134 rfcHTML () {
135 rfcTemplate |
136 pandoc --from markdown+emoji --to html5 \
137 --standalone \
138 --embed-resources \
139 --include-in-header "$rfcRoot"/styles/rfc.header.html \
140 --table-of-contents \
141 --toc-depth 6 \
142 --number-sections \
143 --citeproc \
144 --csl "$rfcRoot"/styles/rfc.csl \
145 $(printf " --bibliography %s" "$rfcRoot"/refs/*.json) \
146 --lua-filter "$rfcRoot"/styles/rfc.lua \
147 --variable lang=fr-FR \
148 "$@"
149 }
150
151 rfcPDF () {
152 rfcTemplate |
153 pandoc --from markdown+emoji --to pdf \
154 --pdf-engine lualatex \
155 --include-in-header "$rfcRoot"/styles/rfc.header.tex \
156 --standalone \
157 --embed-resources \
158 --table-of-contents \
159 --toc-depth 6 \
160 --number-sections \
161 --citeproc \
162 --csl "$rfcRoot"/styles/rfc.csl \
163 $(printf " --bibliography %s" "$rfcRoot"/refs/*.json) \
164 --lua-filter "$rfcRoot"/styles/rfc.lua \
165 --variable colorlinks=true \
166 --variable lang=fr-FR \
167 --variable links-as-notes=true \
168 "$@"
169 }
170
171 rfcTag () {
172 git reset
173 git diff --exit-code
174
175 # Check if $rfcRevAdvocacy must be increased.
176 rfcNoCriticisms="set" \
177 rfcHTML -o "$rfcDir"/advocacy.html
178 git add "$rfcDir"/advocacy.html
179 if ! git diff --cached --quiet "$rfcDir"/advocacy.html; then
180 rfcRevAdvocacyIncrement=1
181 # Note that $rfcRevCriticisms is not reset:
182 # criticisms have their own independant revisions
183 # because, in practice, criticisms to an old $rfcRevAdvocacy
184 # can be received and added after a new $rfcRevAdvocacy has been tagged.
185 fi
186
187 # Check if $rfcRevCriticisms must be increased.
188 rfcNoAdvocacy="set" \
189 rfcHTML \
190 -o "$rfcDir"/criticisms.html \
191 --metadata title="[RFC${rfcTag}] Critiques"
192 git add "$rfcDir"/criticisms.html
193 if ! git diff --cached --quiet "$rfcDir"/criticisms.html; then
194 rfcRevCriticismsIncrement=1
195 fi
196
197 if test "${rfcRevAdvocacyIncrement-0}" -gt 0 ||
198 test "${rfcRevCriticismsIncrement-0}" -gt 0
199 then
200 rfcRevAdvocacy=$((rfcRevAdvocacy + rfcRevAdvocacyIncrement))
201 rfcRevCriticisms=$((rfcRevCriticisms + rfcRevCriticismsIncrement))
202 rfcRevision=v"$rfcRevAdvocacy"c"$rfcRevCriticisms"
203 rfcTag="$rfcBranch$rfcRevision"
204 rfcNoCriticisms="set" \
205 rfcHTML -o "$rfcDir"/advocacy.html
206 rfcNoAdvocacy="set" \
207 rfcHTML -o "$rfcDir"/criticisms.html
208 rfcHTML -o "$rfcDir"/index.html
209 #rfcPDF -o "$rfcDir/${rfcRepo}-${rfcBranch}".pdf
210 git add "$rfcDir"/{advocacy,criticisms,index}.html
211 #git add "$rfcDir/${rfcRepo}-${rfcBranch}".pdf
212 git diff --cached --quiet ||
213 git commit -m "$rfcBranch: v$rfcRevAdvocacy c$rfcRevCriticisms"
214 git tag --force --sign --message "${rfcOrga} RFC${rfcTag}" "$rfcTag"
215 fi
216
217 git_push_remote=${git_push_remote-origin}
218 if test ! "${no_git_push:+set}"; then
219 git push ${git_push-} --follow-tags "$git_push_remote" "$rfcTag"
220 git push ${git_push-} "$git_push_remote" "$(git rev-list "$rfcTag" -1):${rfcBranch}"
221 git push ${git_push-} "$git_push_remote"
222 fi
223 }