-
Notifications
You must be signed in to change notification settings - Fork 7
164 lines (140 loc) · 5.59 KB
/
docs-as-code-cron.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
154
155
156
157
158
159
160
161
162
163
164
name: Publish Portal Content (Cron)
on:
schedule:
- cron: '0 10 * * *'
workflow_dispatch:
inputs:
log_level:
description: 'Log level: 1=DEBUG, 2=INFO, 3=WARNING, 4=ERROR'
required: false
default: '2' # Set the default log level to INFO
skip_api_linting:
description: 'Skip the API linting job'
required: false
default: 'false'
env:
SWAGGERHUB_API_KEY: ${{ secrets.SWAGGERHUB_API_KEY }}
LOG_LEVEL: ${{ github.event.inputs.log_level }}
jobs:
spell-check:
runs-on: ubuntu-latest
environment: Production
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
- name: Install cspell
run: npm install -g cspell
- name: Run cspell
run: cspell --config ./.cspell.json "./products/**/*.md"
validate-manifests:
runs-on: ubuntu-latest
environment: Production
needs: spell-check
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
- name: Install AJV CLI
run: npm install -g ajv-cli
- name: Validate manifests
run: |
# source the utility script
. ./scripts/utilities.sh
for product in ./products/*; do
if [[ -d "$product" ]]; then
product_name=${product#./products/}
manifest="./products/$product_name/manifest.json"
if [[ -f "$manifest" ]]; then
# Further actions...
log_message $INFO "Validating manifest in product: $product_name"
log_message $DEBUG "Validating manifest: $manifest"
ajv validate -s ./schemas/manifest.schema.json -d "$manifest" --spec=draft2020
fi
fi
done
lint-api:
runs-on: ubuntu-latest
if: github.event.inputs.skip_api_linting != 'true'
environment: Production
needs: validate-manifests
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install SwaggerHub CLI
run: npm install -g swaggerhub-cli
- name: Iterate over product folders and validate APIs
shell: bash
run: |
# source the utility script
. ./scripts/utilities.sh
for product in ./products/*; do
log_message $DEBUG "Product: $product"
if [[ -d "$product" ]]; then
log_message $DEBUG "Product is a directory"
product_name=${product#./products/}
log_message $DEBUG "Product name: $product_name"
manifest="./products/$product_name/manifest.json"
log_message $DEBUG "Manifest: $manifest"
if [[ -f "$manifest" ]]; then
log_message $DEBUG "Manifest is a file"
validateAPIs=$(jq -r '.productMetadata.validateAPIs' "$manifest")
if [[ "$validateAPIs" == "true" ]]; then
log_message $INFO "Validating APIs for product: $product_name"
contentMetadata=$(jq -c '.contentMetadata[] | select(.type | ascii_downcase == "apiurl")' "$manifest")
echo "$contentMetadata" | jq -c '.' | while IFS= read -r contentMetadataItem; do
slug=$(echo "$contentMetadataItem" | jq -r '.slug')
log_message $INFO "Validating API: $slug"
swaggerhub api:validate "${SWAGGERHUB_ORG_NAME}/$slug" --fail-on-critical
done
else
log_message $WARNING "API validation is not enabled for product: $product_name"
fi
else
log_message $ERROR "Manifest is not a file"
fi
else
log_message $ERROR "Product is not a directory"
fi
done
env:
SWAGGERHUB_API_KEY: ${{ secrets.SWAGGERHUB_API_KEY }}
SWAGGERHUB_ORG_NAME: ${{ vars.SWAGGERHUB_ORG_NAME }}
publish:
runs-on: ubuntu-latest
environment: Production
needs: [spell-check, lint-api]
if: github.event.inputs.skip_api_linting == 'true' || (needs.spell-check.result == 'success' && needs['lint-api'].result == 'success')
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Iterate over product folders
shell: bash
run: |
for product in ./products/*; do
echo "Product: $product"
if [[ -d "$product" ]]; then
echo "Product is a directory"
product_name=${product#./products/}
echo "Product name: $product_name"
manifest="./products/$product_name/manifest.json"
echo "Manifest: $manifest"
if [[ -f "$manifest" ]]; then
echo "Manifest is a file"
. ./scripts/publish-portal-content.sh && portal_product_upsert "$manifest" "$product_name"
. ./scripts/publish-portal-content.sh && load_and_process_product_manifest_content_metadata "$manifest" "$product_name"
else
echo "Manifest is not a file"
fi
else
echo "Product is not a directory"
fi
done
env:
SWAGGERHUB_PORTAL_SUBDOMAIN: ${{ vars.SWAGGERHUB_PORTAL_SUBDOMAIN }}