Skip to content

Commit 5b5a887

Browse files
committed
ISSUE-344: add docs workflow
1 parent bf669e5 commit 5b5a887

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

.github/workflows/restapi-docs.yml

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Publish REST API Docs
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
8+
jobs:
9+
make-restapi-docs:
10+
name: Checkout phpList rest-api and generate docs specification (OpenAPI latest-restapi.json)
11+
runs-on: ubuntu-20.04
12+
steps:
13+
- name: Checkout Repository
14+
uses: actions/checkout@v3
15+
16+
- name: Setup PHP with Composer and Extensions
17+
uses: shivammathur/setup-php@v2
18+
with:
19+
php-version: 8.1
20+
extensions: mbstring, dom, fileinfo, mysql
21+
22+
- name: Cache Composer Dependencies
23+
uses: actions/cache@v3
24+
with:
25+
path: ~/.composer/cache
26+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
27+
restore-keys: |
28+
${{ runner.os }}-composer-
29+
30+
- name: Install Composer Dependencies
31+
run: composer install --no-interaction --prefer-dist
32+
33+
- name: Generate OpenAPI Specification JSON
34+
run: vendor/bin/openapi -o docs/latest-restapi.json --format json src
35+
36+
- name: Upload REST API Specification
37+
uses: actions/upload-artifact@v3
38+
with:
39+
name: restapi-json
40+
path: docs/latest-restapi.json
41+
42+
deploy-docs:
43+
name: Deploy REST API Specification
44+
runs-on: ubuntu-20.04
45+
needs: make-restapi-docs
46+
steps:
47+
- name: Setup Node.js
48+
uses: actions/setup-node@v3
49+
with:
50+
node-version: 14
51+
52+
- name: Install openapi-checker
53+
run: npm install -g swagger-cli
54+
55+
- name: Checkout REST API Docs Repository
56+
uses: actions/checkout@v3
57+
with:
58+
repository: phpList/restapi-docs
59+
fetch-depth: 0
60+
token: ${{ secrets.PUSH_REST_API_DOCS }}
61+
62+
- name: Download Generated REST API Specification
63+
uses: actions/download-artifact@v3
64+
with:
65+
name: restapi-json
66+
path: docs
67+
68+
- name: Validate OpenAPI Specification
69+
run: swagger-cli validate docs/latest-restapi.json
70+
71+
- name: Compare Specifications
72+
run: git diff --no-index --output=restapi-diff.txt docs/latest-restapi.json restapi.json || true
73+
74+
- name: Check Differences and Decide Deployment
75+
id: allow-deploy
76+
run: |
77+
if [ -s restapi-diff.txt ]; then
78+
echo "Updates detected in the REST API specification. Proceeding with deployment.";
79+
echo 'DEPLOY=true' >> $GITHUB_ENV;
80+
else
81+
echo "No changes detected in the REST API specification. Skipping deployment.";
82+
echo 'DEPLOY=false' >> $GITHUB_ENV;
83+
fi
84+
85+
- name: Commit and Deploy Updates
86+
if: env.DEPLOY == 'true'
87+
run: |
88+
mv docs/latest-restapi.json docs/restapi.json
89+
git config user.name "github-actions"
90+
git config user.email "[email protected]"
91+
git add docs/restapi.json
92+
git commit -m "Update REST API documentation `date`"
93+
git push

0 commit comments

Comments
 (0)