generated from ministryofjustice/template-documentation-site
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Script for quickly reporting outdated pages. Added as target to Makefile Makefile has simple help feature added as default target.
- Loading branch information
Stephen James
committed
Oct 20, 2023
1 parent
66a6248
commit f87685b
Showing
2 changed files
with
111 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
.DEFAULT_GOAL := help | ||
IMAGE := ministryofjustice/tech-docs-github-pages-publisher:1.4 | ||
|
||
# Use this to run a local instance of the documentation site, while editing | ||
.PHONY: preview | ||
preview: | ||
.PHONY: preview report | ||
|
||
preview: ## Run a local instance of the documentation site, while editing | ||
docker run --rm \ | ||
-v $$(pwd)/config:/app/config \ | ||
-v $$(pwd)/source:/app/source \ | ||
-p 4567:4567 \ | ||
-it $(IMAGE) /publishing-scripts/preview.sh | ||
|
||
|
||
report: ## Review which pages have expired | ||
bash ./report-for-daniel-the-manual-spaniel.sh | ||
|
||
help: | ||
@grep -h -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/usr/bin/env bash | ||
|
||
## Simple script to quickly review which pages have expired and which are due | ||
## to expire in next three weeks. | ||
|
||
# | ||
# Reads N lines from input, keeping further lines in the input. | ||
# | ||
# Arguments: | ||
# $1: number N of lines to read. | ||
# | ||
# Return code: | ||
# 0 if at least one line was read. | ||
# 1 if input is empty. | ||
# | ||
function readlines () { | ||
local N="$1" | ||
local line | ||
local rc="1" | ||
|
||
# Read at most N lines | ||
for i in $(seq 1 $N) | ||
do | ||
# Try reading a single line | ||
read line | ||
if [ $? -eq 0 ] | ||
then | ||
# Output line | ||
echo $line | ||
rc="0" | ||
else | ||
break | ||
fi | ||
done | ||
|
||
# Return 1 if no lines where read | ||
return $rc | ||
} | ||
|
||
report=$(ag last_reviewed_on -A 1 --ignore "*.txt" --ignore "*.sh" --group) | ||
|
||
today=$(date '+%Y-%m-%d') | ||
|
||
expiring_pages="Following pages expiring in next 3 weeks:\n" | ||
expired_pages="Following pages have expired:\n" | ||
|
||
|
||
while chunk=$(readlines 4) | ||
do | ||
echo "******************************************************************************************" | ||
echo "$chunk" | ||
echo "" | ||
|
||
last_reviewed_on="$(echo "$chunk" | grep "last_reviewed_on" | cut -d " " -f 2)" | ||
echo "last_reviewed_on: ${last_reviewed_on}" | ||
|
||
review_in="$(echo "$chunk" | grep "review_in" | cut -d " " -f 2)" | ||
echo "review_in: ${review_in}" | ||
|
||
review_in_days=$(expr ${review_in} \* 30) | ||
echo "review_in_days: ${review_in_days}" | ||
|
||
expiry=$(date -d "${last_reviewed_on}+${review_in_days}days" '+%Y-%m-%d') | ||
echo "expiry: ${expiry}" | ||
|
||
expiry_diff=$(datediff ${today} ${expiry}) | ||
echo "expiry_diff: ${expiry_diff}" | ||
|
||
page="$(echo "$chunk" | grep "source" | cut -d "/" -f1-)" | ||
|
||
if [[ ${expiry_diff} -gt 0 ]];then | ||
|
||
echo "****** fine ${page} *****" | ||
|
||
|
||
if [[ ${expiry_diff} -lt 21 ]];then | ||
echo "****** due ${page} *****" | ||
expiring_pages+="$(echo -e "\nExpiring in ${expiry_diff} days: ${page}")" | ||
fi | ||
|
||
else | ||
echo "****** review ${page} *****" | ||
expired_pages+="$(echo -e "\nExpired ${expiry_diff} days ago: ${page}")" | ||
fi | ||
|
||
|
||
echo "******************************************************************************************" | ||
echo "" | ||
echo "" | ||
done <<<"${report}" | ||
|
||
echo "" | ||
echo "" | ||
echo -e "${expiring_pages}" | ||
|
||
echo "" | ||
echo "" | ||
echo -e "${expired_pages}" | ||
echo "" | ||
echo "" |