Browse Source

Скрипты для работы с GitLab

master
Maxim Likhachev 5 years ago
parent
commit
1f38d11af8
  1. 2
      README.md
  2. 57
      gitlab-ci-graph
  3. 36
      gitlab-ci-linter
  4. 2
      todolist

2
README.md

@ -76,6 +76,8 @@ will create the symbolic link for each script in the \<path> directory. @@ -76,6 +76,8 @@ will create the symbolic link for each script in the \<path> directory.
## Development tools
- [doctools2man](doctools2man) converts doctool to man pages.
- [gitlab-ci-graph](gitlab-ci-graph) draws a graph of the GitLab CI Pipeline file.
- [gitlab-ci-linter](gitlab-ci-linter) checks Gitlab CI Pipeline syntax via GitLab API.
- [how](how) shows dev cheat sheets using [cheat.sh](https://cheat.sh).
- [robodoc2html](robodoc2html) converts a documentation in the robodoc format into html.
- [todolist](todolist) shows all `TODO` notes in current git repository.

57
gitlab-ci-graph

@ -0,0 +1,57 @@ @@ -0,0 +1,57 @@
#!/bin/bash
#
# Show graph of GitLab CI Pipeline
#
# Requirements:
# - jq
# - python-yq (pip install yq)
# - graph-easy
GITLAB_CI=${1:-.gitlab-ci.yml}
if [ ! -f "$GITLAB_CI" ]; then
echo "USAGE: $(basename "$0") gitlab-ci.yml."
echo " Or run this script inside CI directory."
exit
fi
mapfile -t stages < <(yq -c -r '.stages[]' <.gitlab-ci.yml | expand | sed -e 's/^\s*-\s\+//') 2>&-
echo
{
printf "[BEGIN] { label: '*'; } ==> ";
printf "[%s] ==> " "${stages[@]^^}";
printf "[END] {label: '*'; }\n"
for stage in "${stages[@]}"; do
mapfile -t jobs < <(yq -r '. as $input
| keys[]
| [., $input[.]]
| select(.[1].stage?=='\""$stage"\"')
| .[0]' <"$GITLAB_CI" 2>&-)
for job in "${jobs[@]}"; do
echo "[${stage^^}] --> [${job}]"
when=$(yq -c -r '.['\""$job"\"']
| select(.when?)
| [.when]
| flatten' <"$GITLAB_CI" \
| sed -E 's/\["|"]//g; s/","/ AND /g')
yq -c -r '.['\""$job"\"']
| select(.needs?)
| [.needs]
| flatten' <"$GITLAB_CI" \
| sed "s/\"//g; s/,/],[/g; s/$/ -- $when --> { text-wrap: 10; } \[$job\]/"
done
done
} | graph-easy
echo

36
gitlab-ci-linter

@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
#!/bin/bash
#Создан: Чт 11 июн 2020 16:05:25
#Изменён: пт 12 июн 2020 19:28:15
#
# GitLab Pipeline Linter
#
# Requirements:
# - curl
# - jq
#
# GitLab Pipeline Linter API endpoint. Official gitlab.com by default
[ -z "$GITLAB_URL" ] && GITLAB_URL="https://gitlab.com/api/v4/ci/lint"
PIPELINE=${1:-.gitlab-ci.yml}
if [ ! -f "$PIPELINE" ]; then
echo "USAGE: $(basename "$0") gitlab-ci.yml."
echo " Or run this script inside CI directory."
exit
fi
CONTENT=$(printf '{ "content": %s }' "$(jq -aRs . <"$PIPELINE")")
RESPONSE=$(curl -sq --header "Content-Type: application/json" "$GITLAB_URL" --data "$CONTENT")
STATUS=$(jq -r .status <<<"$RESPONSE")
if [ "$STATUS" != "valid" ]; then
echo -n "ERROR: Pipeline $PIPELINE is invalid: "
jq -r '.errors[]' <<<"$RESPONSE"
exit 1
fi

2
todolist

@ -5,6 +5,6 @@ @@ -5,6 +5,6 @@
[ -n "$1" ] && cd "$1"
if git rev-parse --show-toplevel &>/dev/null; then
grep -n -R "^[[:space:]]*[#/\"-]*[[:space:]]*TODO:"
grep -n -R "^[[:space:]]*[#/\"-]*[[:space:]]*TODO:" .
fi

Loading…
Cancel
Save