Skip to content

PHP SDK Generator

PHP SDK Generator #914

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 }}