-
Notifications
You must be signed in to change notification settings - Fork 154
134 lines (132 loc) · 5.12 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: Reusable 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
versionNumber:
required: false
default: ""
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"
# We run this step only when the workflow has been triggered by a release
# in this case we publish the docs to `/latest`
- name: (Conditional) Set RELEASE_VERSION env var to `latest`
if: ${{ inputs.isRelease == 'true' }}
run: |
RELEASE_VERSION=$(echo ${{ github.ref_name }} | sed 's/v//')
EXPLICIT_RELEASE_VERSION=$(echo ${{ inputs.versionNumber }} | sed 's/v//')
if [ $EXPLICIT_RELEASE_VERSION != "" ]; then
echo "RELEASE_VERSION=${EXPLICIT_RELEASE_VERSION}"
echo "RELEASE_VERSION=${EXPLICIT_RELEASE_VERSION}" >> $GITHUB_ENV
else
echo "RELEASE_VERSION=${RELEASE_VERSION}"
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV
fi
# 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: (Conditional) Set RELEASE_VERSION env var to `dev`
if: ${{ inputs.prIsMerged == 'true' }}
run: |
echo "RELEASE_VERSION=dev" >> $GITHUB_ENV
- name: Check RELEASE_VERSION env var
if: ${{ env.RELEASE_VERSION == '' }}
uses: actions/github-script@v3
with:
script: |
core.setFailed('RELEASE_VERSION env var is empty.')
- 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 isRelease
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
- name: Release API docs to latest if isRelease
if: ${{ env.RELEASE_VERSION != 'dev' }}
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./api
keep_files: true
destination_dir: latest/api