From 374c29be10e404e4569d6bdb77e2aa39013fc4a6 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Tue, 2 Mar 2021 18:20:01 +0900 Subject: [PATCH 1/3] Switch from Travis to GHA --- .env | 4 ++ .github/workflows/ci.yml | 86 ++++++++++++++++++++++++++++++++++++++++ .travis.yml | 39 ------------------ ci/linkcheck.sh | 12 ++---- 4 files changed, 94 insertions(+), 47 deletions(-) create mode 100644 .env create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.env b/.env new file mode 100644 index 000000000..6923d3796 --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +MDBOOK_VERSION=0.4.7 +MDBOOK_LINKCHECK_VERSION=0.7.2 +MDBOOK_TOC_VERSION=0.6.1 +DEPLOY_DIR=book/html diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..2edc33e16 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,86 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + schedule: + # Run at 18:00 UTC every day + - cron: '0 18 * * *' + +jobs: + ci: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + # Set 0 to rebase later. + fetch-depth: 0 + + - name: Read .env + run: | + . ./.env + echo "MDBOOK_VERSION=${MDBOOK_VERSION}" >> $GITHUB_ENV + echo "MDBOOK_LINKCHECK_VERSION=${MDBOOK_LINKCHECK_VERSION}" >> $GITHUB_ENV + echo "MDBOOK_TOC_VERSION=${MDBOOK_TOC_VERSION}" >> $GITHUB_ENV + echo "DEPLOY_DIR=${DEPLOY_DIR}" >> $GITHUB_ENV + + - name: Cache binaries + id: mdbook-cache + uses: actions/cache@v2 + with: + path: | + ~/.cargo/bin + key: ${{ runner.os }}-${{ env.MDBOOK_VERSION }}--${{ env.MDBOOK_LINKCHECK_VERSION }}--${{ env.MDBOOK_TOC_VERSION }} + + - name: Cache linkcheck + uses: actions/cache@v2 + with: + path: | + ~/book/linkcheck + key: ${{ runner.os }}-${{ hashFiles('./book/linkcheck') }} + + - name: Check line lengths + if: github.event_name != 'schedule' + run: | + shopt -s globstar + MAX_LINE_LENGTH=100 bash ci/check_line_lengths.sh src/**/*.md + + - name: Install latest nightly Rust toolchain + if: steps.mdbook-cache.outputs.cache-hit != 'true' + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + override: true + + - name: Install Dependencies + if: steps.mdbook-cache.outputs.cache-hit != 'true' + run: | + cargo install mdbook --version ${{ env.MDBOOK_VERSION }} + cargo install mdbook-linkcheck --version ${{ env.MDBOOK_LINKCHECK_VERSION }} + cargo install mdbook-toc --version ${{ env.MDBOOK_TOC_VERSION }} + + - name: Check build + if: github.event_name != 'schedule' + run: | + git switch -c ci + git fetch origin master + git rebase origin/master + git log --oneline | head -n 10 + mdbook build + + - name: Deploy to gh-pages + if: github.event_name == 'schedule' && github.repository == 'rust-lang/rustc-dev-guide' + run: | + mdbook build + touch "${{ env.DEPLOY_DIR }}/.nojekyll" + cp CNAME "${{ env.DEPLOY_DIR }}" + cd "${{ env.DEPLOY_DIR }}" + rm -rf .git + git init + git config user.name "Deploy from CI" + git config user.email "" + git add . + git commit -m "Deploy ${GITHUB_SHA} to gh-pages" + git push --quiet -f "https://x-token:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}" HEAD:gh-pages diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1d6747258..000000000 --- a/.travis.yml +++ /dev/null @@ -1,39 +0,0 @@ -language: rust -dist: bionic -rust: -- nightly -cache: -- cargo -- directories: - - book/linkcheck/ -before_install: -- shopt -s globstar -- MAX_LINE_LENGTH=100 bash ci/check_line_lengths.sh src/**/*.md -install: -- source ~/.cargo/env || true -- cargo install mdbook --version '^0.4.5' -- cargo install mdbook-linkcheck --version '^0.7.2' -- cargo install mdbook-toc --version '^0.6.1' -script: -- git checkout -b ci -- git rebase origin/master -- git log --oneline | head -n 10 -- mdbook build -notifications: - email: false -env: - global: - secure: YQX/AWq5KsvAFYqcCK6c1DmOZX9EMrecBM5qnc4uE2HvEBS+x0l8xatI2Nv8U9eiasZYfsqmHn0ANvxu6e4oqL15m4cVsdliCzdkrPsDapxTnwwJvMQg+yHZiEd5BPlaDQt/wYvP8QBXgQsXoAJKrfAS+BFsowBFHt/LOFOunbAQrtQZqwqrnI6+xh+2TRMckws/VcTLRqwl3pyEyfacJhbbv1V3gJh7Y17hELsgsP7+7cMXT0bK6dtf7a9vne9Hsm5fw7VeMKBn1/dJ82fyEK6HHjkjdw1/OoY35YVyNZ/9ZxP2u1ClEXzCRJQ2CvKr8Tuoh/AuoL0pwrfhOTaOuWU0QZT4QBqjTimsgBLqiJicMiSndgsXinLWvlDqrMS1XfleqCKqAQy9AJTCR1LnwR90/HRxfE5YDAL/mbc0Su4jj+l5Zv3UE8vUqFE34E/jzip17JkDT5aMkl4bgW65lqJE7SLWl7gXT7eYbPEtQZoucR1hkSsBu/4YTvcxSlD98spWZ68mWwYyjLJSQDES+GefUnHJ/RbBVl9pW+sL7jXJ+kZ/NBCtCIgrkGchudEMDEvS6rcOzwCejxqL1of0jYHGopkBXSVHOPneWIdNeKXwBZA9hp0yKh0sWwrKHrA3wYhS/kF9uO19l/RnSTXAfApYR/yJUbYliuMJYCgNeKE= -deploy: - provider: pages - skip-cleanup: true - github-token: $GITHUB_TOKEN - local-dir: book/html - fqdn: rustc-dev-guide.rust-lang.org - on: - branch: master - -# Only build master branch on push -branches: - only: - - master diff --git a/ci/linkcheck.sh b/ci/linkcheck.sh index d329a7164..86ee000cb 100755 --- a/ci/linkcheck.sh +++ b/ci/linkcheck.sh @@ -3,22 +3,18 @@ set -e set -o pipefail -# https://docs.travis-ci.com/user/environment-variables/#default-environment-variables -if [ "$TRAVIS_EVENT_TYPE" = "cron" ] ; then # running in cron job +# https://docs.github.com/en/actions/reference/environment-variables +if [ "$GITHUB_EVENT_NAME" = "schedule" ] ; then # running in scheduled job FLAGS="" echo "Doing full link check." set -x elif [ "$CI" = "true" ] ; then # running in PR CI build - if [ -z "$TRAVIS_COMMIT_RANGE" ]; then - echo "error: unexpected state: TRAVIS_COMMIT_RANGE must be non-empty in CI" - exit 1 - fi - CHANGED_FILES=$(git diff --name-only $TRAVIS_COMMIT_RANGE | tr '\n' ' ') + CHANGED_FILES=$(git diff --name-only origin/master... | tr '\n' ' ') FLAGS="--no-cache -f $CHANGED_FILES" - echo "Checking files changed in $TRAVIS_COMMIT_RANGE: $CHANGED_FILES" + echo "Checking files changed in origin/master...: $CHANGED_FILES" set -x else # running locally COMMIT_RANGE=master... From 4c70da4512e1019a4deb0de9160791965b73a6a8 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 3 Mar 2021 02:30:29 +0900 Subject: [PATCH 2/3] Address review comments --- .env | 4 ---- .github/workflows/ci.yml | 20 +++++++++----------- ci/linkcheck.sh | 8 ++++++-- 3 files changed, 15 insertions(+), 17 deletions(-) delete mode 100644 .env diff --git a/.env b/.env deleted file mode 100644 index 6923d3796..000000000 --- a/.env +++ /dev/null @@ -1,4 +0,0 @@ -MDBOOK_VERSION=0.4.7 -MDBOOK_LINKCHECK_VERSION=0.7.2 -MDBOOK_TOC_VERSION=0.6.1 -DEPLOY_DIR=book/html diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2edc33e16..b7a33dd4e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,20 +12,18 @@ on: jobs: ci: runs-on: ubuntu-latest + env: + MDBOOK_VERSION: 0.4.7 + MDBOOK_LINKCHECK_VERSION: 0.7.2 + MDBOOK_TOC_VERSION: 0.6.1 + DEPLOY_DIR: book/html + BASE_SHA: ${{ github.event.pull_request.base.sha }} steps: - uses: actions/checkout@v2 with: # Set 0 to rebase later. fetch-depth: 0 - - name: Read .env - run: | - . ./.env - echo "MDBOOK_VERSION=${MDBOOK_VERSION}" >> $GITHUB_ENV - echo "MDBOOK_LINKCHECK_VERSION=${MDBOOK_LINKCHECK_VERSION}" >> $GITHUB_ENV - echo "MDBOOK_TOC_VERSION=${MDBOOK_TOC_VERSION}" >> $GITHUB_ENV - echo "DEPLOY_DIR=${DEPLOY_DIR}" >> $GITHUB_ENV - - name: Cache binaries id: mdbook-cache uses: actions/cache@v2 @@ -42,7 +40,7 @@ jobs: key: ${{ runner.os }}-${{ hashFiles('./book/linkcheck') }} - name: Check line lengths - if: github.event_name != 'schedule' + if: github.event_name != 'push' run: | shopt -s globstar MAX_LINE_LENGTH=100 bash ci/check_line_lengths.sh src/**/*.md @@ -62,7 +60,7 @@ jobs: cargo install mdbook-toc --version ${{ env.MDBOOK_TOC_VERSION }} - name: Check build - if: github.event_name != 'schedule' + if: github.event_name != 'push' run: | git switch -c ci git fetch origin master @@ -71,7 +69,7 @@ jobs: mdbook build - name: Deploy to gh-pages - if: github.event_name == 'schedule' && github.repository == 'rust-lang/rustc-dev-guide' + if: github.event_name == 'push' && github.repository == 'rust-lang/rustc-dev-guide' run: | mdbook build touch "${{ env.DEPLOY_DIR }}/.nojekyll" diff --git a/ci/linkcheck.sh b/ci/linkcheck.sh index 86ee000cb..0dcd67ec8 100755 --- a/ci/linkcheck.sh +++ b/ci/linkcheck.sh @@ -10,11 +10,15 @@ if [ "$GITHUB_EVENT_NAME" = "schedule" ] ; then # running in scheduled job echo "Doing full link check." set -x elif [ "$CI" = "true" ] ; then # running in PR CI build + if [ -z "$BASE_SHA" ]; then + echo "error: unexpected state: BASE_SHA must be non-empty in CI" + exit 1 + fi - CHANGED_FILES=$(git diff --name-only origin/master... | tr '\n' ' ') + CHANGED_FILES=$(git diff --name-only $BASE_SHA... | tr '\n' ' ') FLAGS="--no-cache -f $CHANGED_FILES" - echo "Checking files changed in origin/master...: $CHANGED_FILES" + echo "Checking files changed from $BASE_SHA: $CHANGED_FILES" set -x else # running locally COMMIT_RANGE=master... From 1a56a3b501f98e5ddae0b3ccbafc0debe0c4d5e5 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 3 Mar 2021 05:52:19 +0900 Subject: [PATCH 3/3] Address the review comments, part 2 --- .github/workflows/ci.yml | 11 ++--------- ci/linkcheck.sh | 2 +- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b7a33dd4e..c3307bb74 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v2 with: - # Set 0 to rebase later. + # linkcheck needs the base commit. fetch-depth: 0 - name: Cache binaries @@ -60,18 +60,11 @@ jobs: cargo install mdbook-toc --version ${{ env.MDBOOK_TOC_VERSION }} - name: Check build - if: github.event_name != 'push' - run: | - git switch -c ci - git fetch origin master - git rebase origin/master - git log --oneline | head -n 10 - mdbook build + run: mdbook build - name: Deploy to gh-pages if: github.event_name == 'push' && github.repository == 'rust-lang/rustc-dev-guide' run: | - mdbook build touch "${{ env.DEPLOY_DIR }}/.nojekyll" cp CNAME "${{ env.DEPLOY_DIR }}" cd "${{ env.DEPLOY_DIR }}" diff --git a/ci/linkcheck.sh b/ci/linkcheck.sh index 0dcd67ec8..3d70432f5 100755 --- a/ci/linkcheck.sh +++ b/ci/linkcheck.sh @@ -18,7 +18,7 @@ elif [ "$CI" = "true" ] ; then # running in PR CI build CHANGED_FILES=$(git diff --name-only $BASE_SHA... | tr '\n' ' ') FLAGS="--no-cache -f $CHANGED_FILES" - echo "Checking files changed from $BASE_SHA: $CHANGED_FILES" + echo "Checking files changed since $BASE_SHA: $CHANGED_FILES" set -x else # running locally COMMIT_RANGE=master...