Skip to content

Commit

Permalink
Azure AD B2C サンプルに Web APIの結合テストを追加する (#1091)
Browse files Browse the repository at this point in the history
* Azure AD B2C サンプルのReadMeの誤字修正とcspellの除外設定追加 (#1051)

* cspellの除外設定を追加。

* 誤字修正。

---------

Co-authored-by: Fumika Koyama <[email protected]>

* アプリケーションアーキテクチャ概要編からコンソールアプリの要件別サンプルにリンクを張る (#1057)

* リンクを追加

* 冗長な記載を修正

* documentsのreadmeを最新化する (#1062)

* フォルダー構造を修正。

* 「テスト方針」と「画像ファイル」のフォルダー構成を修正。

---------

Co-authored-by: Fumika Koyama <[email protected]>

* JWT認証処理を結合テストプロジェクトに追加。

* 結合テスト内でテスト用のJwtBearer認証を利用するよう修正。

* CIでテストを実行するようYAMLを修正。

* READMEにテストについての説明を追加。

* lintエラーに対応。

* lintエラーに対応。

* インデントを修正。

* インデントを修正。

* env名を修正。

* samples-azure-ad-b2c-auth-ci.ymlのインデントを2文字分に修正。

* インデントを修正。

* permissionが必要なjobをCIパイプラインから削除。

* WebApplicationFactoryクラスとテストクラスの名前を変更。

* 結合テストを組み込む方法の説明を追加。

* テスト結果サマリーの表示を修正。

* テスト結果を表示するよう修正。

* テスト結果表示部分を修正。

* テスト実行時のコンソールログのverbosityをquietに変更。

* dotnet test のverbosityをquietに変更。

* テスト実行時のログレベルをWarningに変更。

* 環境変数名を修正。

* 環境変数を修正。

* 環境変数を設定するタイミングを変更。

* テスト実行後の部分のみ表示するよう修正。

* trx-parserを使用する設定を追加。

* バージョン表記を修正。

* node.js 20対応バージョンに変更。

* 解析対象のTRXファイルのパスを修正。

* TRXファイルのパスを修正。

* permission追加。

* TRXのパスを修正。

* test-reporterを使用するよう修正。

* 不要なスペースを削除。

* テスト結果ページのタイトルを修正。

---------

Co-authored-by: Fumika Koyama <[email protected]>
Co-authored-by: kentah <[email protected]>
  • Loading branch information
3 people authored Apr 24, 2024
1 parent 89e800c commit 83398a3
Show file tree
Hide file tree
Showing 12 changed files with 552 additions and 182 deletions.
295 changes: 173 additions & 122 deletions .github/workflows/samples-azure-ad-b2c-auth-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,130 +4,181 @@
name: azure-ad-b2c-auth-sample CI

on:
pull_request:
branches: [main]
paths:
- 'samples/AzureADB2CAuth/**'
- '.github/workflows/samples-azure-ad-b2c-auth-ci.yml'
workflow_dispatch:
pull_request:
branches: [main]
paths:
- 'samples/AzureADB2CAuth/**'
- '.github/workflows/samples-azure-ad-b2c-auth-ci.yml'
workflow_dispatch:

env:
BACKEND_WORKING_DIRECTORY: samples/AzureADB2CAuth/auth-backend
FRONTEND_WORKING_DIRECTORY: samples/AzureADB2CAuth/auth-frontend
BACKEND_WORKING_DIRECTORY: samples/AzureADB2CAuth/auth-backend
FRONTEND_WORKING_DIRECTORY: samples/AzureADB2CAuth/auth-frontend

jobs:
build-frontend:
name: 'フロントエンドアプリケーションのビルド'
runs-on: ubuntu-latest
build-frontend:
name: フロントエンドアプリケーションのビルド
runs-on: ubuntu-latest
env:
NO_COLOR: "1" # 文字化け防止のためカラーコードを出力しない
strategy:
matrix:
node-version: [20.x]

defaults:
run:
working-directory: ${{ env.FRONTEND_WORKING_DIRECTORY }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- uses: actions/cache@v4
id: node_modules_cache_id
env:
NO_COLOR: "1" # 文字化け防止のためカラーコードを出力しない
strategy:
matrix:
node-version: [20.x]

defaults:
run:
working-directory: ${{ env.FRONTEND_WORKING_DIRECTORY }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- uses: actions/cache@v4
id: node_modules_cache_id
env:
cache-name: cache-node-modules-azure-ad-b2c-auth-frontend
with:
path: '**/node_modules'
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}

- name: node パッケージのキャッシュ確認
run: echo '${{ toJSON(steps.node_modules_cache_id.outputs) }}'

- name: node パッケージのインストール
if: ${{ steps.node_modules_cache_id.outputs.cache-hit != 'true' }}
run: npm install

- id: run-lint
name: lintの実行
run: npm run lint:ci >> /var/tmp/lint-result.txt 2>&1

- id: run-typecheck
name: TypeScript の型チェック
run: npm run typecheck >> /var/tmp/typecheck-result.txt 2>&1

- id: application-build
name: アプリケーションのビルド
run: npm run build-only:dev >> /var/tmp/build-result.txt 2>&1

- name: lintの結果出力
if: ${{ success() || (failure() && steps.run-lint.conclusion == 'failure') }}
uses: ./.github/workflows/file-to-summary
with:
body: /var/tmp/lint-result.txt
header: 'lintの結果 :pen:'

- name: 型チェックの結果出力
if: ${{ success() || (failure() && steps.run-typecheck.conclusion == 'failure') }}
uses: ./.github/workflows/file-to-summary
with:
body: /var/tmp/typecheck-result.txt
header: '型チェックの結果 :pencil2:'

- name: ビルドの結果出力
if: ${{ success() || (failure() && steps.application-build.conclusion == 'failure') }}
uses: ./.github/workflows/file-to-summary
with:
body: /var/tmp/build-result.txt
header: 'ビルドの結果 :gear:'

build-backend:
name: 'バックエンドアプリケーションのビルド'
runs-on: ubuntu-latest
env:
DOTNET_NOLOGO: true
BUILD_CONFIGURATION: Debug
BUILD_SUMMARY_FILE: BuildSummary.md
defaults:
run:
working-directory: ${{ env.BACKEND_WORKING_DIRECTORY }}
steps:
- name: 'ブランチのチェックアウト'
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: '.NET SDK のセットアップ'
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.*'

- name: 'NuGet パッケージの復元'
run: dotnet restore

- id: application-build
name: 'アプリケーションのビルド'
continue-on-error: true
run: |
echo '## Build Result :gear:' >> $GITHUB_STEP_SUMMARY
dotnet build --nologo --configuration ${{ env.BUILD_CONFIGURATION }} --verbosity minimal > build-result.txt
echo ':heavy_check_mark: アプリケーションのビルドに成功しました。' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
cat build-result.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: 'ビルド失敗時の結果の表示'
shell: bash
if: ${{ steps.application-build.outcome == 'failure' }}
run: |
echo ':x: アプリケーションのビルドに失敗しました。 ' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
cat build-result.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
exit 1
cache-name: cache-node-modules-azure-ad-b2c-auth-frontend
with:
path: '**/node_modules'
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}

- name: node パッケージのキャッシュ確認
run: echo '${{ toJSON(steps.node_modules_cache_id.outputs) }}'

- name: node パッケージのインストール
if: ${{ steps.node_modules_cache_id.outputs.cache-hit != 'true' }}
run: npm install

- id: run-lint
name: lintの実行
run: npm run lint:ci >> /var/tmp/lint-result.txt 2>&1

- id: run-typecheck
name: TypeScript の型チェック
run: npm run typecheck >> /var/tmp/typecheck-result.txt 2>&1

- id: application-build
name: アプリケーションのビルド
run: npm run build-only:dev >> /var/tmp/build-result.txt 2>&1

- name: lintの結果出力
if: ${{ success() || (failure() && steps.run-lint.conclusion == 'failure') }}
uses: ./.github/workflows/file-to-summary
with:
body: /var/tmp/lint-result.txt
header: 'lintの結果 :pen:'

- name: 型チェックの結果出力
if: ${{ success() || (failure() && steps.run-typecheck.conclusion == 'failure') }}
uses: ./.github/workflows/file-to-summary
with:
body: /var/tmp/typecheck-result.txt
header: '型チェックの結果 :pencil2:'

- name: ビルドの結果出力
if: ${{ success() || (failure() && steps.application-build.conclusion == 'failure') }}
uses: ./.github/workflows/file-to-summary
with:
body: /var/tmp/build-result.txt
header: 'ビルドの結果 :gear:'

build-backend:
name: バックエンドアプリケーションのビルド
runs-on: ubuntu-latest
env:
DOTNET_NOLOGO: true
BUILD_CONFIGURATION: Debug
BUILD_SUMMARY_FILE: BuildSummary.md
permissions:
checks: write
contents: read
defaults:
run:
working-directory: ${{ env.BACKEND_WORKING_DIRECTORY }}
steps:
- name: ブランチのチェックアウト
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: .NET SDK のセットアップ
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.*'

- name: NuGet パッケージの復元
run: dotnet restore

- id: application-build
name: アプリケーションのビルド
continue-on-error: true
run: |
echo '## Build Result :gear:' >> $GITHUB_STEP_SUMMARY
dotnet build --nologo --configuration ${{ env.BUILD_CONFIGURATION }} --verbosity minimal > build-result.txt
echo ':heavy_check_mark: アプリケーションのビルドに成功しました。' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
cat build-result.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: ビルド失敗時の結果の表示
shell: bash
if: ${{ steps.application-build.outcome == 'failure' }}
run: |
echo ':x: アプリケーションのビルドに失敗しました。 ' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
cat build-result.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
exit 1
- id: run-tests
name: テストの実行
continue-on-error: true
run: |
dotnet test --no-build --nologo --logger "trx;LogFileName=integration-test.trx" --logger:"console;verbosity=minimal" --verbosity normal --configuration ${{ env.BUILD_CONFIGURATION }} --collect "XPlat Code Coverage" > integration-test-result.txt
- id: create-test-result-report
name: テスト結果ページの作成
uses: dorny/test-reporter@v1
if: ${{ success() || (failure() && steps.run-tests.conclusion == 'failure') }}
with:
name: 'バックエンドのテスト結果'
path: '**/TestResults/*.trx'
path-replace-backslashes: 'true'
reporter: 'dotnet-trx'
only-summary: 'false'
list-suites: 'all'
list-tests: 'all'
max-annotations: '10'
fail-on-error: 'true'

- name: テスト結果のサマリー表示
shell: bash
if: ${{ success() || (failure() && steps.run-tests.conclusion == 'failure') }}
run: |
echo '## Test Result :memo:' >> ${{ env.BUILD_SUMMARY_FILE }}
echo 'Test was a **${{ steps.create-test-result-report.outputs.conclusion }}**.' >> ${{ env.BUILD_SUMMARY_FILE }}
echo 'Completed in ${{ steps.create-test-result-report.outputs.time }}ms with **${{ steps.create-test-result-report.outputs.passed }}** passed, **${{ steps.create-test-result-report.outputs.failed }}** failed and ${{ steps.create-test-result-report.outputs.skipped }} skipped.' >> ${{ env.BUILD_SUMMARY_FILE }}
cat ${{ env.BUILD_SUMMARY_FILE }} >> $GITHUB_STEP_SUMMARY
- id: create-coverage-report
name: コードカバレッジレポートの解析と作成
uses: danielpalme/ReportGenerator-GitHub-Action@5
if: ${{ success() || (failure() && steps.run-tests.conclusion == 'failure') }}
with:
reports: '**/TestResults/*/coverage.cobertura.xml'
targetdir: '${{ env.BACKEND_WORKING_DIRECTORY }}/CoverageReport'
reporttypes: 'MarkdownSummaryGithub'

- name: コードカバレッジの結果表示
shell: bash
if: ${{ success() || (failure() && steps.run-tests.conclusion == 'failure') }}
run: |
sed -i s/'# Summary'/'## Coverage :triangular_ruler:'/g CoverageReport/SummaryGithub.md
sed -i -e '/^## Coverage$/d' CoverageReport/SummaryGithub.md
cat CoverageReport/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
cat CoverageReport/SummaryGithub.md >> ${{ env.BUILD_SUMMARY_FILE }}
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"langword",
"linenums",
"mkdocs",
"MSAL",
"mssql",
"MVVM",
"nameof",
Expand Down
Loading

0 comments on commit 83398a3

Please sign in to comment.