2021-02-19 20:35:43 +08:00
|
|
|
# When publish a release. This workflow will trigger and deploy to site.
|
|
|
|
|
|
|
|
name: Deploy website
|
|
|
|
on:
|
|
|
|
create
|
|
|
|
|
2022-04-11 11:15:26 +08:00
|
|
|
permissions:
|
2022-11-20 01:13:54 +08:00
|
|
|
contents: write
|
2022-04-11 11:15:26 +08:00
|
|
|
|
2021-02-19 20:35:43 +08:00
|
|
|
jobs:
|
|
|
|
setup:
|
|
|
|
runs-on: ubuntu-latest
|
2022-11-18 14:29:52 +08:00
|
|
|
if: github.event.ref_type == 'tag' && (contains(github.event.ref, '-') == false)
|
2021-02-19 20:35:43 +08:00
|
|
|
steps:
|
|
|
|
- name: checkout
|
2022-03-19 21:53:48 +08:00
|
|
|
uses: actions/checkout@v3
|
2021-02-19 20:35:43 +08:00
|
|
|
|
|
|
|
- name: cache package-lock.json
|
2022-03-22 10:59:37 +08:00
|
|
|
uses: actions/cache@v3
|
2021-02-19 20:35:43 +08:00
|
|
|
with:
|
|
|
|
path: package-temp-dir
|
|
|
|
key: lock-${{ github.sha }}
|
|
|
|
|
|
|
|
- name: create package-lock.json
|
2022-06-10 17:06:07 +08:00
|
|
|
run: npm i --package-lock-only --ignore-scripts
|
2021-02-19 20:35:43 +08:00
|
|
|
|
|
|
|
- name: hack for single file
|
|
|
|
run: |
|
|
|
|
if [ ! -d "package-temp-dir" ]; then
|
|
|
|
mkdir package-temp-dir
|
|
|
|
fi
|
|
|
|
cp package-lock.json package-temp-dir
|
|
|
|
- name: cache node_modules
|
|
|
|
id: node_modules_cache_id
|
2022-03-22 10:59:37 +08:00
|
|
|
uses: actions/cache@v3
|
2021-02-19 20:35:43 +08:00
|
|
|
with:
|
|
|
|
path: node_modules
|
|
|
|
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
|
|
|
|
|
|
|
|
- name: install
|
|
|
|
if: steps.node_modules_cache_id.outputs.cache-hit != 'true'
|
|
|
|
run: npm ci
|
|
|
|
|
|
|
|
build-and-deploy:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
needs: setup
|
|
|
|
steps:
|
|
|
|
- name: checkout
|
2022-03-19 21:53:48 +08:00
|
|
|
uses: actions/checkout@v3
|
2021-02-19 20:35:43 +08:00
|
|
|
|
|
|
|
- name: restore cache from package-lock.json
|
2022-03-22 10:59:37 +08:00
|
|
|
uses: actions/cache@v3
|
2021-02-19 20:35:43 +08:00
|
|
|
with:
|
|
|
|
path: package-temp-dir
|
|
|
|
key: lock-${{ github.sha }}
|
|
|
|
|
|
|
|
- name: restore cache from node_modules
|
2022-03-22 10:59:37 +08:00
|
|
|
uses: actions/cache@v3
|
2021-02-19 20:35:43 +08:00
|
|
|
with:
|
|
|
|
path: node_modules
|
|
|
|
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
|
|
|
|
|
|
|
|
- name: build
|
|
|
|
run: npm run predeploy
|
|
|
|
|
|
|
|
- name: deploy
|
2021-10-19 19:40:08 +08:00
|
|
|
uses: peaceiris/actions-gh-pages@v3
|
2021-02-19 20:35:43 +08:00
|
|
|
with:
|
2022-11-20 01:13:54 +08:00
|
|
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
2021-11-27 22:51:11 +08:00
|
|
|
publish_dir: ./_site
|
2022-11-19 19:40:53 +08:00
|
|
|
force_orphan: true
|