-
Notifications
You must be signed in to change notification settings - Fork 1
153 lines (129 loc) · 5.4 KB
/
publish-techdocs-to-s3.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: Publish TechDocs Site
on:
push:
branches: [main]
paths:
- "docs/**"
- "mkdocs.yml"
- "**/*.md"
workflow_dispatch:
jobs:
check-for-catalog-info-at-root:
runs-on: ubuntu-latest
outputs:
template-present: ${{ steps.check-template.outputs.template-exists }}
catalog-present: ${{ steps.check-catalog.outputs.catalog-exists }}
mkdocs-present: ${{ steps.check-mkdocs.outputs.mkdocs-exists }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check if catalog exists
id: check-catalog
run: |
if [ -f "./catalog-info.yaml" ]; then
echo "catalog-exists=true" >> $GITHUB_OUTPUT
echo "catalog-exists=true"
else
echo "catalog-exists=false" >> $GITHUB_OUTPUT
fi
- name: Check if template exists
id: check-template
run: |
if [ -f "./template.yaml" ]; then
echo "template-exists=true" >> $GITHUB_OUTPUT
echo "template-exists=true"
else
echo "template-exists=false" >> $GITHUB_OUTPUT
fi
- name: Check if mkdocs exists
id: check-mkdocs
run: |
if [ -f "./mkdocs.yml" ] || [ -f "./mkdocs.yaml" ]; then
echo "mkdocs-exists=true" >> $GITHUB_OUTPUT
echo "mkdocs-exists=true"
else
echo "mkdocs-exists=false" >> $GITHUB_OUTPUT
fi
publish-docs-to-s3:
needs: check-for-catalog-info-at-root
if: ${{ needs.check-for-catalog-info-at-root.outputs.mkdocs-present == 'true' && (needs.check-for-catalog-info-at-root.outputs.catalog-present == 'true' || needs.check-for-catalog-info-at-root.outputs.template-present == 'true') }}
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache Node.js modules
uses: actions/cache@v4
with:
path: |
$(npm config get prefix)/lib/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-
- uses: actions/setup-node@v4
- name: Cache Python packages
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/*.txt', '**/*.pip') }}
restore-keys: |
${{ runner.os }}-pip-
- uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Install techdocs-cli
run: sudo npm install -g @techdocs/cli
- name: Install mkdocs and mkdocs plugins
run: python -m pip install mkdocs-techdocs-core==1.* neoteroi-mkdocs mkdocs-kroki-plugin pymdown-extensions
- name: Get namespace from catalog-info.yaml
if: ${{ needs.check-for-catalog-info-at-root.outputs.catalog-present == 'true' }}
id: get_namespace_catalog
uses: mikefarah/yq@master
with:
cmd: yq '.metadata.namespace // "default"' catalog-info.yaml
- name: Get name from catalog-info.yaml
if: ${{ needs.check-for-catalog-info-at-root.outputs.catalog-present == 'true' }}
id: get_name_catalog
uses: mikefarah/yq@master
with:
cmd: yq '.metadata.name' catalog-info.yaml
- name: Get kind from catalog-info.yaml
if: ${{ needs.check-for-catalog-info-at-root.outputs.catalog-present == 'true' }}
id: get_kind_catalog
uses: mikefarah/yq@master
with:
cmd: yq '.kind' catalog-info.yaml
- name: Get namespace from template.yaml
if: ${{ needs.check-for-catalog-info-at-root.outputs.template-present == 'true' }}
id: get_namespace_template
uses: mikefarah/yq@master
with:
cmd: yq '.metadata.namespace // "default"' template.yaml
- name: Get name from template.yaml
if: ${{ needs.check-for-catalog-info-at-root.outputs.template-present == 'true' }}
id: get_name_template
uses: mikefarah/yq@master
with:
cmd: yq '.metadata.name' template.yaml
- name: Get kind from template.yaml
if: ${{ needs.check-for-catalog-info-at-root.outputs.template-present == 'true' }}
id: get_kind_template
uses: mikefarah/yq@master
with:
cmd: yq '.kind' template.yaml
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-east-1
role-session-name: publish-docs
role-to-assume: arn:aws:iam::905418481873:role/Github_OIDC_TechDocs_S3
- name: Generate docs site
run: techdocs-cli generate --no-docker --verbose
- name: Publish docs site
if: ${{ needs.check-for-catalog-info-at-root.outputs.catalog-present == 'true' }}
run: techdocs-cli publish --publisher-type awsS3 --storage-name backstage-liatrio-techdocs --entity ${{ steps.get_namespace_catalog.outputs.result }}/${{ steps.get_kind_catalog.outputs.result }}/${{ steps.get_name_catalog.outputs.result }}
- name: Publish docs site
if: ${{ needs.check-for-catalog-info-at-root.outputs.template-present == 'true' }}
run: techdocs-cli publish --publisher-type awsS3 --storage-name backstage-liatrio-techdocs --entity ${{ steps.get_namespace_template.outputs.result }}/${{ steps.get_kind_template.outputs.result }}/${{ steps.get_name_template.outputs.result }}