Fix OpenAPI generation issue after .NET 9 upgrade (#632) #591
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Account Management - Build and Deploy | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- "application/*" | |
- "application/shared-kernel/**" | |
- "application/shared-webapp/**" | |
- "application/account-management/**" | |
- ".github/workflows/account-management.yml" | |
- ".github/workflows/_deploy-container.yml" | |
- "!**.md" | |
pull_request: | |
paths: | |
- "application/*" | |
- "application/shared-kernel/**" | |
- "application/shared-webapp/**" | |
- "application/account-management/**" | |
- ".github/workflows/account-management.yml" | |
- ".github/workflows/_deploy-container.yml" | |
- "!**.md" | |
workflow_dispatch: | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
build-and-test: | |
name: Build and Test | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.generate_version.outputs.version }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Generate version | |
id: generate_version | |
run: | | |
# Strip leading 0s of Hours and Minutes after midnight | |
MINUTE=$(printf "%s" $(date +"%-H%M") | sed 's/^0*//') | |
VERSION=$(date +"%Y.%-m.%-d.")$MINUTE | |
echo "Generated version: $VERSION" | |
echo "version=$VERSION" >> $GITHUB_OUTPUT | |
- name: Setup Node.js environment | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Install Node modules | |
working-directory: application | |
run: npm ci | |
- name: Setup .NET Core SDK | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: 9.0.x | |
- name: Restore .NET tools | |
working-directory: application | |
run: | | |
dotnet tool restore | |
- name: Restore .NET dependencies | |
working-directory: application | |
run: dotnet restore | |
- name: Generate and set user secret for token signing key | |
working-directory: application/shared-kernel/SharedKernel | |
run: | | |
# Extract UserSecretsId from the .csproj file | |
USER_SECRETS_ID=$(grep -oP '(?<=<UserSecretsId>).*?(?=</UserSecretsId>)' SharedKernel.csproj) | |
# Generate a 512-bit key and set it as a user secret that can be use for token signing when running tests | |
dotnet user-secrets set "authentication-token-signing-key" "$(openssl rand -base64 64)" --id $USER_SECRETS_ID | |
- name: Setup Java JDK for SonarScanner | |
uses: actions/setup-java@v4 | |
with: | |
distribution: "microsoft" | |
java-version: "17" | |
- name: Run tests with dotCover and SonarScanner reporting | |
working-directory: application | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: | | |
if [[ "${{ vars.SONAR_PROJECT_KEY }}" == "" ]]; then | |
echo "SonarCloud is not enabled. Skipping SonarCloud analysis." | |
dotnet build account-management/AccountManagement.slnf --no-restore /p:Version=${{ steps.generate_version.outputs.version }} && | |
dotnet dotcover test account-management/AccountManagement.slnf --no-build --dcOutput=coverage/dotCover.html --dcReportType=HTML --dcFilters="+:PlatformPlatform.*;-:*.Tests;-:type=*.AppHost.*" | |
else | |
dotnet sonarscanner begin /k:"${{ vars.SONAR_PROJECT_KEY }}" /o:"${{ vars.SONAR_ORGANIZATION }}" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.dotcover.reportsPaths="coverage/dotCover.html" && | |
dotnet build account-management/AccountManagement.slnf --no-restore /p:Version=${{ steps.generate_version.outputs.version }} && | |
dotnet dotcover test account-management/AccountManagement.slnf --no-build --dcOutput=coverage/dotCover.html --dcReportType=HTML --dcFilters="+:PlatformPlatform.*;-:*.Tests;-:type=*.AppHost.*" && | |
dotnet sonarscanner end /d:sonar.login="${SONAR_TOKEN}" | |
fi | |
- name: Build frontend artifacts | |
if: github.ref == 'refs/heads/main' | |
working-directory: application | |
run: npm run build | |
- name: Publish frontend artifacts | |
if: github.ref == 'refs/heads/main' | |
working-directory: application/account-management/WebApp | |
run: npm run publish | |
- name: Publish API build | |
if: github.ref == 'refs/heads/main' | |
working-directory: application/account-management | |
run: | | |
dotnet publish ./Api/AccountManagement.Api.csproj --no-restore --configuration Release --output ./Api/publish /p:Version=${{ steps.generate_version.outputs.version }} | |
- name: Save API artifacts | |
if: github.ref == 'refs/heads/main' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: account-management-api | |
path: application/account-management/Api/publish/**/* | |
- name: Publish Worker build | |
if: github.ref == 'refs/heads/main' | |
working-directory: application/account-management | |
run: | | |
dotnet publish ./Workers/AccountManagement.Workers.csproj --no-restore --configuration Release --output ./Workers/publish /p:Version=${{ steps.generate_version.outputs.version }} | |
- name: Save Workers artifacts | |
if: github.ref == 'refs/heads/main' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: account-management-workers | |
path: application/account-management/Workers/publish/**/* | |
code-style-and-linting: | |
name: Code Style and Linting | |
if: github.ref != 'refs/heads/main' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Node.js environment | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Install Node modules | |
working-directory: application | |
run: npm ci | |
- name: Setup .NET Core SDK | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: 9.0.x | |
- name: Restore .NET tools | |
working-directory: application | |
run: | | |
dotnet tool restore | |
- name: Restore .NET dependencies | |
working-directory: application | |
run: dotnet restore | |
- name: Build backend solution | |
working-directory: application | |
run: dotnet build account-management/AccountManagement.slnf --no-restore | |
- name: Run code inspections | |
working-directory: application | |
run: | | |
dotnet jb inspectcode account-management/AccountManagement.slnf --no-build --output=result.json --severity=SUGGESTION | |
# Check if there are any issues. <Issues /> indicates no issues found. | |
if ! grep -q '\"results\": \[\],' result.json; then | |
cat result.json | |
echo "Code inspection issues found." | |
exit 1 | |
fi | |
- name: Check for code formatting issues | |
working-directory: application | |
run: | | |
dotnet jb cleanupcode account-management/AccountManagement.slnf --no-build --profile=".NET only" | |
# Check for any changes made by the code formatter | |
git diff --exit-code || { | |
echo "Formatting issues detected. Please run 'dotnet jb cleanupcode account-management/AccountManagement.slnf --profile=\".NET only\"' locally and commit the formatted code." | |
exit 1 | |
} | |
- name: Build frontend artifacts | |
working-directory: application | |
run: npm run build | |
- name: Run check | |
working-directory: application/account-management/WebApp | |
run: npm run check | |
api-deploy: | |
name: Deploy API | |
if: github.ref == 'refs/heads/main' | |
needs: [build-and-test] | |
uses: ./.github/workflows/_deploy-container.yml | |
secrets: inherit | |
with: | |
image_name: account-management-api | |
version: ${{ needs.build-and-test.outputs.version }} | |
artifacts_name: account-management-api | |
artifacts_path: application/account-management/Api/publish | |
docker_context: ./application/account-management | |
docker_file: ./Api/Dockerfile | |
workers-deploy: | |
name: Deploy Workers | |
if: github.ref == 'refs/heads/main' | |
needs: [build-and-test] | |
uses: ./.github/workflows/_deploy-container.yml | |
secrets: inherit | |
with: | |
image_name: account-management-workers | |
version: ${{ needs.build-and-test.outputs.version }} | |
artifacts_name: account-management-workers | |
artifacts_path: application/account-management/Workers/publish | |
docker_context: ./application/account-management | |
docker_file: ./Workers/Dockerfile |