Skip to content

Commit 66cec42

Browse files
committed
publish_edition: automate using Dscho's ideas
1 parent a685463 commit 66cec42

File tree

1 file changed

+64
-19
lines changed

1 file changed

+64
-19
lines changed

publish_edition.sh

Lines changed: 64 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,87 @@
11
#!/bin/sh
22

3-
cur=46
4-
next=47
3+
# TODO: Automate finding next publication date
4+
nextdate="2019-02-20"
55

6-
today="2018-12-19"
7-
nextdate="2019-01-23"
6+
# TODO: Find the commit below using something like:
7+
# TODO: git log -1 --grep "Add draft for rn" --oneline
8+
# TODO: or better use a template
9+
last_draft_commit=52c3265bc4485bc3db8262fd4a9907a99849e046
810

9-
prev_month="November 2018"
10-
next_month="December 2018"
1111

12-
# Find this commit using something like:
13-
# git log -1 --grep "Add draft for rn" --oneline
14-
last_draft_commit=5bc243932ea7938830757e8370df6bd86df39cab
12+
repo_url="https://github.com/git/git.github.io.git"
13+
known_good_commit="5bc243932ea7938830757e8370df6bd86df39cab"
14+
src_dir="rev_news/drafts"
15+
dst_dir="_posts"
16+
17+
die() {
18+
printf >&2 "FATAL: %s\n" "$@"
19+
exit 1
20+
}
21+
22+
# Basic checks
23+
24+
type git >/dev/null || die "git not found" "we need git"
25+
26+
git show "$known_good_commit" >/dev/null 2>&1 ||
27+
die "$known_good_commit not found" \
28+
"we need to be in a repo cloned from $repo_url"
29+
30+
test -d "$src_dir" || die "no source '$src_dir' directory"
31+
32+
test -d "$dst_dir" || die "no destination '$dst_dir' directory"
33+
34+
nb_ed=$(ls "$src_dir"/edition-*.md | wc -l)
35+
36+
test "$nb_ed" -eq 0 && die "no 'edition-*.md' file in '$src_dir' directory"
37+
38+
test "$nb_ed" -gt 1 && die "more than one 'edition-*.md' file in '$src_dir' directory"
39+
40+
41+
# Find info we need
42+
43+
edition=$(ls "$src_dir"/edition-*.md)
44+
45+
cur=$(expr "$edition" : "rev_news/drafts/edition-\([0-9]\+\).md")
46+
47+
test -n "$cur" || die "'$edition' should contain a number"
48+
49+
next=$(expr "$cur" + 1)
50+
51+
today=$(date "+%Y-%m-%d")
52+
53+
# Each edition covers the previous month
54+
next_month=$(LANG=C date "+%B %Y")
55+
prev_month=$(LANG=C date --date="$today - 1 month" "+%B %Y")
56+
1557

1658
# If needed make sure we are up-to-date
1759

1860
git checkout master
19-
git pull origin master
61+
git pull horigin master
2062

2163
# Publish current draft
2264

23-
git mv rev_news/drafts/edition-$cur.md _posts/$today-edition-$cur.markdown
65+
git mv "$src_dir"/edition-$cur.md "$dst_dir"/$today-edition-$cur.markdown
2466

25-
git commit -m "Publish rn-$cur in _posts/"
67+
git commit -m "Publish rn-$cur in $dst_dir/"
2668

2769
# Create a draft for next edition
2870

29-
git cherry-pick "$last_draft_commit" # Cherry pick commit with the last draft
71+
git cherry-pick "$last_draft_commit"
72+
73+
git mv "$src_dir"/edition-$cur.md "$src_dir"/edition-$next.md
3074

31-
git mv rev_news/drafts/edition-$cur.md rev_news/drafts/edition-$next.md
75+
# TODO: Use only one Perl invocation
3276

33-
perl -pi -e "s/Edition $cur/Edition $next/g" rev_news/drafts/edition-$next.md
77+
perl -pi -e "s/Edition $cur/Edition $next/g" "$src_dir"/edition-$next.md
3478

35-
perl -pi -e "s/${cur}th edition/${next}th edition/g" rev_news/drafts/edition-$next.md
79+
# TODO: fix "th" when $cur or $next end with 1, 2 or 3
80+
perl -pi -e "s/${cur}th edition/${next}th edition/g" "$src_dir"/edition-$next.md
3681

37-
perl -pi -e "s/$today/$nextdate/g" rev_news/drafts/edition-$next.md
82+
perl -pi -e "s/$today/$nextdate/g" "$src_dir"/edition-$next.md
3883

39-
perl -pi -e "s/$prev_month/$next_month/g" rev_news/drafts/edition-$next.md
84+
perl -pi -e "s/$prev_month/$next_month/g" "$src_dir"/edition-$next.md
4085

41-
git commit --amend -m "Add draft for rn-$next" rev_news/drafts/edition-$next.md
86+
git commit --amend -m "Add draft for rn-$next" "$src_dir"/edition-$cur.md "$src_dir"/edition-$next.md
4287

0 commit comments

Comments
 (0)