-
Notifications
You must be signed in to change notification settings - Fork 0
/
populate_projects.sh
executable file
·48 lines (42 loc) · 1.63 KB
/
populate_projects.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
#!/usr/bin/env bash
set -e -u -o pipefail
cd projects
github_auth=()
if [[ -n "${GITHUB_TOKEN:-}" ]]; then
github_auth=(--header "Authorization: Bearer $GITHUB_TOKEN")
fi
if [[ $# -eq 0 ]]; then
projects=(*/)
else
projects="$@"
fi
for d in "${projects[@]}"; do
d="${d%/}"
cd "$d"
printf "%s -> " "$d" >&2
if [[ -f 'project.txt' ]]; then
[[ "$(head -1 'project.txt')" =~ ^https://github.com/([^/]+/[^/]+)/blob/([^/]+)/(.+)$ ]]
repo="${BASH_REMATCH[1]}"
branch="${BASH_REMATCH[2]}"
mkdocs_yml="${BASH_REMATCH[3]}"
else
repo="${d//--//}"
branch=$(curl -sfL "${github_auth[@]}" "https://api.github.com/repos/$repo" | jq -r '.default_branch')
mkdocs_yml='mkdocs.yml'
fi
[[ "$(curl -sfL "${github_auth[@]}" "https://api.github.com/repos/$repo/commits?per_page=1&sha=$branch" | jq -r '.[0].commit.url')" =~ ^https://api.github.com/repos/([^/]+/[^/]+)/git/commits/([0-9a-f]+)$ ]]
repo="${BASH_REMATCH[1]}"
commit="${BASH_REMATCH[2]}"
echo "https://github.com/$repo/blob/$branch/$mkdocs_yml" | tee /dev/stderr >project.txt
echo "https://github.com/$repo/raw/$commit/$mkdocs_yml" >>project.txt
tail -1 project.txt | xargs curl -sfL | (mkdocs-get-deps -f - || true) | grep . >requirements.in.new
(grep ' ' requirements.in 2>/dev/null || true) >>requirements.in.new
mv requirements.in.new requirements.in
cd ..
# Rename the directory in case the repository has been renamed
dir_name="${repo//\//--}"
if [[ "$d" != "$dir_name" ]]; then
mv "$d" "$dir_name"
fi
done
printf "%s/requirements.in\n" "${projects[@]}" | xargs -t -n1 -P4 pip-compile -q --allow-unsafe --strip-extras --no-annotate --no-header -U