From ac451eab06bdd69918e9fe258bc88caeb11ac8af Mon Sep 17 00:00:00 2001 From: sabertazimi Date: Tue, 8 Mar 2022 12:03:44 +0800 Subject: [PATCH] ci(action-pages): setup GitHub Pages action --- .github/workflows/ci.yml | 58 ++++++++++++++++++++++++++++++++++++++++ deploy.sh | 21 --------------- 2 files changed, 58 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100755 deploy.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..17e003de --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,58 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +env: + CARGO_TERM_COLOR: always + +jobs: + pages: + name: Building and Deployment + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + submodules: true + fetch-depth: 1 + - name: Cache cargo binaries and registry + uses: actions/cache@v2 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/book.toml') }} + - name: Install mdbook + continue-on-error: true + run: | + cargo install mdbook || exit 0 + - name: Check toolchain version + run: | + rustc -V + cargo -V + mdbook -V + - name: Build book + run: | + mdbook build + - name: Copy metadata files + run: | + cp ./assets/CNAME ./book/ + cp ./assets/*.html ./book/ + cp ./assets/sitemap.xml ./book/ + - name: Deploy to Github Pages + uses: peaceiris/actions-gh-pages@v3 + if: ${{ github.ref == 'refs/heads/main' }} + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./book + force_orphan: true + user_name: 'github-actions[bot]' + user_email: 'github-actions[bot]@users.noreply.github.com' + commit_message: ${{ github.event.head_commit.message }} diff --git a/deploy.sh b/deploy.sh deleted file mode 100755 index e661e8fb..00000000 --- a/deploy.sh +++ /dev/null @@ -1,21 +0,0 @@ -## this script deploys the static website of course.rs to github pages - -## build static website for book -mdbook build -## copy CNAME info to book dir -cp ./assets/CNAME ./book/ -cp ./assets/*.html ./book/ -cp ./assets/sitemap.xml ./book/ - -## init git repo -cd book -git init -git config user.name "sunface" -git config user.email "cto@188.com" -git add . -git commit -m 'deploy' -git branch -M gh-pages -git remote add origin https://github.com/sunface/rust-course - -## push to github pages -git push -u -f origin gh-pages \ No newline at end of file