-
Notifications
You must be signed in to change notification settings - Fork 153
102 lines (100 loc) · 3.75 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
name: Publish docs
on:
workflow_call:
inputs:
workflow_origin: # see https://github.com/awslabs/aws-lambda-powertools-python/issues/1349
required: true
type: string
prIsMerged:
required: false
default: "false"
type: string
isRelease:
required: false
default: "false"
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: "16"
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: 16-cache-utils-node-modules-${{ hashFiles('./package-lock.json') }}
# Here we assume that there will always be a cache hit because this workflow can be triggered
# only after tests have already happened on this same code
- name: Build packages
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"
# We run this step only when the workflow has been triggered by a release
# in this case we publish the docs to `/latest`
- name: Set RELEASE_VERSION env var to `latest`
if: ${{ inputs.isRelease == 'true' }}
run: |
RELEASE_VERSION=$(cat packages/commons/package.json | jq '.version' -r)
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV
# We run this step only when the workflow has been triggered by a PR merge
# in this case we publish the docs to `/dev`
- name: Set RELEASE_VERSION env var to `dev`
if: ${{ inputs.prIsMerged == 'true' }}
run: |
echo "RELEASE_VERSION=dev" >> $GITHUB_ENV
- 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: Publish docs to latest
if: ${{ env.RELEASE_VERSION != 'dev' }}
run: |
rm -rf site
mkdocs build
mike deploy --push --update-aliases --no-redirect "${{ env.RELEASE_VERSION }}" "latest"
# Set latest version as a default
mike set-default --push latest
- name: Publish docs to dev
if: ${{ env.RELEASE_VERSION == 'dev' }}
run: |
rm -rf site
mkdocs build
mike deploy --push dev
- name: Build API docs
run: |
rm -rf api
npm run docs-generateApiDoc
- name: Release API docs
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./api
keep_files: true
destination_dir: ${{ env.RELEASE_VERSION }}/api