jellyfin/.github/workflows/openapi.yml

140 lines
5.6 KiB
YAML
Raw Normal View History

2021-07-12 08:06:13 +00:00
name: OpenAPI
on:
push:
branches:
- master
pull_request_target:
2021-07-12 08:06:13 +00:00
permissions: {}
2021-07-12 08:06:13 +00:00
jobs:
openapi-head:
name: OpenAPI - HEAD
runs-on: ubuntu-latest
permissions: read-all
2021-07-12 08:06:13 +00:00
steps:
- name: Checkout repository
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
with:
ref: ${{ github.event.pull_request.head.sha }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
2022-11-09 14:28:52 +00:00
- name: Setup .NET
uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0
2021-07-12 08:06:13 +00:00
with:
2022-11-09 14:28:52 +00:00
dotnet-version: '7.0.x'
2021-07-12 08:06:13 +00:00
- name: Generate openapi.json
2021-09-15 17:32:55 +00:00
run: dotnet test tests/Jellyfin.Server.Integration.Tests/Jellyfin.Server.Integration.Tests.csproj -c Release --filter "Jellyfin.Server.Integration.Tests.OpenApiSpecTests"
2021-07-12 08:06:13 +00:00
- name: Upload openapi.json
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
2021-07-12 08:06:13 +00:00
with:
name: openapi-head
retention-days: 14
if-no-files-found: error
2022-11-09 14:28:52 +00:00
path: tests/Jellyfin.Server.Integration.Tests/bin/Release/net7.0/openapi.json
2021-07-12 08:06:13 +00:00
openapi-base:
name: OpenAPI - BASE
if: ${{ github.base_ref != '' }}
runs-on: ubuntu-latest
permissions: read-all
2021-07-12 08:06:13 +00:00
steps:
- name: Checkout repository
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
2021-07-12 08:06:13 +00:00
with:
ref: ${{ github.event.pull_request.head.sha }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
- name: Checkout common ancestor
2023-06-19 13:56:15 +00:00
env:
HEAD_REF: ${{ github.head_ref }}
run: |
git remote add upstream https://github.com/${{ github.event.pull_request.base.repo.full_name }}
git -c protocol.version=2 fetch --prune --progress --no-recurse-submodules upstream +refs/heads/*:refs/remotes/upstream/* +refs/tags/*:refs/tags/*
ANCESTOR_REF=$(git merge-base upstream/${{ github.base_ref }} origin/$HEAD_REF)
git checkout --progress --force $ANCESTOR_REF
2022-11-09 14:28:52 +00:00
- name: Setup .NET
uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0
2021-07-12 08:06:13 +00:00
with:
2022-11-09 14:28:52 +00:00
dotnet-version: '7.0.x'
2021-07-12 08:06:13 +00:00
- name: Generate openapi.json
2021-09-15 17:32:55 +00:00
run: dotnet test tests/Jellyfin.Server.Integration.Tests/Jellyfin.Server.Integration.Tests.csproj -c Release --filter "Jellyfin.Server.Integration.Tests.OpenApiSpecTests"
2021-07-12 08:06:13 +00:00
- name: Upload openapi.json
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
2021-07-12 08:06:13 +00:00
with:
name: openapi-base
retention-days: 14
if-no-files-found: error
2022-11-09 14:28:52 +00:00
path: tests/Jellyfin.Server.Integration.Tests/bin/Release/net7.0/openapi.json
2021-07-12 08:06:13 +00:00
openapi-diff:
permissions:
pull-requests: write # to create or update comment (peter-evans/create-or-update-comment)
2021-07-12 08:06:13 +00:00
name: OpenAPI - Difference
if: ${{ github.event_name == 'pull_request_target' }}
2021-07-12 08:06:13 +00:00
runs-on: ubuntu-latest
needs:
- openapi-head
- openapi-base
steps:
- name: Download openapi-head
2023-03-16 04:57:01 +00:00
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
2021-07-12 08:06:13 +00:00
with:
name: openapi-head
path: openapi-head
- name: Download openapi-base
2023-03-16 04:57:01 +00:00
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
2021-07-12 08:06:13 +00:00
with:
name: openapi-base
path: openapi-base
- name: Workaround openapi-diff issue
run: |
sed -i 's/"allOf"/"oneOf"/g' openapi-head/openapi.json
sed -i 's/"allOf"/"oneOf"/g' openapi-base/openapi.json
- name: Calculate OpenAPI difference
uses: docker://openapitools/openapi-diff
continue-on-error: true
with:
args: --fail-on-changed --markdown openapi-changes.md openapi-base/openapi.json openapi-head/openapi.json
- id: read-diff
name: Read openapi-diff output
run: |
body=$(cat openapi-changes.md)
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo ::set-output name=body::$body
- name: Find difference comment
uses: peter-evans/find-comment@a54c31d7fa095754bfef525c0c8e5e5674c4b4b1 # v2.4.0
2021-07-12 08:06:13 +00:00
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
direction: last
body-includes: openapi-diff-workflow-comment
- name: Reply or edit difference comment (changed)
uses: peter-evans/create-or-update-comment@c6c9a1a66007646a28c153e2a8580a5bad27bcfa # v3.0.2
2021-07-12 08:06:13 +00:00
if: ${{ steps.read-diff.outputs.body != '' }}
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body: |
<!--openapi-diff-workflow-comment-->
<details>
<summary>Changes in OpenAPI specification found. Expand to see details.</summary>
${{ steps.read-diff.outputs.body }}
</details>
- name: Edit difference comment (unchanged)
uses: peter-evans/create-or-update-comment@c6c9a1a66007646a28c153e2a8580a5bad27bcfa # v3.0.2
2021-07-12 08:06:13 +00:00
if: ${{ steps.read-diff.outputs.body == '' && steps.find-comment.outputs.comment-id != '' }}
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body: |
<!--openapi-diff-workflow-comment-->
No changes to OpenAPI specification found. See history of this comment for previous changes.