-
Notifications
You must be signed in to change notification settings - Fork 1
92 lines (89 loc) · 3.45 KB
/
deploy_mdbook.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# SPDX-FileCopyrightText: 2024 Cognitive Disorders Research Lab
#
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: MIT
name: Book Deployment
on:
workflow_call:
outputs:
deployment_url:
description: "The vercel deployment url of the book"
value: ${{ jobs.deploy_book.outputs.deployment_url }}
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
GITHUB_TOKEN: ${{ secrets.ACTIONS_PAT_GITHUB }}
BRANCH: ${{ github.ref_name }}
PROJECT_ENVIRONMENT: ''
STORE_PATH: ''
jobs:
deploy_book:
runs-on: ubuntu-latest
outputs:
deployment_url: ${{ steps.output_deployment_url.outputs.deployment_url }}
steps:
- name: Checkout the Repository
uses: actions/checkout@v3
- name: Decide Deployment Environment
id: deployment_environment
run: |
if [[ ${{ env.BRANCH }} == "main" ]]; then
echo "PROJECT_ENVIRONMENT=production" >> $GITHUB_ENV
else
echo "PROJECT_ENVIRONMENT=preview" >> $GITHUB_ENV
fi
- name: Setup NodeJS
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
id: rust-toolchain
with:
toolchain: stable
- name: Cache dependencies
uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # v2.2.1
- name: Install cargo-binstall
uses: taiki-e/install-action@v2
with:
tool: cargo-binstall
- name: Install dependencies
run: cargo binstall --log-level debug --no-confirm --locked mdbook mdbook-plantuml mdbook-inline-highlighting
- name: Install dependencies
run: pnpm install -g vercel@latest
- name: Populate Preview Variables
run: vercel pull --yes --environment=${{env.PROJECT_ENVIRONMENT}} --token=${{ env.VERCEL_TOKEN }}
- name: Build the Book
run: mdbook build guide
- name: Build for Vercel deployment -- Preview
if: env.PROJECT_ENVIRONMENT == 'preview'
run: vercel build --cwd guide/book -y -d --token=${{ env.VERCEL_TOKEN }}
- name: Build for Vercel deployment -- Production
if: env.PROJECT_ENVIRONMENT == 'production'
run: vercel build --cwd guide/book -y --prod -d --token=${{ env.VERCEL_TOKEN }}
- name: Deploy to Vercel -- Preview
if: env.PROJECT_ENVIRONMENT == 'preview'
run: vercel deploy --cwd guide/book --prebuilt --token=${{ env.VERCEL_TOKEN }} > deployment_url
- name: Deploy to Vercel -- Production
if: env.PROJECT_ENVIRONMENT == 'production'
run: vercel deploy --cwd guide/book --prod --prebuilt --token=${{ env.VERCEL_TOKEN }} > deployment_url
- name: Output Deployment URL
id: output_deployment_url
run: echo "deployment_url=$(cat deployment_url)" >> $GITHUB_OUTPUT