Skip to content

Commit

Permalink
Switch from Travis to GHA
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTitor committed Mar 2, 2021
1 parent c431f8c commit 374c29b
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 47 deletions.
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -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
86 changes: 86 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
39 changes: 0 additions & 39 deletions .travis.yml

This file was deleted.

12 changes: 4 additions & 8 deletions ci/linkcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down

0 comments on commit 374c29b

Please sign in to comment.