|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + pull_request: |
| 8 | + schedule: |
| 9 | + # Run at 18:00 UTC every day |
| 10 | + - cron: '0 18 * * *' |
| 11 | + |
| 12 | +jobs: |
| 13 | + ci: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v2 |
| 17 | + with: |
| 18 | + # Set 0 to rebase later. |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: Read .env |
| 22 | + run: | |
| 23 | + . ./.env |
| 24 | + echo "MDBOOK_VERSION=${MDBOOK_VERSION}" >> $GITHUB_ENV |
| 25 | + echo "MDBOOK_LINKCHECK_VERSION=${MDBOOK_LINKCHECK_VERSION}" >> $GITHUB_ENV |
| 26 | + echo "MDBOOK_TOC_VERSION=${MDBOOK_TOC_VERSION}" >> $GITHUB_ENV |
| 27 | + echo "DEPLOY_DIR=${DEPLOY_DIR}" >> $GITHUB_ENV |
| 28 | +
|
| 29 | + - name: Cache binaries |
| 30 | + id: mdbook-cache |
| 31 | + uses: actions/cache@v2 |
| 32 | + with: |
| 33 | + path: | |
| 34 | + ~/.cargo/bin |
| 35 | + key: ${{ runner.os }}-${{ env.MDBOOK_VERSION }}--${{ env.MDBOOK_LINKCHECK_VERSION }}--${{ env.MDBOOK_TOC_VERSION }} |
| 36 | + |
| 37 | + - name: Cache linkcheck |
| 38 | + uses: actions/cache@v2 |
| 39 | + with: |
| 40 | + path: | |
| 41 | + ~/book/linkcheck |
| 42 | + key: ${{ runner.os }}-${{ hashFiles('./book/linkcheck') }} |
| 43 | + |
| 44 | + - name: Check line lengths |
| 45 | + if: github.event_name != 'schedule' |
| 46 | + run: | |
| 47 | + shopt -s globstar |
| 48 | + MAX_LINE_LENGTH=100 bash ci/check_line_lengths.sh src/**/*.md |
| 49 | +
|
| 50 | + - name: Install latest nightly Rust toolchain |
| 51 | + if: steps.mdbook-cache.outputs.cache-hit != 'true' |
| 52 | + uses: actions-rs/toolchain@v1 |
| 53 | + with: |
| 54 | + toolchain: nightly |
| 55 | + override: true |
| 56 | + |
| 57 | + - name: Install Dependencies |
| 58 | + if: steps.mdbook-cache.outputs.cache-hit != 'true' |
| 59 | + run: | |
| 60 | + cargo install mdbook --version ${{ env.MDBOOK_VERSION }} |
| 61 | + cargo install mdbook-linkcheck --version ${{ env.MDBOOK_LINKCHECK_VERSION }} |
| 62 | + cargo install mdbook-toc --version ${{ env.MDBOOK_TOC_VERSION }} |
| 63 | +
|
| 64 | + - name: Check build |
| 65 | + if: github.event_name != 'schedule' |
| 66 | + run: | |
| 67 | + git switch -c ci |
| 68 | + git fetch origin master |
| 69 | + git rebase origin/master |
| 70 | + git log --oneline | head -n 10 |
| 71 | + mdbook build |
| 72 | +
|
| 73 | + - name: Deploy to gh-pages |
| 74 | + if: github.event_name == 'schedule' && github.repository == 'rust-lang/rustc-dev-guide' |
| 75 | + run: | |
| 76 | + mdbook build |
| 77 | + touch "${{ env.DEPLOY_DIR }}/.nojekyll" |
| 78 | + cp CNAME "${{ env.DEPLOY_DIR }}" |
| 79 | + cd "${{ env.DEPLOY_DIR }}" |
| 80 | + rm -rf .git |
| 81 | + git init |
| 82 | + git config user.name "Deploy from CI" |
| 83 | + git config user.email "" |
| 84 | + git add . |
| 85 | + git commit -m "Deploy ${GITHUB_SHA} to gh-pages" |
| 86 | + git push --quiet -f "https://x-token:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}" HEAD:gh-pages |
0 commit comments