Skip to content

Commit 8a9183d

Browse files
committed
phplist-api-client swagger push ci
1 parent dc9d5e4 commit 8a9183d

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

.github/workflows/client-docs.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Update phplist-api-client OpenAPI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
generate-openapi:
11+
runs-on: ubuntu-22.04
12+
steps:
13+
- name: Checkout Source 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 OpenAPI Artifact
37+
uses: actions/upload-artifact@v4
38+
with:
39+
name: openapi-json
40+
path: docs/latest-restapi.json
41+
42+
update-phplist-api-client:
43+
runs-on: ubuntu-22.04
44+
needs: generate-openapi
45+
steps:
46+
- name: Checkout phplist-api-client Repository
47+
uses: actions/checkout@v3
48+
with:
49+
repository: TatevikGr/phplist-api-client
50+
token: ${{ secrets.PUSH_API_CLIENT }}
51+
fetch-depth: 0
52+
53+
- name: Download Generated OpenAPI JSON
54+
uses: actions/download-artifact@v4
55+
with:
56+
name: openapi-json
57+
path: ./new-openapi
58+
59+
- name: Compare and Check for Differences
60+
id: diff
61+
run: |
62+
# Compare the openapi files if old exists, else always deploy
63+
if [ -f openapi.json ]; then
64+
diff openapi.json new-openapi/latest-restapi.json > openapi-diff.txt || true
65+
if [ -s openapi-diff.txt ]; then
66+
echo "diff=true" >> $GITHUB_OUTPUT
67+
else
68+
echo "diff=false" >> $GITHUB_OUTPUT
69+
fi
70+
else
71+
echo "No previous openapi.json, will add."
72+
echo "diff=true" >> $GITHUB_OUTPUT
73+
fi
74+
75+
- name: Update and Commit OpenAPI File
76+
if: steps.diff.outputs.diff == 'true'
77+
run: |
78+
cp new-openapi/latest-restapi.json openapi.json
79+
git config user.name "github-actions"
80+
git config user.email "[email protected]"
81+
git add openapi.json
82+
git commit -m "Update openapi.json from REST API workflow `date`"
83+
git push
84+
85+
- name: Skip Commit if No Changes
86+
if: steps.diff.outputs.diff == 'false'
87+
run: echo "No changes to openapi.json, skipping commit."

0 commit comments

Comments
 (0)