|
| 1 | +name: Build and deploy an updated version of the website |
| 2 | + |
| 3 | +on: |
| 4 | + [push, pull_request] |
| 5 | + |
| 6 | +env: |
| 7 | + MDBOOK_LINKCHECK_VER: 0.7.4 |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Checkout pandocs |
| 14 | + uses: actions/checkout@v2 |
| 15 | + with: |
| 16 | + path: pandocs |
| 17 | + |
| 18 | + - name: Install mdbook |
| 19 | + uses: peaceiris/actions-mdbook@v1 |
| 20 | + with: |
| 21 | + mdbook-version: latest |
| 22 | + |
| 23 | + # FIXME: Keep this up to date |
| 24 | + - name: Install mdbook-linkcheck |
| 25 | + run: | # `-L` because GitHub performs a redirection |
| 26 | + curl -L -o mdbook-linkcheck.zip "https://github.com/Michael-F-Bryan/mdbook-linkcheck/releases/download/v$MDBOOK_LINKCHECK_VER/mdbook-linkcheck.v$MDBOOK_LINKCHECK_VER.x86_64-unknown-linux-gnu.zip" |
| 27 | + unzip mdbook-linkcheck.zip mdbook-linkcheck |
| 28 | + chmod +x mdbook-linkcheck |
| 29 | +
|
| 30 | + - name: Install Python dependencies |
| 31 | + run: | |
| 32 | + python -m pip install --upgrade pip |
| 33 | + pip install -r pandocs/requirements.txt |
| 34 | +
|
| 35 | + - name: Cache build dir |
| 36 | + uses: actions/cache@v2 |
| 37 | + with: |
| 38 | + path: pandocs/target/ |
| 39 | + key: ${{ runner.os }}-build-${{ hashFiles('pandocs/Cargo.lock') }} |
| 40 | + restore-keys: | |
| 41 | + ${{ runner.os }}-build- |
| 42 | +
|
| 43 | + - name: Build |
| 44 | + working-directory: pandocs/ |
| 45 | + env: |
| 46 | + MDBOOK_BUILD__CREATE_MISSING: "false" # Prevent creating missing files in SUMMARY.md |
| 47 | + MDBOOK_OUTPUT__LINKCHECK__COMMAND: "../mdbook-linkcheck" |
| 48 | + run: | |
| 49 | + mdbook build |
| 50 | +
|
| 51 | + - name: Store final build |
| 52 | + uses: actions/upload-artifact@v2 |
| 53 | + with: |
| 54 | + name: Build output |
| 55 | + path: pandocs/docs/pandocs/ |
| 56 | + if-no-files-found: error |
| 57 | + |
| 58 | + deploy: |
| 59 | + runs-on: ubuntu-latest |
| 60 | + needs: build |
| 61 | + # Do not run this unless *pushing* (`heads`) to `master` |
| 62 | + if: github.ref == 'refs/heads/master' |
| 63 | + steps: |
| 64 | + - name: Checkout pandocs/gh-pages |
| 65 | + uses: actions/checkout@v2 |
| 66 | + with: |
| 67 | + path: pandocs |
| 68 | + ref: gh-pages |
| 69 | + |
| 70 | + - name: Delete all current files |
| 71 | + run: | |
| 72 | + rm -vrf pandocs/* |
| 73 | +
|
| 74 | + - name: Unpack build |
| 75 | + uses: actions/download-artifact@v2 |
| 76 | + with: |
| 77 | + name: Build output |
| 78 | + path: pandocs/ |
| 79 | + |
| 80 | + - name: Deploy |
| 81 | + working-directory: pandocs/ |
| 82 | + run: | |
| 83 | + git config --local user.name "GitHub Action" |
| 84 | + git config --global user.email "[email protected]" |
| 85 | + git remote -v |
| 86 | + git branch -v |
| 87 | + git add -A |
| 88 | + git commit -am 'Update build' |
| 89 | + git push -v |
0 commit comments