Skip to content

Commit 674f73d

Browse files
authored
Switch from Travis to GHA (#1073)
1 parent 912aa00 commit 674f73d

File tree

3 files changed

+83
-45
lines changed

3 files changed

+83
-45
lines changed

.github/workflows/ci.yml

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
env:
16+
MDBOOK_VERSION: 0.4.7
17+
MDBOOK_LINKCHECK_VERSION: 0.7.2
18+
MDBOOK_TOC_VERSION: 0.6.1
19+
DEPLOY_DIR: book/html
20+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
21+
steps:
22+
- uses: actions/checkout@v2
23+
with:
24+
# linkcheck needs the base commit.
25+
fetch-depth: 0
26+
27+
- name: Cache binaries
28+
id: mdbook-cache
29+
uses: actions/cache@v2
30+
with:
31+
path: |
32+
~/.cargo/bin
33+
key: ${{ runner.os }}-${{ env.MDBOOK_VERSION }}--${{ env.MDBOOK_LINKCHECK_VERSION }}--${{ env.MDBOOK_TOC_VERSION }}
34+
35+
- name: Cache linkcheck
36+
uses: actions/cache@v2
37+
with:
38+
path: |
39+
~/book/linkcheck
40+
key: ${{ runner.os }}-${{ hashFiles('./book/linkcheck') }}
41+
42+
- name: Check line lengths
43+
if: github.event_name != 'push'
44+
run: |
45+
shopt -s globstar
46+
MAX_LINE_LENGTH=100 bash ci/check_line_lengths.sh src/**/*.md
47+
48+
- name: Install latest nightly Rust toolchain
49+
if: steps.mdbook-cache.outputs.cache-hit != 'true'
50+
uses: actions-rs/toolchain@v1
51+
with:
52+
toolchain: nightly
53+
override: true
54+
55+
- name: Install Dependencies
56+
if: steps.mdbook-cache.outputs.cache-hit != 'true'
57+
run: |
58+
cargo install mdbook --version ${{ env.MDBOOK_VERSION }}
59+
cargo install mdbook-linkcheck --version ${{ env.MDBOOK_LINKCHECK_VERSION }}
60+
cargo install mdbook-toc --version ${{ env.MDBOOK_TOC_VERSION }}
61+
62+
- name: Check build
63+
run: mdbook build
64+
65+
- name: Deploy to gh-pages
66+
if: github.event_name == 'push' && github.repository == 'rust-lang/rustc-dev-guide'
67+
run: |
68+
touch "${{ env.DEPLOY_DIR }}/.nojekyll"
69+
cp CNAME "${{ env.DEPLOY_DIR }}"
70+
cd "${{ env.DEPLOY_DIR }}"
71+
rm -rf .git
72+
git init
73+
git config user.name "Deploy from CI"
74+
git config user.email ""
75+
git add .
76+
git commit -m "Deploy ${GITHUB_SHA} to gh-pages"
77+
git push --quiet -f "https://x-token:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}" HEAD:gh-pages

.travis.yml

-39
This file was deleted.

ci/linkcheck.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
set -e
44
set -o pipefail
55

6-
# https://docs.travis-ci.com/user/environment-variables/#default-environment-variables
7-
if [ "$TRAVIS_EVENT_TYPE" = "cron" ] ; then # running in cron job
6+
# https://docs.github.com/en/actions/reference/environment-variables
7+
if [ "$GITHUB_EVENT_NAME" = "schedule" ] ; then # running in scheduled job
88
FLAGS=""
99

1010
echo "Doing full link check."
1111
set -x
1212
elif [ "$CI" = "true" ] ; then # running in PR CI build
13-
if [ -z "$TRAVIS_COMMIT_RANGE" ]; then
14-
echo "error: unexpected state: TRAVIS_COMMIT_RANGE must be non-empty in CI"
13+
if [ -z "$BASE_SHA" ]; then
14+
echo "error: unexpected state: BASE_SHA must be non-empty in CI"
1515
exit 1
1616
fi
1717

18-
CHANGED_FILES=$(git diff --name-only $TRAVIS_COMMIT_RANGE | tr '\n' ' ')
18+
CHANGED_FILES=$(git diff --name-only $BASE_SHA... | tr '\n' ' ')
1919
FLAGS="--no-cache -f $CHANGED_FILES"
2020

21-
echo "Checking files changed in $TRAVIS_COMMIT_RANGE: $CHANGED_FILES"
21+
echo "Checking files changed since $BASE_SHA: $CHANGED_FILES"
2222
set -x
2323
else # running locally
2424
COMMIT_RANGE=master...

0 commit comments

Comments
 (0)