Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
**Superseeded by [log4brains](https://github.com/thomvaill/log4brains)**

ADR Tools
=========

Expand Down
2 changes: 1 addition & 1 deletion src/_adr_add_link
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ awk -v link_type="$link_type" -v target="$(basename $target)" -v target_title="$
}
/^##/ {
if (in_status_section) {
print link_type " [" target_title "](" target ")"
print link_type " ["target_title"](" target ")"
print ""
}
in_status_section=0
Expand Down
32 changes: 32 additions & 0 deletions src/_adr_add_link_madr
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
set -e
eval "$($(dirname $0)/adr-config)"
date=${ADR_DATE:-$(date +%Y-%m-%d)}
source=$("$adr_bin_dir/_adr_file" "${1:?SOURCE}")
link_type="${2:?LINK TYPE}"
target=$("$adr_bin_dir/_adr_file" "${3:?TARGET}")

target_title="$("$adr_bin_dir/_adr_title" "$target")"
updated_status="$link_type [$target_title]($(basename $target))"

if [ "$link_type" != "Supercedes" ]
then
awk -v n=3 -v s="* Status: $updated_status" '(NR==n) { print s }{ print } ' "$source" > "$source.tmp" && mv "$source.tmp" "$source"
fi

if [ "$link_type" == "Superceded by" ]
then
sed -e "s/\* Date:.*/\* Date: $date/" "$source" > "$source.tmp" && mv "$source.tmp" "$source"
fi

if grep -q "## Links" "$source"; then
cat <<EOT >> "$source"
* $updated_status
EOT
else
cat <<EOT >> "$source"
## Links

* $updated_status
EOT
fi
5 changes: 3 additions & 2 deletions src/_adr_generate_graph
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ eval "$($(dirname $0)/adr-config)"

link_prefix=
link_extension=.html

template_type=$("$adr_bin_dir/_adr_type")
while getopts e:p: arg
do
case "$arg" in
Expand All @@ -51,7 +51,7 @@ shift $((OPTIND-1))


function index() {
basename "$1" | sed -e 's/-.*//' | sed -e 's/^0*//'
basename "$1" | sed -e 's/-.*//' | sed -e 's/^0//' | sed -e 's/^0//' | sed -e 's/^0//'
}

echo "digraph {"
Expand All @@ -68,6 +68,7 @@ do
then
echo " _$(($n - 1)) -> _$n [style=\"dotted\", weight=1];"
fi

done
echo " }"

Expand Down
10 changes: 9 additions & 1 deletion src/_adr_links
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@
set -e
eval "$($(dirname $0)/adr-config)"

"$adr_bin_dir/_adr_status" "$1" | sed -n -E 's/^(.+) \[.*\]\(0*([1-9][0-9]*).*\)/\2=\1/p'
template_type=$("$adr_bin_dir/_adr_type")
case $template_type in
"")
"$adr_bin_dir/_adr_status" "$1" | sed -n -E 's/^(.+) \[.*\]\(0*([1-9][0-9]*).*\)/\2=\1/p'
;;
madr)
sed 's/^\* //' "$("$adr_bin_dir/_adr_file" "$1")" | sed -n '/Status:/!p' | sed -n -E 's/^([a-zA-Z ]+) \[.*\]\(0*([1-9][0-9]*).*\)/\2=\1/p'
;;
esac
8 changes: 8 additions & 0 deletions src/_adr_remove_status_madr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -e
eval "$($(dirname $0)/adr-config)"

current_status=${1:?FROM}
file=$("$adr_bin_dir/_adr_file" "${2:?FILE}")
pattern="* Status: $current_status"
sed -n "/\* Status: $current_status/!p" "$file" > temp && mv temp "$file"
1 change: 1 addition & 0 deletions src/_adr_title
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
set -e
eval "$($(dirname $0)/adr-config)"

#sed -n '/---/,/---/p' $("$adr_bin_dir/_adr_file" "$1") | sed -n 's/^title: "\(.*\)"$/\1/p'
head -1 $("$adr_bin_dir/_adr_file" "$1") | cut -c 3-
8 changes: 8 additions & 0 deletions src/_adr_type
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -e
eval "$($(dirname $0)/adr-config)"

if [ -f .adr-type ]
then
cat .adr-type
fi
28 changes: 25 additions & 3 deletions src/adr-init
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e
eval "$($(dirname $0)/adr-config)"

## usage: adr init [DIRECTORY]
## usage: adr init [DIRECTORY] [TYPE]
##
## Initialises the directory of architecture decision records:
##
Expand All @@ -11,12 +11,34 @@ eval "$($(dirname $0)/adr-config)"
## record architectural decisions with ADRs.
##
## If the DIRECTORY is not given, the ADRs are stored in the directory `doc/adr`.
##
## To initialize with a non default template a directory has to be specified.
## E.g. To use the MADR template and save documentation in the docs directory:
## adr init docs madr
##
## Currently supported templates:
## * madr


if [ ! -z $1 ]
then
mkdir -p "$1"
echo "$1" > .adr-dir
fi

VISUAL=true ADR_TEMPLATE="$adr_template_dir/init.md" \
"$adr_bin_dir/adr-new" record-architecture-decisions
if [ ! -z $2 ]
then
template_type=$2
if [ -f "$adr_template_dir/template-$template_type.md" ] && [ -f "$adr_template_dir/init-$template_type.md" ]
then
echo "$2" > .adr-type
else
echo "$2 is not a supported type"
fi
VISUAL=true ADR_TEMPLATE="$adr_template_dir/init-$template_type.md" \
"$adr_bin_dir/adr-new" record-architecture-decisions
else
VISUAL=true ADR_TEMPLATE="$adr_template_dir/init.md" \
"$adr_bin_dir/adr-new" record-architecture-decisions
fi

12 changes: 10 additions & 2 deletions src/adr-link
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ source="${1:?SOURCE}"
forward_link="${2:?LINK}"
target="${3:?TARGET}"
reverse_link="${4:?REVERSE-LINK}"
type=$("$adr_bin_dir/_adr_type")

"$adr_bin_dir/_adr_add_link" "$source" "$forward_link" "$target"
"$adr_bin_dir/_adr_add_link" "$target" "$reverse_link" "$source"
if [ -z $type ]
then
type_suffix=""
else
type_suffix="_$type"
fi

"$adr_bin_dir/_adr_add_link$type_suffix" "$source" "$forward_link" "$target"
"$adr_bin_dir/_adr_add_link$type_suffix" "$target" "$reverse_link" "$source"
79 changes: 63 additions & 16 deletions src/adr-new
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,25 @@ done
shift $((OPTIND-1))

dstdir=$("$adr_bin_dir/_adr_dir")
template_type=$("$adr_bin_dir/_adr_type")
template="$ADR_TEMPLATE"
if [ -z $template ]
then
template="$dstdir/templates/template.md"
if [ ! -f "$template" ]
if [ -d "$dstdir/templates" ]
then
template="$adr_template_dir/template.md"
template="$dstdir/templates/template.md"
else
template="$dstdir/template.md"
fi
if [ ! -f "$template" ]
then
if [ -z $template_type ]
then
template="$adr_template_dir/template.md"
else
template="$adr_template_dir/template-$template_type.md"
fi
fi
fi

title="$@"
Expand All @@ -91,42 +102,78 @@ then
exit 1
fi

#newnum=0

if [ -d $dstdir ]
then
maxid=$(ls $dstdir | grep -Eo '^[0-9]+' | sed -e 's/^0*//' | sort -rn | head -1)
filecount=$(ls $dstdir | grep -Eo '^[0-9]+' | wc -l)
maxid=$(ls $dstdir | grep -Eo '^[0-9]+' | sed -e 's/^0//' | sed -e 's/^0//'| sed -e 's/^0//' | sort -rn | head -1)
newnum=$(($maxid + 1))
if [ -z $maxid ]
then
newnum_madr=1
else
newnum_madr=$(($maxid + 1))
fi
else
newnum=1
newnum_madr=1
fi

newid=$(printf "%04d" $newnum)
if [ -z $template_type ]
then
newid=$(printf "%04d" $newnum)
else
newid=$(printf "%04d" $newnum_madr)
fi
slug=$(echo -n $title | tr -Ccs [:alnum:] - | tr [:upper:] [:lower:] | sed -e 's/[^[:alnum:]]*$//' -e 's/^[^[:alnum:]]*//')
dstfile=$dstdir/$newid-$slug.md
date=${ADR_DATE:-$(date +%Y-%m-%d)}

mkdir -p $dstdir
cat $template | sed \

tempfile=$dstdir/.tempfile

case $template_type in
"")
cat $template | sed \
-e "s|NUMBER|$newnum|" \
-e "s|TITLE|$title|" \
-e "s|DATE|$date|" \
-e "s|STATUS|Accepted|" \
> $dstfile
;;
madr)
cat $template | sed \
-e "s/\[short title of solved problem and solution\]/$title/" \
-e "s/\* Status: \[accepted | superseeded by \[ADR-0005\](0005-example.md) | deprecated | …\] <!-- optional -->/\* Status: Accepted/" \
-e "s/\* Date: \[YYYY-MM-DD when the decision was last updated\] <!-- optional -->/\* Date: $date/" \
> $dstfile
;;
esac

type=$("$adr_bin_dir/_adr_type")
if [ -z $type ]
then
type_suffix=""
else
type_suffix="_$type"
fi

for target in "${superceded[@]}"
do
"$adr_bin_dir/_adr_add_link" "$target" "Superceded by" "$dstfile"
"$adr_bin_dir/_adr_remove_status" "Accepted" "$target"
"$adr_bin_dir/_adr_add_link" "$dstfile" "Supercedes" "$target"
"$adr_bin_dir/_adr_add_link$type_suffix" "$target" "Superceded by" "$dstfile"
"$adr_bin_dir/_adr_remove_status$type_suffix" "Accepted" "$target"
"$adr_bin_dir/_adr_add_link$type_suffix" "$dstfile" "Supercedes" "$target"
done

for l in "${links[@]}"
do
target="$(echo $l | cut -d : -f 1)"
forward_link="$(echo $l | cut -d : -f 2)"
reverse_link="$(echo $l | cut -d : -f 3)"
"$adr_bin_dir/_adr_add_link" "$dstfile" "$forward_link" "$target"
"$adr_bin_dir/_adr_add_link" "$target" "$reverse_link" "$dstfile"
target="$(echo $l | cut -d : -f 1)"
forward_link="$(echo $l | cut -d : -f 2)"
reverse_link="$(echo $l | cut -d : -f 3)"

"$adr_bin_dir/_adr_add_link$type_suffix" "$dstfile" "$forward_link" "$target"
"$adr_bin_dir/_adr_add_link$type_suffix" "$target" "$reverse_link" "$dstfile"
done

${VISUAL:-${EDITOR:-true}} $dstfile
Expand Down
25 changes: 25 additions & 0 deletions src/init-madr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use Markdown Architectural Decision Records

## Context and Problem Statement

We want to record architectural decisions made in this project.
Which format and structure should these records follow?

## Considered Options

* [MADR](https://adr.github.io/madr/) 2.1.0 - The Markdown Architectural Decision Records
* [Michael Nygard's template](http://thinkrelevance.com/blog/2011/11/15/documenting-architecture-decisions) - The first incarnation of the term "ADR"
* [Sustainable Architectural Decisions](https://www.infoq.com/articles/sustainable-architectural-design-decisions) - The Y-Statements
* Other templates listed at <https://github.com/joelparkerhenderson/architecture_decision_record>
* Formless - No conventions for file format and structure

## Decision Outcome

Chosen option: "MADR 2.1.0", because
* Implicit assumptions should be made explicit.
Design documentation is important to enable people understanding the decisions later on.
See also [A rational design process: How and why to fake it](https://doi.org/10.1109/TSE.1986.6312940).
* The MADR format is lean and fits our development style.
* The MADR structure is comprehensible and facilitates usage & maintenance.
* The MADR project is vivid.
* Version 2.1.0 is the latest one available when starting to document ADRs.
72 changes: 72 additions & 0 deletions src/template-madr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# [short title of solved problem and solution]

* Status: [accepted | superseeded by [ADR-0005](0005-example.md) | deprecated | …] <!-- optional -->
* Deciders: [list everyone involved in the decision] <!-- optional -->
* Date: [YYYY-MM-DD when the decision was last updated] <!-- optional -->

Technical Story: [description | ticket/issue URL] <!-- optional -->

## Context and Problem Statement

[Describe the context and problem statement, e.g., in free form using two to three sentences. You may want to articulate the problem in form of a question.]

## Decision Drivers <!-- optional -->

* [driver 1, e.g., a force, facing concern, …]
* [driver 2, e.g., a force, facing concern, …]
* … <!-- numbers of drivers can vary -->

## Considered Options

* [option 1]
* [option 2]
* [option 3]
* … <!-- numbers of options can vary -->

## Decision Outcome

Chosen option: "[option 1]", because [justification. e.g., only option, which meets k.o. criterion decision driver | which resolves force force | … | comes out best (see below)].

### Positive Consequences <!-- optional -->

* [e.g., improvement of quality attribute satisfaction, follow-up decisions required, …]
* …

### Negative consequences <!-- optional -->

* [e.g., compromising quality attribute, follow-up decisions required, …]
* …

## Pros and Cons of the Options <!-- optional -->

### [option 1]

[example | description | pointer to more information | …] <!-- optional -->

* Good, because [argument a]
* Good, because [argument b]
* Bad, because [argument c]
* … <!-- numbers of pros and cons can vary -->

### [option 2]

[example | description | pointer to more information | …] <!-- optional -->

* Good, because [argument a]
* Good, because [argument b]
* Bad, because [argument c]
* … <!-- numbers of pros and cons can vary -->

### [option 3]

[example | description | pointer to more information | …] <!-- optional -->

* Good, because [argument a]
* Good, because [argument b]
* Bad, because [argument c]
* … <!-- numbers of pros and cons can vary -->

## Links <!-- optional -->

* [Link type] [Link to ADR] <!-- example: Refined by [ADR-0005](0005-example.md) -->
* … <!-- numbers of links can vary -->
Loading