|
1 | 1 | #!/bin/sh |
2 | 2 |
|
3 | | -cur=46 |
4 | | -next=47 |
| 3 | +# TODO: Automate finding next publication date |
| 4 | +nextdate="2019-02-20" |
5 | 5 |
|
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 |
8 | 10 |
|
9 | | -prev_month="November 2018" |
10 | | -next_month="December 2018" |
11 | 11 |
|
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 | + |
15 | 57 |
|
16 | 58 | # If needed make sure we are up-to-date |
17 | 59 |
|
18 | 60 | git checkout master |
19 | | -git pull origin master |
| 61 | +git pull horigin master |
20 | 62 |
|
21 | 63 | # Publish current draft |
22 | 64 |
|
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 |
24 | 66 |
|
25 | | -git commit -m "Publish rn-$cur in _posts/" |
| 67 | +git commit -m "Publish rn-$cur in $dst_dir/" |
26 | 68 |
|
27 | 69 | # Create a draft for next edition |
28 | 70 |
|
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 |
30 | 74 |
|
31 | | -git mv rev_news/drafts/edition-$cur.md rev_news/drafts/edition-$next.md |
| 75 | +# TODO: Use only one Perl invocation |
32 | 76 |
|
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 |
34 | 78 |
|
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 |
36 | 81 |
|
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 |
38 | 83 |
|
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 |
40 | 85 |
|
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 |
42 | 87 |
|
0 commit comments