Refactor Travis to use a series of short scripts so that the output is cleaner (and easier to manage / test locally)

This commit is contained in:
Tianon Gravi 2017-04-21 17:21:56 -07:00
parent 38736a40d6
commit 1f5076e2e8
6 changed files with 93 additions and 54 deletions

View File

@ -3,59 +3,10 @@ language: go
sudo: false sudo: false
install: install:
- export GOPATH_FIRST="${GOPATH%%:*}" - .travis/get-markdownfmt.sh
- >
git clone \
--depth 1 \
https://github.com/tianon/markdownfmt.git \
"$GOPATH_FIRST/src/github.com/shurcooL/markdownfmt"
- export BLACKFRIDAY_VERSION="$(awk '$1 == "ENV" && $2 == "BLACKFRIDAY_VERSION" { print $3; exit }' "$GOPATH_FIRST/src/github.com/shurcooL/markdownfmt/Dockerfile")"
- >
git clone \
--depth 1 \
-b "$BLACKFRIDAY_VERSION" \
https://github.com/russross/blackfriday.git \
"$GOPATH_FIRST/src/github.com/russross/blackfriday"
- go get -v github.com/shurcooL/markdownfmt
script: script:
- files="$(find -name '*.md' -print0 | xargs -0 markdownfmt -l)"; - .travis/check-markdownfmt.sh
if [ "$files" ]; then - .travis/check-short.sh
echo >&2 'Need markdownfmt:'; - .travis/check-required-files.sh
echo >&2 "$files"; - .travis/check-pr-no-readme.sh
echo >&2;
echo "$files" | xargs markdownfmt -d >&2;
exit 1;
fi
- failed='';
for short in */README-short.txt; do
chars="$(echo -n "$(cat "$short")" | wc -m)";
lines="$(cat "$short" | wc -l)";
if [ "$chars" -gt 100 -o "$lines" -gt 1 ]; then
failed+=" $short";
fi
done;
if [ "$failed" ]; then
echo >&2 "Too long (or too many lines):$failed";
exit 1;
fi
- failed='';
for repo in */; do
if [ ! -e "$repo/github-repo" ]; then
failed+=" $repo";
fi
done;
if [ "$failed" ]; then
echo >&2 "Missing github-repo for:$failed";
exit 1;
fi
- if [ "$TRAVIS_PULL_REQUEST" != 'false' ]; then
if [ "$(git diff --numstat "$TRAVIS_COMMIT_RANGE" -- '*/README.md')" ]; then
echo >&2 'Error:'' at least one repo README.md has changed';
echo >&2 'These files are autogenerated, so it is unnecessary to modify them';
echo >&2 'Please update content.md and docker-library-bot will take care of README.md';
echo >&2 'See:'' https://github.com/docker-library/docs/#image-namereadmemd';
echo >&2;
exit 1;
fi
fi

13
.travis/check-markdownfmt.sh Executable file
View File

@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -Eeuo pipefail
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")/.."
files="$(find -name '*.md' -print0 | xargs -0 markdownfmt -l)"
if [ "$files" ]; then
echo >&2 'Need markdownfmt:'
echo >&2 "$files"
echo >&2
echo "$files" | xargs markdownfmt -d >&2
exit 1
fi

15
.travis/check-pr-no-readme.sh Executable file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -Eeuo pipefail
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")/.."
if [ "$TRAVIS_PULL_REQUEST" != 'false' ]; then
if [ "$(git diff --numstat "$TRAVIS_COMMIT_RANGE" -- '*/README.md')" ]; then
echo >&2 'Error: at least one repo README.md has changed'
echo >&2 'These files are autogenerated, so it is unnecessary to modify them'
echo >&2 'Please update content.md and docker-library-bot will take care of README.md'
echo >&2 'See: https://github.com/docker-library/docs/#image-namereadmemd'
echo >&2
exit 1
fi
fi

25
.travis/check-required-files.sh Executable file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -Eeuo pipefail
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")/.."
exitCode=0
for requiredFile in \
content.md \
github-repo \
; do
failed=''
for repo in */; do
case "${repo%/}" in
scratch) continue ;;
esac
if [ ! -e "$repo/$requiredFile" ]; then
failed+=" $repo"
fi
done
if [ "$failed" ]; then
echo >&2 "Missing $requiredFile for:$failed"
exitCode=1
fi
done
exit "$exitCode"

18
.travis/check-short.sh Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -Eeuo pipefail
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")/.."
failed=''
for short in */README-short.txt; do
chars="$(echo -n "$(cat "$short")" | wc -m)"
lines="$(cat "$short" | wc -l)"
if [ "$chars" -gt 100 -o "$lines" -gt 1 ]; then
failed+=" $short"
fi
done
if [ "$failed" ]; then
echo >&2 "Too long (or too many lines):$failed"
exit 1
fi

17
.travis/get-markdownfmt.sh Executable file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -Eeuo pipefail
set -x
[ -n "$GOPATH" ]
export GOPATH_FIRST="${GOPATH%%:*}"
git clone \
--depth 1 \
https://github.com/tianon/markdownfmt.git \
"$GOPATH_FIRST/src/github.com/shurcooL/markdownfmt"
export BLACKFRIDAY_VERSION="$(awk '$1 == "ENV" && $2 == "BLACKFRIDAY_VERSION" { print $3; exit }' "$GOPATH_FIRST/src/github.com/shurcooL/markdownfmt/Dockerfile")"
git clone \
--depth 1 \
-b "$BLACKFRIDAY_VERSION" \
https://github.com/russross/blackfriday.git \
"$GOPATH_FIRST/src/github.com/russross/blackfriday"
go get -v github.com/shurcooL/markdownfmt