-
Notifications
You must be signed in to change notification settings - Fork 1
/
aggregate-repositories.sh
executable file
·63 lines (51 loc) · 1.78 KB
/
aggregate-repositories.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
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
#
# This script is run in the "Aggregate documentation" github workflow.
#
# The script takes one or more repositories as arguments, clones those
# repositories main branches, and copies files into this repo according to the
# mappings in `aggregate-mappings.json`.
#
set -e
echo "Aggregating files"
for repo in "$@"
do
# clone repo into a temp dir
tempdir="$(mktemp -d)"
git clone "https://github.com/$repo" "$tempdir/${repo#*/}"
# get file mappings from mappings file
repo_mappings=$(jq .["\"$repo\""] < aggregate-mappings.json)
for key in $(jq -r 'keys[]' <<< "$repo_mappings")
do
target=$(jq -r .["\"$key\""] <<< "$repo_mappings")
if [ -f "$tempdir/${repo#*/}/$key" ]
then
cp "$tempdir/${repo#*/}/$key" "$target"
git add "$target"
fi
done
# add special use case for sda.md links
sed -i -E 's#cmd\/([a-z0-9\-]+)\/#''#g' docs/services/sda.md
git add docs/services/sda.md
# update wordlist
spell_result=$(pyspelling | awk '!/^<context>|^Misspelled|^--|check failed|Spelling check passed/ && NF > 0')
if [ -n "$spell_result" ]
then
echo "$spell_result" >> docs/dictionary/wordlist.txt
sort -u docs/dictionary/wordlist.txt -o docs/dictionary/wordlist.txt
git add docs/dictionary/wordlist.txt
fi
# check if there are any changes
if ! git status | grep 'nothing to commit'
then
# commit files to repo
msg=$(date +"Update from $repo at %H:%M on %Y-%m-%d")
git config --global user.name 'Github aggregate action'
git config --global user.email '[email protected]'
git commit -m "$msg"
else
echo "No changes to commit"
fi
# clean up temp dir
rm -rf "$tempdir"
done