forked from kcp-dev/kcp
-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (125 loc) · 3.8 KB
/
docs-gen-and-push.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
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
130
131
132
133
134
135
136
137
138
name: Generate and push docs
on:
push:
branches:
- main
tags:
- "v*"
paths:
- "cmd/**"
- "docs/**"
- "pkg/**"
- "README.md"
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
jobs:
generate-and-push:
name: Generate and push docs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true # Fetch Hugo themes (true OR recursive)
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
path: kcp
- uses: actions/checkout@v3
with:
ref: gh-pages
path: docs
- uses: actions/setup-go@v3
with:
go-version: v1.19
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: "0.104.3"
extended: true
# install npm dependencies
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "16"
- name: Cache dependencies
uses: actions/[email protected]
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: cd kcp/docs && npm install && npm ci
- name: Copy readmes
run: tail -n +4 kcp/README.md >> kcp/docs/content/en/main/_index.md
- name: Generate CLI and CRD docs
run: |
cd kcp
make generate-docs
cat <<EOF > docs/content/en/main/cli/_index.md
---
title: "CLI Reference"
linkTitle: "CLI Reference"
weight: 4
description: >
Reference documentation for the kcp CLI.
---
EOF
- name: Build hugo docs
run: |
cd kcp/docs
hugo --minify
mv public ../../public
# This step check if the trigger is a tag and if so, it will update the version in the
# config.toml file and mark it as archived, since the tag is also a latest main, the same
# content is rebuilt using updated config and folder name. The folder thus generated is saved
# as archive in gh-pages branch.
- name: Update version info on tag for archive
if: startsWith(github.ref, 'refs/tags/v')
run: |
cd kcp/docs
cat <<EOF > temp.txt
#version-start
archived_version = true
version = "${{ github.ref }}"
EOF
ed config.toml<<EOF
/^#version-start
+,/^#version-end/-1d
-r !sed -n '/^#version-start/,/^#version-end/p' temp.txt | grep -v '^#'
w
q
EOF
mkdir -p content/en/${{ github.ref }}
mv content/en/main content/en/${{ github.ref }}
hugo --minify
rsync -av public/${{ github.ref }} ../../docs
- name: Push to gh-pages on tag for archive
if: startsWith(github.ref, 'refs/tags/v')
run: |
cd docs
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "Static archive of docs for ${{ github.ref }}"
git push
- name: Copy everything from archive to docs
run: rsync -av docs public
- name: Upload build artifact
uses: actions/upload-pages-artifact@v1
with:
path: public/
# Deployment Job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-22.04
needs: generate-and-push
steps:
- name: Deploy
id: deployment
uses: actions/deploy-pages@v1