From 97c4a33fcdbd8f3b2cdf638cfa7c9da9d615254a Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 1 Feb 2021 13:53:59 +0100 Subject: [PATCH 1/6] Adding mdbook support --- .env | 7 + .github/workflows/gh-pages.yml | 52 ++++++++ book.toml | 20 +++ ci/ghpages-deploy.sh | 226 +++++++++++++++++++++++++++++++++ 4 files changed, 305 insertions(+) create mode 100644 .env create mode 100644 .github/workflows/gh-pages.yml create mode 100644 book.toml create mode 100644 ci/ghpages-deploy.sh diff --git a/.env b/.env new file mode 100644 index 0000000..392a5ad --- /dev/null +++ b/.env @@ -0,0 +1,7 @@ +MDBOOK_VERSION=0.4.6 +MDBOOK_LINKCHECK_VERSION=0.7.2 +MDBOOK_TOC_VERSION=0.6.1 + +GIT_DEPLOY_DIR=book +GIT_DEPLOY_BRANCH=gh-pages +GIT_DEPLOY_REPO=https://github.com/rust-lang/std-dev-guide diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml new file mode 100644 index 0000000..65942bc --- /dev/null +++ b/.github/workflows/gh-pages.yml @@ -0,0 +1,52 @@ +name: github pages + +on: + push: + branches: + - master + +jobs: + deploy: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + + - name: Read .env + id: mdbook-version + run: | + . ./.env + echo "::set-output name=MDBOOK_VERSION::${MDBOOK_VERSION}" + echo "::set-output name=MDBOOK_LINKCHECK_VERSION::${MDBOOK_LINKCHECK_VERSION}" + echo "::set-output name=MDBOOK_TOC_VERSION::${MDBOOK_TOC_VERSION}" + + - name: Cache binaries + id: mdbook-cache + uses: actions/cache@v2 + with: + path: | + ~/.cargo/bin + key: ${{ runner.os }}-${{ steps.mdbook-version.outputs.MDBOOK_VERSION }}--${{ steps.mdbook-version.outputs.DBOOK_LINKCHECK_VERSION }}--${{ steps.mdbook-version.outputs.MDBOOK_TOC_VERSION }} + + - name: Install latest stable Rust toolchain + if: steps.mdbook-cache.outputs.cache-hit != 'true' + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Install Dependencies + if: steps.mdbook-cache.outputs.cache-hit != 'true' + run: | + cargo install mdbook --version ${{ steps.mdbook-version.outputs.MDBOOK_VERSION }} + cargo install mdbook-linkcheck --version ${{ steps.mdbook-version.outputs.MDBOOK_LINKCHECK_VERSION }} + cargo install mdbook-toc --version ${{ steps.mdbook-version.outputs.MDBOOK_TOC_VERSION }} + + - name: Build book + run: mdbook build + + - name: Deploy to gh-pages + run: | + git config --global user.email "Runner@GH Actions Deployment" + git config --global user.name "GH Actions Runner" + chmod u+x ci/ghpages-deploy.sh + ./ci/ghpages-deploy.sh diff --git a/book.toml b/book.toml new file mode 100644 index 0000000..37e9aab --- /dev/null +++ b/book.toml @@ -0,0 +1,20 @@ +[book] +title = "Standard library developers Guide" +authors = ["the rust-lang authors"] +description = "Guide for standard library developers" +language = "en" +multilingual = false +src = "./src" + +[build] +create-missing = false + +[rust] +edition = "2018" + +[output.html] +default-theme = "rust" +git-repository-url = "https://github.com/rust-lang/std-dev-guide" +git-repository-icon = "fa-github" + +# [output.linkcheck] # enable the "mdbook-linkcheck" renderer, disabled due to gh-actions diff --git a/ci/ghpages-deploy.sh b/ci/ghpages-deploy.sh new file mode 100644 index 0000000..c77b08e --- /dev/null +++ b/ci/ghpages-deploy.sh @@ -0,0 +1,226 @@ +#!/usr/bin/env bash + +# This file was taken from https://github.com/X1011/git-directory-deploy/blob/e37ac94cda4bfc5773c0f01d89d8c875a21ab4f9/deploy.sh, +# Copyright 2013-2021 Daniel Smith +# All rights reserved. +# It's licensed under the terms of the 3-clause BSD license. + +set -o errexit #abort if any command fails +me=$(basename "$0") + +help_message="\ +Usage: $me [-c FILE] [] +Deploy generated files to a git branch. + +Options: + + -h, --help Show this help information. + -v, --verbose Increase verbosity. Useful for debugging. + -e, --allow-empty Allow deployment of an empty directory. + -m, --message MESSAGE Specify the message used when committing on the + deploy branch. + -n, --no-hash Don't append the source commit's hash to the deploy + commit's message. + -c, --config-file PATH Override default & environment variables' values + with those in set in the file at 'PATH'. Must be the + first option specified. + +Variables: + + GIT_DEPLOY_DIR Folder path containing the files to deploy. + GIT_DEPLOY_BRANCH Commit deployable files to this branch. + GIT_DEPLOY_REPO Push the deploy branch to this repository. + +These variables have default values defined in the script. The defaults can be +overridden by environment variables. Any environment variables are overridden +by values set in a '.env' file (if it exists), and in turn by those set in a +file specified by the '--config-file' option." + +parse_args() { + # Set args from a local environment file. + if [ -e ".env" ]; then + source .env + fi + + # Set args from file specified on the command-line. + if [[ $1 = "-c" || $1 = "--config-file" ]]; then + source "$2" + shift 2 + fi + + # Parse arg flags + # If something is exposed as an environment variable, set/overwrite it + # here. Otherwise, set/overwrite the internal variable instead. + while : ; do + if [[ $1 = "-h" || $1 = "--help" ]]; then + echo "$help_message" + return 0 + elif [[ $1 = "-v" || $1 = "--verbose" ]]; then + verbose=true + shift + elif [[ $1 = "-e" || $1 = "--allow-empty" ]]; then + allow_empty=true + shift + elif [[ ( $1 = "-m" || $1 = "--message" ) && -n $2 ]]; then + commit_message=$2 + shift 2 + elif [[ $1 = "-n" || $1 = "--no-hash" ]]; then + GIT_DEPLOY_APPEND_HASH=false + shift + else + break + fi + done + + # Set internal option vars from the environment and arg flags. All internal + # vars should be declared here, with sane defaults if applicable. + + # Source directory & target branch. + deploy_directory=${GIT_DEPLOY_DIR:-dist} + deploy_branch=${GIT_DEPLOY_BRANCH:-gh-pages} + + #if no user identity is already set in the current git environment, use this: + default_username=${GIT_DEPLOY_USERNAME:-deploy.sh} + default_email=${GIT_DEPLOY_EMAIL:-} + + #repository to deploy to. must be readable and writable. + repo=${GIT_DEPLOY_REPO:-origin} + + #append commit hash to the end of message by default + append_hash=${GIT_DEPLOY_APPEND_HASH:-true} +} + +main() { + parse_args "$@" + + enable_expanded_output + + if ! git diff --exit-code --quiet --cached; then + echo Aborting due to uncommitted changes in the index >&2 + return 1 + fi + + commit_title=`git log -n 1 --format="%s" HEAD` + commit_hash=` git log -n 1 --format="%H" HEAD` + + #default commit message uses last title if a custom one is not supplied + if [[ -z $commit_message ]]; then + commit_message="publish: $commit_title" + fi + + #append hash to commit message unless no hash flag was found + if [ $append_hash = true ]; then + commit_message="$commit_message"$'\n\n'"generated from commit $commit_hash" + fi + + previous_branch=`git rev-parse --abbrev-ref HEAD` + + if [ ! -d "$deploy_directory" ]; then + echo "Deploy directory '$deploy_directory' does not exist. Aborting." >&2 + return 1 + fi + + # must use short form of flag in ls for compatibility with OS X and BSD + if [[ -z `ls -A "$deploy_directory" 2> /dev/null` && -z $allow_empty ]]; then + echo "Deploy directory '$deploy_directory' is empty. Aborting. If you're sure you want to deploy an empty tree, use the --allow-empty / -e flag." >&2 + return 1 + fi + + if git ls-remote --exit-code $repo "refs/heads/$deploy_branch" ; then + # deploy_branch exists in $repo; make sure we have the latest version + + disable_expanded_output + git fetch --force $repo $deploy_branch:$deploy_branch + enable_expanded_output + fi + + # check if deploy_branch exists locally + if git show-ref --verify --quiet "refs/heads/$deploy_branch" + then incremental_deploy + else initial_deploy + fi + + restore_head +} + +initial_deploy() { + git --work-tree "$deploy_directory" checkout --orphan $deploy_branch + git --work-tree "$deploy_directory" add --all + commit+push +} + +incremental_deploy() { + #make deploy_branch the current branch + git symbolic-ref HEAD refs/heads/$deploy_branch + #put the previously committed contents of deploy_branch into the index + git --work-tree "$deploy_directory" reset --mixed --quiet + git --work-tree "$deploy_directory" add --all + + set +o errexit + diff=$(git --work-tree "$deploy_directory" diff --exit-code --quiet HEAD --)$? + set -o errexit + case $diff in + 0) echo No changes to files in $deploy_directory. Skipping commit.;; + 1) commit+push;; + *) + echo git diff exited with code $diff. Aborting. Staying on branch $deploy_branch so you can debug. To switch back to master, use: git symbolic-ref HEAD refs/heads/master && git reset --mixed >&2 + return $diff + ;; + esac +} + +commit+push() { + set_user_id + git --work-tree "$deploy_directory" commit -m "$commit_message" + + disable_expanded_output + #--quiet is important here to avoid outputting the repo URL, which may contain a secret token + git push --quiet $repo $deploy_branch + enable_expanded_output +} + +#echo expanded commands as they are executed (for debugging) +enable_expanded_output() { + if [ $verbose ]; then + set -o xtrace + set +o verbose + fi +} + +#this is used to avoid outputting the repo URL, which may contain a secret token +disable_expanded_output() { + if [ $verbose ]; then + set +o xtrace + set -o verbose + fi +} + +set_user_id() { + if [[ -z `git config user.name` ]]; then + git config user.name "$default_username" + fi + if [[ -z `git config user.email` ]]; then + git config user.email "$default_email" + fi +} + +restore_head() { + if [[ $previous_branch = "HEAD" ]]; then + #we weren't on any branch before, so just set HEAD back to the commit it was on + git update-ref --no-deref HEAD $commit_hash $deploy_branch + else + git symbolic-ref HEAD refs/heads/$previous_branch + fi + + git reset --mixed +} + +filter() { + sed -e "s|$repo|\$repo|g" +} + +sanitize() { + "$@" 2> >(filter 1>&2) | filter +} + +[[ $1 = --source-only ]] || main "$@" From 98ab8cf2073185eaf841430ca444e172a0758348 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 1 Feb 2021 15:10:08 +0100 Subject: [PATCH 2/6] Enable toc and linkcheck --- book.toml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/book.toml b/book.toml index 37e9aab..07294ba 100644 --- a/book.toml +++ b/book.toml @@ -12,9 +12,15 @@ create-missing = false [rust] edition = "2018" +[preprocessor.toc] +command = "mdbook-toc" +renderer = ["html"] + +[output.linkcheck] + [output.html] default-theme = "rust" git-repository-url = "https://github.com/rust-lang/std-dev-guide" git-repository-icon = "fa-github" -# [output.linkcheck] # enable the "mdbook-linkcheck" renderer, disabled due to gh-actions + From 203ee92062fa51e7fd5e7d19c9bdd581d03b24d2 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 1 Feb 2021 15:22:58 +0100 Subject: [PATCH 3/6] Adding CI --- .github/workflows/ci.yml | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d120c4e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,45 @@ +name: Continuous Integration + +on: + push: + branches: [master] + pull_request: + +jobs: + book-test: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + + - name: Read .env + id: mdbook-version + run: | + . ./.env + echo "::set-output name=MDBOOK_VERSION::${MDBOOK_VERSION}" + echo "::set-output name=MDBOOK_LINKCHECK_VERSION::${MDBOOK_LINKCHECK_VERSION}" + echo "::set-output name=MDBOOK_TOC_VERSION::${MDBOOK_TOC_VERSION}" + + - name: Cache binaries + id: mdbook-cache + uses: actions/cache@v2 + with: + path: | + ~/.cargo/bin + key: ${{ runner.os }}-${{ steps.mdbook-version.outputs.MDBOOK_VERSION }}--${{ steps.mdbook-version.outputs.DBOOK_LINKCHECK_VERSION }}--${{ steps.mdbook-version.outputs.MDBOOK_TOC_VERSION }} + + - name: Install latest stable Rust toolchain + if: steps.mdbook-cache.outputs.cache-hit != 'true' + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Install Dependencies + if: steps.mdbook-cache.outputs.cache-hit != 'true' + run: | + cargo install mdbook --version ${{ steps.mdbook-version.outputs.MDBOOK_VERSION }} + cargo install mdbook-linkcheck --version ${{ steps.mdbook-version.outputs.MDBOOK_LINKCHECK_VERSION }} + cargo install mdbook-toc --version ${{ steps.mdbook-version.outputs.MDBOOK_TOC_VERSION }} + + - name: Test book + run: mdbook test From ef89e9e66625791fbdfc30ef721f811271d7f4b6 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 1 Feb 2021 15:26:40 +0100 Subject: [PATCH 4/6] Add book build to CI --- .github/workflows/ci.yml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d120c4e..fe10edf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,3 +43,41 @@ jobs: - name: Test book run: mdbook test + + book-build: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + + - name: Read .env + id: mdbook-version + run: | + . ./.env + echo "::set-output name=MDBOOK_VERSION::${MDBOOK_VERSION}" + echo "::set-output name=MDBOOK_LINKCHECK_VERSION::${MDBOOK_LINKCHECK_VERSION}" + echo "::set-output name=MDBOOK_TOC_VERSION::${MDBOOK_TOC_VERSION}" + + - name: Cache binaries + id: mdbook-cache + uses: actions/cache@v2 + with: + path: | + ~/.cargo/bin + key: ${{ runner.os }}-${{ steps.mdbook-version.outputs.MDBOOK_VERSION }}--${{ steps.mdbook-version.outputs.DBOOK_LINKCHECK_VERSION }}--${{ steps.mdbook-version.outputs.MDBOOK_TOC_VERSION }} + + - name: Install latest stable Rust toolchain + if: steps.mdbook-cache.outputs.cache-hit != 'true' + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Install Dependencies + if: steps.mdbook-cache.outputs.cache-hit != 'true' + run: | + cargo install mdbook --version ${{ steps.mdbook-version.outputs.MDBOOK_VERSION }} + cargo install mdbook-linkcheck --version ${{ steps.mdbook-version.outputs.MDBOOK_LINKCHECK_VERSION }} + cargo install mdbook-toc --version ${{ steps.mdbook-version.outputs.MDBOOK_TOC_VERSION }} + + - name: Test book + run: mdbook build \ No newline at end of file From 63225a5f3ade6c59b0e3e30621a47c6a0cc29e23 Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 1 Feb 2021 15:40:15 +0100 Subject: [PATCH 5/6] New line --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe10edf..df3d4b9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,5 +79,5 @@ jobs: cargo install mdbook-linkcheck --version ${{ steps.mdbook-version.outputs.MDBOOK_LINKCHECK_VERSION }} cargo install mdbook-toc --version ${{ steps.mdbook-version.outputs.MDBOOK_TOC_VERSION }} - - name: Test book - run: mdbook build \ No newline at end of file + - name: Build book for testing + run: mdbook build From 99219f102e6275983d6598fce70c46729c767928 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 2 Feb 2021 07:55:32 +0100 Subject: [PATCH 6/6] Remove travis, remove empty lines in book.toml --- .travis.yml | 38 -------------------------------------- book.toml | 2 -- 2 files changed, 40 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e08b033..0000000 --- a/.travis.yml +++ /dev/null @@ -1,38 +0,0 @@ -language: rust -dist: bionic -rust: -- nightly -cache: -- cargo -- directories: - - book/linkcheck/ -before_install: -- shopt -s globstar -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/book.toml b/book.toml index 07294ba..d7a254f 100644 --- a/book.toml +++ b/book.toml @@ -22,5 +22,3 @@ renderer = ["html"] default-theme = "rust" git-repository-url = "https://github.com/rust-lang/std-dev-guide" git-repository-icon = "fa-github" - -