|
| 1 | +name: PHP SDK Generator |
| 2 | + |
| 3 | +env: |
| 4 | + FETCH_CMD: 'wget https://znanylekarz.pl/openapi/integrations-api.yaml -d --header="X-OAS-INTEGRATIONS-TOKEN: ${{ secrets.OPENAPI_INTEGRATIONS_SPECIFICATION_TOKEN }}"' |
| 5 | + FILE_NAME: integrations-api.yaml |
| 6 | + BRANCH: develop |
| 7 | + |
| 8 | +on: |
| 9 | + schedule: |
| 10 | + - cron: '0 0 * * *' |
| 11 | + workflow_dispatch: |
| 12 | + push: |
| 13 | + branches: |
| 14 | + - develop |
| 15 | + |
| 16 | +jobs: |
| 17 | + diff: |
| 18 | + name: Check for changes |
| 19 | + runs-on: ubuntu-latest |
| 20 | + outputs: |
| 21 | + diff: ${{ steps.checksum.outputs.diff }} |
| 22 | + steps: |
| 23 | + - name: Fetch yaml specification file |
| 24 | + run: ${{ env.FETCH_CMD }} |
| 25 | + - name: Check cache |
| 26 | + id: cache |
| 27 | + uses: actions/cache@v2 |
| 28 | + with: |
| 29 | + path: ${{ env.FILE_NAME }} |
| 30 | + key: oas--${{ hashFiles(env.FILE_NAME) }} |
| 31 | + - name: Stop process (no changes) |
| 32 | + id: checksum |
| 33 | + if: steps.cache.outputs.cache-hit == 'true' |
| 34 | + run: echo "::set-output name=diff::true" |
| 35 | + - name: Generate specification artifacts |
| 36 | + if: steps.checksum.outputs.diff != 'false' |
| 37 | + uses: actions/upload-artifact@v2 |
| 38 | + with: |
| 39 | + name: specification |
| 40 | + path: ${{ env.FILE_NAME }} |
| 41 | + generate: |
| 42 | + needs: diff |
| 43 | + if: needs.diff.outputs.diff != 'false' |
| 44 | + name: Generate SDK |
| 45 | + runs-on: ubuntu-latest |
| 46 | + steps: |
| 47 | + - name: Checkout repository |
| 48 | + uses: actions/checkout@v2 |
| 49 | + with: |
| 50 | + ref: ${{ env.BRANCH }} |
| 51 | + - name: Download specification artifacts |
| 52 | + uses: actions/download-artifact@v2 |
| 53 | + with: |
| 54 | + name: specification |
| 55 | + - name: Setup java |
| 56 | + uses: actions/setup-java@v1 |
| 57 | + with: |
| 58 | + java-version: '11' |
| 59 | + - name: Download swagger codegen |
| 60 | + 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 |
| 61 | + - name: Generate SDK files |
| 62 | + 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/ |
| 63 | + - name: Patch library files |
| 64 | + run: cp -r final/SwaggerClient-php/docs/* docs/ |
| 65 | + - name: Patch docs files |
| 66 | + run: cp -r final/SwaggerClient-php/lib/* lib/ |
| 67 | + - name: Commit files |
| 68 | + id: commit |
| 69 | + run: | |
| 70 | + git config --local user.email "[email protected]" |
| 71 | + git config --local user.name "github-actions" |
| 72 | + git add lib/ docs/ |
| 73 | + if [ -z "$(git status -uno --porcelain)" ]; then |
| 74 | + echo "::set-output name=push::false" |
| 75 | + else |
| 76 | + git commit -m "Generate SDK" -a |
| 77 | + echo "::set-output name=push::true" |
| 78 | + fi |
| 79 | + shell: bash |
| 80 | + - name: Push changes |
| 81 | + if: steps.commit.outputs.push == 'true' |
| 82 | + uses: ad-m/github-push-action@master |
| 83 | + with: |
| 84 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 85 | + branch: ${{ env.BRANCH }} |
| 86 | + - name: Create Release |
| 87 | + id: create_release |
| 88 | + uses: actions/create-release@v1 |
| 89 | + env: |
| 90 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 91 | + with: |
| 92 | + tag_name: v1.0.${{ github.run_number }} |
| 93 | + release_name: Release v1.0.${{ github.run_number }} |
| 94 | + body: | |
| 95 | + Generated automatically |
| 96 | + draft: true |
| 97 | + prerelease: false |
| 98 | + - name: Delete artifacts |
| 99 | + uses: geekyeggo/delete-artifact@v1 |
| 100 | + with: |
| 101 | + name: specification |
| 102 | + - name: Send Slack notification on success |
| 103 | + if: ${{ success() }} |
| 104 | + uses: rtCamp/action-slack-notify@v2 |
| 105 | + env: |
| 106 | + SLACK_CHANNEL: integrations_notifications |
| 107 | + SLACK_COLOR: '#36a64f' |
| 108 | + SLACK_ICON: https://github.com/swagger-api.png |
| 109 | + SLACK_MESSAGE: 'PHP SDK generated. Release URL: ${{ steps.create_release.outputs.html_url }}' |
| 110 | + SLACK_TITLE: Success |
| 111 | + SLACK_USERNAME: Github Actions |
| 112 | + SLACK_WEBHOOK: ${{ secrets.INTEGRATIONS_SLACK_WEBHOOK }} |
| 113 | + - name: Send Slack notification on failure |
| 114 | + if: ${{ failure() }} |
| 115 | + uses: rtCamp/action-slack-notify@v2 |
| 116 | + env: |
| 117 | + SLACK_CHANNEL: integrations_notifications |
| 118 | + SLACK_COLOR: '#cb2431' |
| 119 | + SLACK_ICON: https://github.com/swagger-api.png |
| 120 | + SLACK_MESSAGE: 'Failed to generate PHP SDK' |
| 121 | + SLACK_TITLE: Failure |
| 122 | + SLACK_USERNAME: Github Actions |
| 123 | + SLACK_WEBHOOK: ${{ secrets.INTEGRATIONS_SLACK_WEBHOOK }} |
0 commit comments