-
Notifications
You must be signed in to change notification settings - Fork 3
134 lines (131 loc) · 5.03 KB
/
api-docs-generator.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: PHP SDK Generator
env:
FETCH_CMD: 'wget https://znanylekarz.pl/openapi/integrations-api.yaml -d --header="X-OAS-INTEGRATIONS-TOKEN: ${{ secrets.OPENAPI_INTEGRATIONS_SPECIFICATION_TOKEN }}"'
FILE_NAME: integrations-api.yaml
CODEGEN_TEMPLATES_FOLDER: .github/workflows/swagger-codegen-templates
BRANCH: develop
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
push:
branches:
- develop
jobs:
diff:
name: Check for changes
runs-on: ubuntu-latest
outputs:
diff: ${{ steps.checksum.outputs.diff }}
steps:
- name: Fetch yaml specification file
run: ${{ env.FETCH_CMD }}
- name: Check cache
id: cache
uses: actions/cache@v4
with:
path: ${{ env.FILE_NAME }}
key: oas--${{ hashFiles(env.FILE_NAME) }}
- name: Stop process (no changes)
id: checksum
if: steps.cache.outputs.cache-hit == 'true'
run: echo "::set-output name=diff::true"
- name: Generate specification artifacts
if: steps.checksum.outputs.diff != 'true'
uses: actions/upload-artifact@v4
with:
name: specification
path: ${{ env.FILE_NAME }}
generate:
needs: diff
if: needs.diff.outputs.diff != 'true'
name: Generate SDK
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ env.BRANCH }}
- name: Download specification artifacts
uses: actions/download-artifact@v4
with:
name: specification
- name: Parse changelog
id: changelog
run: |
version="$(cat ${{ env.FILE_NAME }} | grep -Po '(?<=version:\s.)[a-zA-Z0-9.]*(?=.$)')"
commit="$(cat ${{ env.FILE_NAME }} | grep -Pzo "(?<=$version:\s>\n)[\s\S]*?[\r\n]{2}" | tr -s ' ')"
commit="${commit//'%'/'%25'}"
commit="${commit//$'\n'/'%0A'}"
commit="${commit//$'\r'/'%0D'}"
echo "::set-output name=version::$version"
echo "::set-output name=commit::$commit"
- name: Setup java
uses: actions/setup-java@v1
with:
java-version: '11'
- name: Download swagger codegen
run: wget https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.24/swagger-codegen-cli-3.0.24.jar -O swagger-codegen-cli.jar
- name: Generate SDK files
run: java -jar swagger-codegen-cli.jar generate --git-user-id=DocPlanner --git-repo-id integrations-api-sdk-php -DinvokerPackage=DocPlanner\\Client -i ${{ env.FILE_NAME }} -l php -o ./final/ -t ${{ env.CODEGEN_TEMPLATES_FOLDER }}
- name: Patch library files
run: cp -r final/SwaggerClient-php/docs/* docs/
- name: Patch docs files
run: cp -r final/SwaggerClient-php/lib/* lib/
- name: Commit files
id: commit
run: |
git config --local user.email "[email protected]"
git config --local user.name "github-actions"
git add lib/ docs/
if [ -z "$(git status -uno --porcelain)" ]; then
echo "::set-output name=push::false"
else
git commit -m "Release v${{ steps.changelog.outputs.version }}" -m "${{ steps.changelog.outputs.commit }}" -a
echo "::set-output name=push::true"
fi
shell: bash
- name: Push changes
if: steps.commit.outputs.push == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ env.BRANCH }}
- name: Create Release
if: steps.commit.outputs.push == 'true'
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.changelog.outputs.version }}
release_name: Release v${{ steps.changelog.outputs.version }}
body: ${{ steps.changelog.outputs.commit }}
draft: true
prerelease: false
- name: Delete artifacts
uses: geekyeggo/delete-artifact@v4
with:
name: specification
- name: Send Slack notification on success
if: ${{ success() }}
uses: rtCamp/action-slack-notify@v2
env:
SLACK_CHANNEL: integrations_notifications
SLACK_COLOR: '#36a64f'
SLACK_ICON: https://github.com/swagger-api.png
SLACK_MESSAGE: 'PHP SDK generated. Release URL: ${{ steps.create_release.outputs.html_url }}'
SLACK_TITLE: Success
SLACK_USERNAME: Github Actions
SLACK_WEBHOOK: ${{ secrets.INTEGRATIONS_SLACK_WEBHOOK }}
- name: Send Slack notification on failure
if: ${{ failure() }}
uses: rtCamp/action-slack-notify@v2
env:
SLACK_CHANNEL: integrations_notifications
SLACK_COLOR: '#cb2431'
SLACK_ICON: https://github.com/swagger-api.png
SLACK_MESSAGE: 'Failed to generate PHP SDK'
SLACK_TITLE: Failure
SLACK_USERNAME: Github Actions
SLACK_WEBHOOK: ${{ secrets.INTEGRATIONS_SLACK_WEBHOOK }}