-
Notifications
You must be signed in to change notification settings - Fork 154
120 lines (115 loc) · 4.49 KB
/
reusable-publish-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
name: Reusable Publish docs
env:
BRANCH: main
ORIGIN: awslabs/aws-lambda-powertools-python
on:
workflow_call:
inputs:
version:
description: "Version to build and publish docs (1.28.0, develop)"
required: true
type: string
alias:
description: "Alias to associate version (latest, stage)"
required: true
type: string
detached_mode:
description: "Whether it's running in git detached mode to ensure git is sync'd"
required: false
default: false
type: boolean
workflow_origin: # see https://github.com/awslabs/aws-lambda-powertools-python/issues/1349
required: true
type: string
secrets:
token:
required: true
jobs:
publish-docs:
# see https://github.com/awslabs/aws-lambda-powertools-python/issues/1349
if: ${{ inputs.workflow_origin == 'awslabs/aws-lambda-powertools-typescript' }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
# Here `token` is needed to avoid incurring in error GH006 Protected Branch Update Failed,
token: ${{ secrets.token }}
# While `fetch-depth` is used to allow the workflow to later commit & push the changes.
fetch-depth: 0
- name: Setup NodeJS
uses: actions/setup-node@v3
with:
node-version: "18"
cache: "npm"
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
# if one of them changes the cache is invalidated/discarded
- name: Cache node modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: "./node_modules"
key: 18-cache-utils-node-modules-${{ hashFiles('./package-lock.json') }}
- name: Install dependencies
# We can skip the installation if there was a cache hit
if: steps.cache-node-modules.outputs.cache-hit != 'true'
# See https://github.com/npm/cli/issues/4475 to see why --foreground-scripts
run: npm ci --foreground-scripts
- name: Build packages
# If there's a cache hit we still need to manually build the packages
# this would otherwise have been done automatically as a part of the
# post-install npm hook
if: steps.cache-node-modules.outputs.cache-hit == 'true'
run: |
npm run build -w packages/commons
npm run build -w packages/logger & npm run build -w packages/tracer & npm run build -w packages/metrics
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Install doc generation dependencies
run: |
pip install --upgrade pip
pip install -r docs/requirements.txt
- name: Setup doc deploy
run: |
git config --global user.name Docs deploy
git config --global user.email [email protected]
- name: Git refresh tip (detached mode)
# Git Detached mode (release notes) doesn't have origin
if: ${{ inputs.detached_mode }}
run: |
git config pull.rebase true
git config remote.origin.url >&- || git remote add origin https://github.com/"$ORIGIN"
git pull origin "$BRANCH"
- name: Build docs website and API reference
run: |
make release-docs VERSION="$VERSION" ALIAS="$ALIAS"
poetry run mike set-default --push latest
- name: Build docs website and API reference
env:
VERSION: ${{ inputs.version }}
ALIAS: ${{ inputs.alias }}
run: |
rm -rf site
mkdocs build
mike deploy --push --update-aliases --no-redirect ${{ env.VERSION }} ${{ env.ALIAS }}"
# Set latest version as a default
mike set-default --push latest
- name: Release API docs
uses: peaceiris/actions-gh-pages@bd8c6b06eba6b3d25d72b7a1767993c0aeee42e7 # v3.9.2
env:
VERSION: ${{ inputs.version }}
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./api
keep_files: true
destination_dir: ${{ env.VERSION }}/api
- name: Release API docs to latest
if: ${{ input.alias == 'latest' }}
uses: peaceiris/actions-gh-pages@bd8c6b06eba6b3d25d72b7a1767993c0aeee42e7
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./api
keep_files: true
destination_dir: latest/api