From 3840e97da2d14856c64d7ea29bc5dafe6168a651 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Sun, 14 May 2023 10:23:44 +0300 Subject: [PATCH] Update openapi.json with Github Actions --- .github/workflows/api_docs.yml | 57 ++++++++++++++++++++++++++++++++++ docs.sh | 41 ++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 .github/workflows/api_docs.yml create mode 100755 docs.sh diff --git a/.github/workflows/api_docs.yml b/.github/workflows/api_docs.yml new file mode 100644 index 000000000..9dc4fa6c1 --- /dev/null +++ b/.github/workflows/api_docs.yml @@ -0,0 +1,57 @@ +name: 'API Docs' + +on: + workflow_dispatch: + schedule: + - cron: '0 0 * * 1' + push: + branches: + - develop + paths: + - ".github/workflows/api_docs.yml" + - "docs.sh" + - "src/Sonarr.Api.*/**" + - "src/**/*.csproj" + - "src/*" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + api_docs: + runs-on: ubuntu-latest + if: github.repository == 'Sonarr/Sonarr' + permissions: + contents: write + steps: + - uses: actions/checkout@v3 + + - name: Setup dotnet + uses: actions/setup-dotnet@v3 + id: setup-dotnet + with: + dotnet-version: '6.0.x' + + - name: Create temporary global.json + run: | + echo '{"sdk":{"version": "${{ steps.setup-dotnet.outputs.dotnet-version }}" } }' > ./global.json + + - name: Create openapi.json + run: ./docs.sh Linux + + - name: Commit API Docs Change + continue-on-error: true + run: | + git config --global user.email "development@sonarr.tv" + git config --global user.name "Sonarr" + git checkout -b api-docs + git add src + if git status | grep -q modified + then + git commit -am 'Automated API Docs update' + git push -f --set-upstream origin api-docs + curl -X POST -H "Authorization: Bearer ${{ secrets.OPENAPI_PAT }}" -H "Accept: application/vnd.github+json" https://api.github.com/repos/sonarr/sonarr/pulls -d '{"head":"api-docs","base":"develop","title":"Update API docs"}' + else + echo "No changes since last run" + fi diff --git a/docs.sh b/docs.sh new file mode 100755 index 000000000..685a4d6e0 --- /dev/null +++ b/docs.sh @@ -0,0 +1,41 @@ +#!/bin/bash +set -e + +PLATFORM=$1 + +if [ "$PLATFORM" = "Windows" ]; then + RUNTIME="win-x64" +elif [ "$PLATFORM" = "Linux" ]; then + RUNTIME="linux-x64" +elif [ "$PLATFORM" = "Mac" ]; then + RUNTIME="osx-x64" +else + echo "Platform must be provided as first argument: Windows, Linux or Mac" + exit 1 +fi + +outputFolder='_output' +testPackageFolder='_tests' + +rm -rf $outputFolder +rm -rf $testPackageFolder + +slnFile=src/Sonarr.sln + +platform=Posix + +dotnet clean $slnFile -c Debug +dotnet clean $slnFile -c Release + +dotnet msbuild -restore $slnFile -p:Configuration=Debug -p:Platform=$platform -p:RuntimeIdentifiers=$RUNTIME -t:PublishAllRids + +dotnet new tool-manifest +dotnet tool install --version 6.5.0 Swashbuckle.AspNetCore.Cli + +dotnet tool run swagger tofile --output ./src/Sonarr.Api.V3/openapi.json "$outputFolder/net6.0/$RUNTIME/Sonarr.dll" v3 & + +sleep 30 + +kill %1 + +exit 0