Skip to content

Commit

Permalink
Create github action to generate openapi and md file. Modify build.ps…
Browse files Browse the repository at this point in the history
…1 to include steps to build and generate openapi and md file
  • Loading branch information
jagudelo-gap committed Sep 6, 2024
1 parent 7c8f6a2 commit 767439e
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 1 deletion.
69 changes: 69 additions & 0 deletions .github/workflows/openapi-md.yml
Original file line number Diff line number Diff line change
@@ -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 }}
45 changes: 44 additions & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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/"
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -470,6 +512,7 @@ Invoke-Main {
switch ($Command) {
Clean { Invoke-Clean }
Build { Invoke-Build }
GenerateOpenAPIAndMD { Invoke-GenerateOpenAPIAndMD }
BuildAndPublish {
Invoke-SetAssemblyInfo
Invoke-Build
Expand Down

0 comments on commit 767439e

Please sign in to comment.