-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate_readme.sh
executable file
·50 lines (41 loc) · 1.42 KB
/
update_readme.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env bash
set -euo pipefail
FILE=${1:-README.md}
ACTION_FILE=${2}
# Smart action file name default
if [ -z "$ACTION_FILE" ]; then
if [ -f action.yaml ]; then
ACTION_FILE="action.yaml"
else
ACTION_FILE="action.yml"
fi
fi
render_inputs() {
{
echo
echo "| Name | Required | Default | Description |"
echo "| :---: | :------: | :-----: | ----------- |"
# shellcheck disable=SC2016
yq e '.inputs | .[] | ["`" + key + "`", .required, .default // "", .description | sub("\s+$", "") | sub("\n", "<br>")] | "| " + join(" | ") + " |"' "$ACTION_FILE"
echo
} >/tmp/TABLE.md
sed "/<!--(inputs-start)-->/,/<!--(inputs-end)-->/{//!d;}" "$FILE" >/tmp/FILE.md
awk '$0=="<!--(inputs-start)-->" {print;system("cat /tmp/TABLE.md");next}1' /tmp/FILE.md >"$FILE"
rm -f /tmp/TABLE.md /tmp/FILE.md
}
render_outputs() {
{
echo
echo "| Name | Description |"
echo "| :---: | ----------- |"
# shellcheck disable=SC2016
yq e '.outputs | .[] | ["`" + key + "`", .description | sub("\s+$", "") | sub("\n", "<br>")] | "| " + join(" | ") + " |"' "$ACTION_FILE"
echo
} >/tmp/TABLE.md
sed "/<!--(outputs-start)-->/,/<!--(outputs-end)-->/{//!d;}" "$FILE" >/tmp/FILE.md
awk '$0=="<!--(outputs-start)-->" {print;system("cat /tmp/TABLE.md");next}1' /tmp/FILE.md >"$FILE"
rm -f /tmp/TABLE.md /tmp/FILE.md
}
echo >&2 "Updating $FILE according to $ACTION_FILE"
render_inputs
render_outputs