Skip to content

Commit

Permalink
Merge pull request docker-library#887 from infosiftr/travis-refactor
Browse files Browse the repository at this point in the history
Refactor Travis to use a series of short scripts so that the output is cleaner (and easier to manage / test locally)
  • Loading branch information
tianon authored Apr 22, 2017
2 parents 7d03e21 + 1f5076e commit 3cce78c
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 54 deletions.
59 changes: 5 additions & 54 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,10 @@ language: go
sudo: false

install:
- 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
- .travis/get-markdownfmt.sh

script:
- 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
- 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
- .travis/check-markdownfmt.sh
- .travis/check-short.sh
- .travis/check-required-files.sh
- .travis/check-pr-no-readme.sh
13 changes: 13 additions & 0 deletions .travis/check-markdownfmt.sh
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions .travis/check-pr-no-readme.sh
Original file line number Diff line number Diff line change
@@ -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 changes: 25 additions & 0 deletions .travis/check-required-files.sh
Original file line number Diff line number Diff line change
@@ -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 changes: 18 additions & 0 deletions .travis/check-short.sh
Original file line number Diff line number Diff line change
@@ -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 changes: 17 additions & 0 deletions .travis/get-markdownfmt.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3cce78c

Please sign in to comment.