From 5e44f19db25bb1054378961cf6bf3622b6448939 Mon Sep 17 00:00:00 2001 From: mark Date: Mon, 5 Oct 2020 13:23:14 -0500 Subject: [PATCH 1/7] linkcheck only for changed files except in cron jobs --- .travis.yml | 2 +- book.toml | 1 + ci/linkcheck.sh | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100755 ci/linkcheck.sh diff --git a/.travis.yml b/.travis.yml index fba5ab87e..3e4a3dc0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ before_install: install: - source ~/.cargo/env || true - cargo install mdbook --version '^0.4.3' -- cargo install mdbook-linkcheck --version '^0.7.0' +- cargo install mdbook-linkcheck --git https://github.com/Michael-F-Bryan/mdbook-linkcheck script: - git checkout -b ci - git rebase origin/master diff --git a/book.toml b/book.toml index 10bc2edd4..af909446a 100644 --- a/book.toml +++ b/book.toml @@ -14,6 +14,7 @@ enable = true level = 0 [output.linkcheck] +command = "../../ci/linkcheck.sh" follow-web-links = true exclude = [ "crates\\.io", "gcc\\.godbolt\\.org", "youtube\\.com", "youtu\\.be", "dl\\.acm\\.org", "cs\\.bgu\\.ac\\.il", "www\\.amazon\\.com", "www\\.rustaceans\\.org" ] cache-timeout = 86400 diff --git a/ci/linkcheck.sh b/ci/linkcheck.sh new file mode 100755 index 000000000..85573314c --- /dev/null +++ b/ci/linkcheck.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +if [ "$TRAVIS_EVENT_TYPE" = "cron" ] ; then # running in cron job + FLAGS="" + + echo "Doing full link check." +elif [ "$CI" = "true" ] ; then # running in PR CI build + CHANGED_FILES=$(git diff --name-only $TRAVIS_COMMIT_RANGE | tr '\n' ' ') + FLAGS="-f $CHANGED_FILES" + + echo "Checking files changed in $TRAVIS_COMMIT_RANGE: $CHANGED_FILES" +else # running locally + COMMIT_RANGE=master... + CHANGED_FILES=$(git diff --name-only $COMMIT_RANGE | tr '\n' ' ') + FLAGS="-f $CHANGED_FILES" + + echo "Checking files changed in $COMMIT_RANGE: $CHANGED_FILES" +fi + +exec mdbook-linkcheck $FLAGS -- $TRAVIS_BUILD_DIR From 2edc2c1fe916cbdb573abdf899fdc821a7e2ebff Mon Sep 17 00:00:00 2001 From: mark Date: Wed, 7 Oct 2020 03:10:35 -0500 Subject: [PATCH 2/7] pin mdbook-linkcheck version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3e4a3dc0d..395334e5c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ before_install: install: - source ~/.cargo/env || true - cargo install mdbook --version '^0.4.3' -- cargo install mdbook-linkcheck --git https://github.com/Michael-F-Bryan/mdbook-linkcheck +- cargo install mdbook-linkcheck --git https://github.com/Michael-F-Bryan/mdbook-linkcheck --rev 14441d77646d58cea8ffc32fde9ea33b2bedb1a2 script: - git checkout -b ci - git rebase origin/master From daed1a228a60d0835f35652283bc2788e16b13e2 Mon Sep 17 00:00:00 2001 From: Who? Me?! Date: Wed, 7 Oct 2020 23:01:20 -0500 Subject: [PATCH 3/7] Add comment referring to travis docs Co-authored-by: Joshua Nelson --- ci/linkcheck.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/linkcheck.sh b/ci/linkcheck.sh index 85573314c..7149ab3a7 100755 --- a/ci/linkcheck.sh +++ b/ci/linkcheck.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash +# https://docs.travis-ci.com/user/environment-variables/#default-environment-variables if [ "$TRAVIS_EVENT_TYPE" = "cron" ] ; then # running in cron job FLAGS="" From 6dd9d5eef143cbaf5d446359f730168cf9ab4377 Mon Sep 17 00:00:00 2001 From: Who? Me?! Date: Thu, 8 Oct 2020 15:15:58 -0500 Subject: [PATCH 4/7] More debuggable bash settings Co-authored-by: Joshua Nelson --- ci/linkcheck.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ci/linkcheck.sh b/ci/linkcheck.sh index 7149ab3a7..a1cd424fb 100755 --- a/ci/linkcheck.sh +++ b/ci/linkcheck.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash +set -ev +set -o pipefail + # https://docs.travis-ci.com/user/environment-variables/#default-environment-variables if [ "$TRAVIS_EVENT_TYPE" = "cron" ] ; then # running in cron job FLAGS="" From 4fd429aa1385711a3fc3aa5558f0ee74a5caad07 Mon Sep 17 00:00:00 2001 From: mark Date: Thu, 8 Oct 2020 15:54:29 -0500 Subject: [PATCH 5/7] add assert --- ci/linkcheck.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ci/linkcheck.sh b/ci/linkcheck.sh index a1cd424fb..db6b35a5b 100755 --- a/ci/linkcheck.sh +++ b/ci/linkcheck.sh @@ -9,6 +9,11 @@ if [ "$TRAVIS_EVENT_TYPE" = "cron" ] ; then # running in cron job echo "Doing full link check." elif [ "$CI" = "true" ] ; then # running in PR CI build + if [ -n "$TRAVIS_COMMIT_RANGE" ]; then + echo "error: unexpected state: COMMIT_RANGE must be non-empty in CI" + exit 1 + fi + CHANGED_FILES=$(git diff --name-only $TRAVIS_COMMIT_RANGE | tr '\n' ' ') FLAGS="-f $CHANGED_FILES" From 4e840a0af897e1f7501fd759b6a719a6530eec07 Mon Sep 17 00:00:00 2001 From: Who? Me?! Date: Thu, 8 Oct 2020 16:08:25 -0500 Subject: [PATCH 6/7] Lol logic is hard Co-authored-by: Joshua Nelson --- ci/linkcheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/linkcheck.sh b/ci/linkcheck.sh index db6b35a5b..6979e9867 100755 --- a/ci/linkcheck.sh +++ b/ci/linkcheck.sh @@ -9,7 +9,7 @@ if [ "$TRAVIS_EVENT_TYPE" = "cron" ] ; then # running in cron job echo "Doing full link check." elif [ "$CI" = "true" ] ; then # running in PR CI build - if [ -n "$TRAVIS_COMMIT_RANGE" ]; then + if [ -z "$TRAVIS_COMMIT_RANGE" ]; then echo "error: unexpected state: COMMIT_RANGE must be non-empty in CI" exit 1 fi From 436ffc37aaab2a3dc44687e606c7bd98efcb5992 Mon Sep 17 00:00:00 2001 From: Who? Me?! Date: Thu, 8 Oct 2020 16:08:42 -0500 Subject: [PATCH 7/7] Better error message Co-authored-by: Camelid --- ci/linkcheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/linkcheck.sh b/ci/linkcheck.sh index 6979e9867..d827b8476 100755 --- a/ci/linkcheck.sh +++ b/ci/linkcheck.sh @@ -10,7 +10,7 @@ if [ "$TRAVIS_EVENT_TYPE" = "cron" ] ; then # running in cron job echo "Doing full link check." elif [ "$CI" = "true" ] ; then # running in PR CI build if [ -z "$TRAVIS_COMMIT_RANGE" ]; then - echo "error: unexpected state: COMMIT_RANGE must be non-empty in CI" + echo "error: unexpected state: TRAVIS_COMMIT_RANGE must be non-empty in CI" exit 1 fi