4 changed files with 96 additions and 1 deletions
@ -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 |
||||||
|
|
@ -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 |
||||||
|
|
Loading…
Reference in new issue