openapi.yml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. name: OpenAPI
  2. on:
  3. push:
  4. branches:
  5. - master
  6. pull_request_target:
  7. permissions: {}
  8. jobs:
  9. openapi-head:
  10. name: OpenAPI - HEAD
  11. runs-on: ubuntu-latest
  12. permissions: read-all
  13. steps:
  14. - name: Checkout repository
  15. uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  16. with:
  17. ref: ${{ github.event.pull_request.head.sha }}
  18. repository: ${{ github.event.pull_request.head.repo.full_name }}
  19. - name: Setup .NET
  20. uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0
  21. with:
  22. dotnet-version: '7.0.x'
  23. - name: Generate openapi.json
  24. run: dotnet test tests/Jellyfin.Server.Integration.Tests/Jellyfin.Server.Integration.Tests.csproj -c Release --filter "Jellyfin.Server.Integration.Tests.OpenApiSpecTests"
  25. - name: Upload openapi.json
  26. uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
  27. with:
  28. name: openapi-head
  29. retention-days: 14
  30. if-no-files-found: error
  31. path: tests/Jellyfin.Server.Integration.Tests/bin/Release/net7.0/openapi.json
  32. openapi-base:
  33. name: OpenAPI - BASE
  34. if: ${{ github.base_ref != '' }}
  35. runs-on: ubuntu-latest
  36. permissions: read-all
  37. steps:
  38. - name: Checkout repository
  39. uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  40. with:
  41. ref: ${{ github.event.pull_request.head.sha }}
  42. repository: ${{ github.event.pull_request.head.repo.full_name }}
  43. fetch-depth: 0
  44. - name: Checkout common ancestor
  45. env:
  46. HEAD_REF: ${{ github.head_ref }}
  47. run: |
  48. git remote add upstream https://github.com/${{ github.event.pull_request.base.repo.full_name }}
  49. git -c protocol.version=2 fetch --prune --progress --no-recurse-submodules upstream +refs/heads/*:refs/remotes/upstream/* +refs/tags/*:refs/tags/*
  50. ANCESTOR_REF=$(git merge-base upstream/${{ github.base_ref }} origin/$HEAD_REF)
  51. git checkout --progress --force $ANCESTOR_REF
  52. - name: Setup .NET
  53. uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0
  54. with:
  55. dotnet-version: '7.0.x'
  56. - name: Generate openapi.json
  57. run: dotnet test tests/Jellyfin.Server.Integration.Tests/Jellyfin.Server.Integration.Tests.csproj -c Release --filter "Jellyfin.Server.Integration.Tests.OpenApiSpecTests"
  58. - name: Upload openapi.json
  59. uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
  60. with:
  61. name: openapi-base
  62. retention-days: 14
  63. if-no-files-found: error
  64. path: tests/Jellyfin.Server.Integration.Tests/bin/Release/net7.0/openapi.json
  65. openapi-diff:
  66. permissions:
  67. pull-requests: write # to create or update comment (peter-evans/create-or-update-comment)
  68. name: OpenAPI - Difference
  69. if: ${{ github.event_name == 'pull_request_target' }}
  70. runs-on: ubuntu-latest
  71. needs:
  72. - openapi-head
  73. - openapi-base
  74. steps:
  75. - name: Download openapi-head
  76. uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
  77. with:
  78. name: openapi-head
  79. path: openapi-head
  80. - name: Download openapi-base
  81. uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
  82. with:
  83. name: openapi-base
  84. path: openapi-base
  85. - name: Workaround openapi-diff issue
  86. run: |
  87. sed -i 's/"allOf"/"oneOf"/g' openapi-head/openapi.json
  88. sed -i 's/"allOf"/"oneOf"/g' openapi-base/openapi.json
  89. - name: Calculate OpenAPI difference
  90. uses: docker://openapitools/openapi-diff
  91. continue-on-error: true
  92. with:
  93. args: --fail-on-changed --markdown openapi-changes.md openapi-base/openapi.json openapi-head/openapi.json
  94. - id: read-diff
  95. name: Read openapi-diff output
  96. run: |
  97. body=$(cat openapi-changes.md)
  98. body="${body//'%'/'%25'}"
  99. body="${body//$'\n'/'%0A'}"
  100. body="${body//$'\r'/'%0D'}"
  101. echo ::set-output name=body::$body
  102. - name: Find difference comment
  103. uses: peter-evans/find-comment@a54c31d7fa095754bfef525c0c8e5e5674c4b4b1 # v2.4.0
  104. id: find-comment
  105. with:
  106. issue-number: ${{ github.event.pull_request.number }}
  107. direction: last
  108. body-includes: openapi-diff-workflow-comment
  109. - name: Reply or edit difference comment (changed)
  110. uses: peter-evans/create-or-update-comment@23ff15729ef2fc348714a3bb66d2f655ca9066f2 # v3.1.0
  111. if: ${{ steps.read-diff.outputs.body != '' }}
  112. with:
  113. issue-number: ${{ github.event.pull_request.number }}
  114. comment-id: ${{ steps.find-comment.outputs.comment-id }}
  115. edit-mode: replace
  116. body: |
  117. <!--openapi-diff-workflow-comment-->
  118. <details>
  119. <summary>Changes in OpenAPI specification found. Expand to see details.</summary>
  120. ${{ steps.read-diff.outputs.body }}
  121. </details>
  122. - name: Edit difference comment (unchanged)
  123. uses: peter-evans/create-or-update-comment@23ff15729ef2fc348714a3bb66d2f655ca9066f2 # v3.1.0
  124. if: ${{ steps.read-diff.outputs.body == '' && steps.find-comment.outputs.comment-id != '' }}
  125. with:
  126. issue-number: ${{ github.event.pull_request.number }}
  127. comment-id: ${{ steps.find-comment.outputs.comment-id }}
  128. edit-mode: replace
  129. body: |
  130. <!--openapi-diff-workflow-comment-->
  131. No changes to OpenAPI specification found. See history of this comment for previous changes.