From 767439eeb461fe627edb53923de8552d1bd025e2 Mon Sep 17 00:00:00 2001 From: Juan Agudelo Date: Thu, 5 Sep 2024 20:51:21 -0500 Subject: [PATCH] Create github action to generate openapi and md file. Modify build.ps1 to include steps to build and generate openapi and md file --- .github/workflows/openapi-md.yml | 69 ++++++++++++++++++++++++++++++++ build.ps1 | 45 ++++++++++++++++++++- 2 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/openapi-md.yml diff --git a/.github/workflows/openapi-md.yml b/.github/workflows/openapi-md.yml new file mode 100644 index 00000000..791b2aa5 --- /dev/null +++ b/.github/workflows/openapi-md.yml @@ -0,0 +1,69 @@ +# SPDX-License-Identifier: Apache-2.0 +# Licensed to the Ed-Fi Alliance under one or more agreements. +# The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. +# See the LICENSE and NOTICES files in the project root for more information. + +name: Create PR to update doc and openapi definition + +on: + workflow_dispatch: + inputs: + version: + description: 'API Version [format 0.0.0]' + required: true + type: string +permissions: write-all + +env: + CI_COMMIT_MESSAGE: Continuous Integration Build Artifacts + CI_COMMIT_AUTHOR: github-actions[bot] + CI_COMMIT_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com + +jobs: + create-doc-and-openapiyaml: + name: Build C# + runs-on: ubuntu-latest + defaults: + run: + shell: pwsh + steps: + - name: Checkout the Repo + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Git create branch + run: git checkout -b openapi-${{ inputs.version }} + + - name: Install Swashbuckle CLI + run: dotnet tool install Swashbuckle.AspNetCore.Cli --version 6.5.0 --create-manifest-if-needed + + - name: Install widdershins CLI + run: npm install -g widdershins + + - name: Set issuer and signingkey + run: ./build.ps1 -Command Build -Configuration Debug + + - name: Build + run: | + $p = @{ + Authority = "http://api" + IssuerUrl = "https://localhost" + DatabaseEngine = "PostgreSql" + PathBase = "adminapi" + SigningKey = "test" + AdminDB = "host=db-admin;port=5432;username=username;password=password;database=EdFi_Admin;Application Name=EdFi.Ods.AdminApi;" + SecurityDB = "host=db-admin;port=5432;username=username;password=password;database=EdFi_Security;Application Name=EdFi.Ods.AdminApi;" + } + ./build.ps1 -APIVersion ${{ inputs.version }} -Configuration Release -DockerEnvValues $p -Command GenerateOpenAPIAndMD + + - name: GIT commit and push + run: | + git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}" + git config --global user.email "${{ env.CI_COMMIT_EMAIL }}" + git add . + git commit -m "${{ env.CI_COMMIT_MESSAGE }}" + git push --set-upstream origin openapi-${{ inputs.version }} + + - name: Create pull request + run: gh pr create -B main -H test1 --title 'Merge test1 into main' --body 'Created by Github action' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/build.ps1 b/build.ps1 index bd548018..d68ebaba 100644 --- a/build.ps1 +++ b/build.ps1 @@ -63,7 +63,7 @@ param( # Command to execute, defaults to "Build". [string] - [ValidateSet("Clean", "Build", "BuildAndPublish", "UnitTest", "IntegrationTest", "PackageApi" + [ValidateSet("Clean", "Build", "GenerateOpenAPIAndMD", "BuildAndPublish", "UnitTest", "IntegrationTest", "PackageApi" , "Push", "BuildAndTest", "BuildAndDeployToAdminApiDockerContainer" , "BuildAndRunAdminApiDevDocker", "RunAdminApiDevDockerContainer", "RunAdminApiDevDockerCompose", "Run", "CopyToDockerContext", "RemoveDockerContextFiles")] $Command = "Build", @@ -166,6 +166,24 @@ function Compile { } } +function GenerateOpenAPI { + Invoke-Execute { + cd $solutionRoot/EdFi.Ods.AdminApi/ + $outputOpenAPI = "../../docs/api-specifications/openapi-yaml/admin-api-$APIVersion.yaml" + $dllPath = "./bin/Release/net8.0/EdFi.Ods.AdminApi.dll" + dotnet tool run swagger tofile --output $outputOpenAPI --yaml $dllPath v2 + cd ..\.. + } +} + +function GenerateDocumentation { + Invoke-Execute { + $outputOpenAPI = "docs/api-specifications/openapi-yaml/admin-api-$APIVersion.yaml" + $outputMD = "docs/api-specifications/markdown/admin-api-$APIVersion-summary.md" + widdershins --search false --omitHeader true --code true --summary $outputOpenAPI -o $outputMD + } +} + function PublishAdminApi { Invoke-Execute { $project = "$solutionRoot/EdFi.Ods.AdminApi/" @@ -294,6 +312,15 @@ function Invoke-Build { Invoke-Step { Compile } } +function Invoke-GenerateOpenAPIAndMD { + Invoke-Step { UpdateAppSettingsForAdminApi } + Invoke-Step { DotNetClean } + Invoke-Step { Restore } + Invoke-Step { Compile } + Invoke-Step { GenerateOpenAPI } + Invoke-Step { GenerateDocumentation } +} + function Invoke-SetAssemblyInfo { Write-Output "Setting Assembly Information" @@ -375,6 +402,21 @@ function UpdateAppSettingsForAdminApiDocker { $json | ConvertTo-Json -Depth 10 | Set-Content $filePath } +function UpdateAppSettingsForAdminApi { + $filePath = "$solutionRoot/EdFi.Ods.AdminApi/appsettings.json" + $json = (Get-Content -Path $filePath) | ConvertFrom-Json + $json.AppSettings.DatabaseEngine = $DockerEnvValues["DatabaseEngine"] + $json.AppSettings.PathBase = $DockerEnvValues["PathBase"] + + $json.Authentication.IssuerUrl = $DockerEnvValues["IssuerUrl"] + $json.Authentication.SigningKey = $DockerEnvValues["SigningKey"] + + $json.ConnectionStrings.EdFi_Admin = $DockerEnvValues["AdminDB"] + $json.ConnectionStrings.EdFi_Security = $DockerEnvValues["SecurityDB"] + $json.Log4NetCore.Log4NetConfigFileName = "log4net\log4net.config" + $json | ConvertTo-Json -Depth 10 | Set-Content $filePath +} + function CopyLatestFilesToAdminApiContainer { $source = "$solutionRoot/EdFi.Ods.AdminApi/bin/Release/net8.0/." &docker cp $source adminapi:/app/AdminApi @@ -470,6 +512,7 @@ Invoke-Main { switch ($Command) { Clean { Invoke-Clean } Build { Invoke-Build } + GenerateOpenAPIAndMD { Invoke-GenerateOpenAPIAndMD } BuildAndPublish { Invoke-SetAssemblyInfo Invoke-Build