-
Notifications
You must be signed in to change notification settings - Fork 1
129 lines (114 loc) · 3.89 KB
/
build-and-deploy-docs.yml
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: Build and deploy docs
on:
workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: "Run the build with tmate debugging enabled"
pull_request: { }
push:
branches:
- "main"
concurrency:
group: "${{ github.workflow }}-${{ github.event.pull_request.number || github.event.after }}"
cancel-in-progress: true
permissions:
contents: "read"
pages: "write"
id-token: "write"
pull-requests: "read"
statuses: "write"
jobs:
check_changes:
name: "Deduce required tests from code changes"
runs-on: "ubuntu-latest"
outputs:
docs: "${{ steps.changes.outputs.docs }}"
steps:
- name: "Checkout"
if: "${{ !github.event.pull_request }}"
uses: "actions/checkout@v4"
with:
persist-credentials: "false"
fetch-depth: "0"
- name: "Check code changes"
uses: "dorny/paths-filter@v3"
id: "changes"
with:
# For "push" events, compare against the "ref" base branch.
# For "pull_request" events, this is ignored and will compare against
# the pull request base branch.
base: "${{ github.ref }}"
filters: |
docs:
- '*.nix'
- 'flake.lock'
- 'design-docs/**'
- 'nix/**'
- '.github/workflows/build-and-deploy-docs.yml'
build:
name: "Build and deploy documentation"
needs: [ check_changes ]
if: "${{ needs.check_changes.outputs.docs == 'true' }}"
runs-on: "ubuntu-latest"
steps:
- uses: cargo-bins/cargo-binstall@main
- run: cargo binstall --no-confirm just
- name: "Checkout"
uses: "actions/checkout@v4"
- name: "Extract branch name"
shell: "bash"
run: |
echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: "extract_branch"
- name: "Extract git hash"
shell: "bash"
run: |
echo "git_hash=${GITHUB_SHA}" >> $GITHUB_OUTPUT
id: "extract_hash"
- name: "Build design docs"
run: |
just mdbook build
- name: "Copy design doc build to publish directory"
run: |
set -euxo pipefail
mkdir --parent "${{ github.workspace }}/publish/"
cp -r ./design-docs/src/mdbook/book "${{ github.workspace }}/publish/design-docs"
- name: "(Push) Setup Pages"
if: "${{ !github.event.pull_request }}"
uses: "actions/configure-pages@v5"
- name: "(Push) Upload design-docs"
if: "${{ !github.event.pull_request }}"
uses: "actions/upload-pages-artifact@v3"
with:
# Upload design-docs build directory content
path: 'publish/design-docs'
- name: "(Push) Deploy to GitHub Pages"
if: "${{ !github.event.pull_request }}"
id: "deployment"
uses: "actions/deploy-pages@v4"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: "(PR) Deploy documentation preview"
if: "${{ github.event.pull_request }}"
uses: "nwtgck/actions-netlify@v2"
with:
publish-dir: "${{ github.workspace }}/publish/design-docs"
alias: "preview-${{ github.event.number }}"
deploy-message: "${{ github.event.pull_request.title }}"
github-token: "${{ secrets.GITHUB_TOKEN }}"
fails-without-credentials: "true"
enable-commit-status: "true"
enable-pull-request-comment: "false"
enable-commit-comment: "false"
enable-github-deployment: "false"
env:
NETLIFY_AUTH_TOKEN: "${{ secrets.NETLIFY_AUTH_TOKEN }}"
NETLIFY_SITE_ID: "${{ secrets.NETLIFY_SITE_ID }}"
timeout-minutes: 5
- name: Setup tmate session for debug
if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3
timeout-minutes: 30
with:
limit-access-to-actor: true