Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

楽観同時実行制御・認可を行うサンプルアプリ(Dressca Admin)を追加する #2137

Merged
merged 5 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 65 additions & 17 deletions .github/workflows/check-openapi-generator-update.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# cspell:ignore dblock elif fjogeleit Wandalen wretry
# cspell:ignore dblock elif fjogeleit openapitools Wandalen wretry
name: openapi-generatorのバージョンアップ確認
on:
pull_request:
Expand Down Expand Up @@ -38,27 +38,38 @@ jobs:
- name: 現在のOpenAPI Generatorのバージョン取得
id: get-current-openapi-generator-version
run: |
echo "current-version=$(jq -r '.["generator-cli"].version' ./samples/Dressca/dressca-frontend/consumer/openapitools.json)" >> $GITHUB_OUTPUT
echo "current-version-consumer=$(jq -r '.["generator-cli"].version' ./samples/Dressca/dressca-frontend/consumer/openapitools.json)" >> $GITHUB_OUTPUT
echo "current-version-admin=$(jq -r '.["generator-cli"].version' ./samples/Dressca/dressca-frontend/admin/openapitools.json)" >> $GITHUB_OUTPUT

- name: アップデート要否を判定
id: check-version-update
run: |
if [[ ${{ steps.get-latest-openapi-generator-version.outputs.latest-version }} == ${{ steps.get-current-openapi-generator-version.outputs.current-version }} ]]; then
echo "update-required=false" >> $GITHUB_OUTPUT
if [[ ${{ steps.get-latest-openapi-generator-version.outputs.latest-version }} == ${{ steps.get-current-openapi-generator-version.outputs.current-version-consumer }} ]]; then
echo "update-required-consumer=false" >> $GITHUB_OUTPUT
else
echo "update-required=true" >> $GITHUB_OUTPUT
echo "update-required-consumer=true" >> $GITHUB_OUTPUT
fi
if [[ ${{ steps.get-latest-openapi-generator-version.outputs.latest-version }} == ${{ steps.get-current-openapi-generator-version.outputs.current-version-admin }} ]]; then
echo "update-required-admin=false" >> $GITHUB_OUTPUT
else
echo "update-required-admin=true" >> $GITHUB_OUTPUT
fi

- name: サマリに出力
run: |
echo "# 確認結果" >> $GITHUB_STEP_SUMMARY
echo "openapi-generator のバージョンは ${{ steps.get-latest-openapi-generator-version.outputs.latest-version }} です。" >> $GITHUB_STEP_SUMMARY
echo "openapitools.json の openapi-generator のバージョンは ${{ steps.get-current-openapi-generator-version.outputs.current-version }} です。" >> $GITHUB_STEP_SUMMARY
echo "アップデート要否の判定結果は ${{ steps.check-version-update.outputs.update-required }} です。">> $GITHUB_STEP_SUMMARY
echo "## Dressca-Consumer" >> $GITHUB_STEP_SUMMARY
echo "openapitools.json の openapi-generator のバージョンは ${{ steps.get-current-openapi-generator-version.outputs.current-version-consumer }} です。" >> $GITHUB_STEP_SUMMARY
echo "アップデート要否の判定結果は ${{ steps.check-version-update.outputs.update-required-consumer }} です。">> $GITHUB_STEP_SUMMARY
echo "## Dressca-Admin" >> $GITHUB_STEP_SUMMARY
echo "openapitools.json の openapi-generator のバージョンは ${{ steps.get-current-openapi-generator-version.outputs.current-version-admin }} です。" >> $GITHUB_STEP_SUMMARY
echo "アップデート要否の判定結果は ${{ steps.check-version-update.outputs.update-required-admin }} です。">> $GITHUB_STEP_SUMMARY

- name: issue を作成
id: create-issue
if: ${{ steps.check-version-update.outputs.update-required == 'true' }}

- name: issue を作成(Dressca-Consumer)
id: create-issue-consumer
if: ${{ steps.check-version-update.outputs.update-required-consumer == 'true' }}
uses: Wandalen/wretry.action@master
with:
action: dblock/create-a-github-issue@v3
Expand All @@ -72,17 +83,17 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TARGET_APP_NAME: "Dressca-Consumer"
LATEST_VERSION: ${{ steps.get-latest-openapi-generator-version.outputs.latest-version }}
CURRENT_VERSION: ${{ steps.get-current-openapi-generator-version.outputs.current-version }}
CURRENT_VERSION: ${{ steps.get-current-openapi-generator-version.outputs.current-version-consumer }}


- name: issue の情報を出力
if: ${{ steps.check-version-update.outputs.update-required == 'true' }}
- name: issue の情報を出力(Dressca-Consumer)
if: ${{ steps.check-version-update.outputs.update-required-consumer == 'true' }}
env:
STATUS: ${{ steps.create-issue.outputs.outputs && fromJson(steps.create-issue.outputs.outputs).status }}
ISSUE_NUMBER: ${{ steps.create-issue.outputs.outputs && fromJson(steps.create-issue.outputs.outputs).number }}
ISSUE_URL: ${{ steps.create-issue.outputs.outputs && fromJson(steps.create-issue.outputs.outputs).url }}
STATUS: ${{ steps.create-issue-consumer.outputs.outputs && fromJson(steps.create-issue-consumer.outputs.outputs).status }}
ISSUE_NUMBER: ${{ steps.create-issue-consumer.outputs.outputs && fromJson(steps.create-issue-consumer.outputs.outputs).number }}
ISSUE_URL: ${{ steps.create-issue-consumer.outputs.outputs && fromJson(steps.create-issue-consumer.outputs.outputs).url }}
run: |
echo "# issue の作成結果" >> $GITHUB_STEP_SUMMARY
echo "# issue の作成結果(Dressca-Consumer)" >> $GITHUB_STEP_SUMMARY
if [ $STATUS = 'created' ]; then
echo "issue を新規作成しました。" >> $GITHUB_STEP_SUMMARY
elif [ $STATUS = 'updated' ]; then
Expand All @@ -93,3 +104,40 @@ jobs:
echo issue number: $ISSUE_NUMBER >> $GITHUB_STEP_SUMMARY
echo status: $STATUS >> $GITHUB_STEP_SUMMARY
echo - $ISSUE_URL >> $GITHUB_STEP_SUMMARY

- name: issue を作成(Dressca-Admin)
id: create-issue-admin
if: ${{ steps.check-version-update.outputs.update-required-admin == 'true' }}
uses: Wandalen/wretry.action@master
with:
action: dblock/create-a-github-issue@v3
with: |
filename: ./.github/ISSUE_TEMPLATE/99-openapi-generator-update-issue.md
update_existing: true
search_existing: open
attempt_limit: 3
attempt_delay: 300000
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TARGET_APP_NAME: "Dressca-Admin"
LATEST_VERSION: ${{ steps.get-latest-openapi-generator-version.outputs.latest-version }}
CURRENT_VERSION: ${{ steps.get-current-openapi-generator-version.outputs.current-version-admin }}

- name: issue の情報を出力(Dressca-Admin)
if: ${{ steps.check-version-update.outputs.update-required-admin == 'true' }}
env:
STATUS: ${{ steps.create-issue-admin.outputs.outputs && fromJson(steps.create-issue-admin.outputs.outputs).status }}
ISSUE_NUMBER: ${{ steps.create-issue-admin.outputs.outputs && fromJson(steps.create-issue-admin.outputs.outputs).number }}
ISSUE_URL: ${{ steps.create-issue-admin.outputs.outputs && fromJson(steps.create-issue-admin.outputs.outputs).url }}
run: |
echo "# issue の作成結果(Dressca-Admin)" >> $GITHUB_STEP_SUMMARY
if [ $STATUS = 'created' ]; then
echo "issue を新規作成しました。" >> $GITHUB_STEP_SUMMARY
elif [ $STATUS = 'updated' ]; then
echo "同名の issue が存在するため、更新のみ行いました。" >> $GITHUB_STEP_SUMMARY
else
echo "ステータスの値が不正です。" >> $GITHUB_STEP_SUMMARY
fi
echo issue number: $ISSUE_NUMBER >> $GITHUB_STEP_SUMMARY
echo status: $STATUS >> $GITHUB_STEP_SUMMARY
echo - $ISSUE_URL >> $GITHUB_STEP_SUMMARY
144 changes: 144 additions & 0 deletions .github/workflows/samples-dressca-admin-backend.ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
---
# cSpell:ignore danielpalme dorny marocchino NOLOGO OPTOUT reporttypes targetdir

name: dressca-admin-backend CI

on:
pull_request:
branches: [main]
paths:
- 'samples/Dressca/dressca-backend/**'
- '.github/workflows/samples-dressca-admin-backend.ci.yml'
workflow_dispatch:

env:
WORKING_DIRECTORY: samples/Dressca/dressca-backend
SOLUTION_FILE_NAME: Dressca.Web.Admin.slnf

defaults:
run:
working-directory: samples/Dressca/dressca-backend

jobs:
build:
name: バックエンドアプリケーションのビルド
runs-on: ubuntu-latest
env:
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
BUILD_CONFIGURATION: Debug
BUILD_SUMMARY_FILE: BuildSummary.md
TEST_ENVIRONMENT: IntegrationTest
permissions:
checks: write
contents: read
pull-requests: write

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 ${{ env.SOLUTION_FILE_NAME }}

- id: application-build
name: アプリケーションのビルド
run: dotnet build ${{ env.SOLUTION_FILE_NAME }} --no-restore --configuration ${{ env.BUILD_CONFIGURATION }} --verbosity minimal > build-result.txt

- name: ビルド結果の表示
shell: bash
if: ${{ success() || (failure() && steps.application-build.conclusion == 'failure') }}
run: |
echo '# Build Result :gear:' >> $GITHUB_STEP_SUMMARY
cat build-result.txt | sed -n -e 's/^/> /p' >> $GITHUB_STEP_SUMMARY

- name: SQL ServerのDockerイメージをプル(結合テスト用)
run: sudo docker pull mcr.microsoft.com/mssql/server:2022-latest

- name: SQL Serverのコンテナを起動(結合テスト用)
run: |
sudo docker run -e "ACCEPT_EULA=Y" \
-e "MSSQL_SA_PASSWORD=P@ssw0rd" \
-p 1433:1433 --name sql1 \
--hostname sql1 \
-d mcr.microsoft.com/mssql/server:2022-latest

- name: データベース接続文字列を取得(結合テスト用)
id: get-connection-string
env:
APPSETTINGS_FILEPATH: tests/Dressca.Web.Admin.IntegrationTest/appsettings.${{ env.TEST_ENVIRONMENT }}.json
run: |
connectionString=$(cat ${{env.APPSETTINGS_FILEPATH}} | jq '.ConnectionStrings.DresscaDbContext')
echo "CONNECTION_STRING=${connectionString}" >> "$GITHUB_OUTPUT"

- name: EF Core ツールのインストール(結合テスト用)
shell: bash
run: dotnet tool install --global dotnet-ef --version 8.*

- name: マイグレーション適用(結合テスト用)
working-directory: ${{ env.WORKING_DIRECTORY }}/src/Dressca.EfInfrastructure
shell: bash
run: dotnet ef database update --connection ${{ steps.get-connection-string.outputs.CONNECTION_STRING }}

- id: run-tests
name: テストの実行
continue-on-error: true
run: |
export TEST_ENVIRONMENT=${{ env.TEST_ENVIRONMENT }}
dotnet test ${{ env.SOLUTION_FILE_NAME }} --no-build --logger trx --verbosity normal --configuration ${{ env.BUILD_CONFIGURATION }} --collect "XPlat Code Coverage"

- id: create-test-result-report
name: テスト結果ページの作成
uses: dorny/test-reporter@v1
if: ${{ success() || (failure() && steps.run-tests.conclusion == 'failure') }}
with:
name: 'Test results'
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@v5
if: ${{ success() || (failure() && steps.run-tests.conclusion == 'failure') }}
with:
reports: '**/TestResults/*/coverage.cobertura.xml'
targetdir: '${{ env.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 }}

- name: ビルドサマリーをPull-requestに表示
uses: marocchino/sticky-pull-request-comment@v2
if: ${{ github.event_name == 'pull_request' && (success() || (failure() && steps.run-tests.conclusion == 'failure')) }}
with:
recreate: true
path: '${{ env.WORKING_DIRECTORY }}/${{ env.BUILD_SUMMARY_FILE }}'
93 changes: 93 additions & 0 deletions .github/workflows/samples-dressca-admin-frontend.ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---

name: dressca-admin-frontend CI

on:
pull_request:
branches: [main]
paths:
- 'samples/Dressca/dressca-frontend/*.*'
- 'samples/Dressca/dressca-frontend/admin/**'
- '.github/workflows/samples-dressca-admin-frontend.ci.yml'
workflow_dispatch:

defaults:
run:
working-directory: samples/Dressca/dressca-frontend/

jobs:
build:
name: Dressca 管理のフロントエンドアプリケーションのビルド
runs-on: ubuntu-latest
env:
NO_COLOR: "1" # 文字化け防止のためカラーコードを出力しない
strategy:
matrix:
node-version: [20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v4
- 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
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 ci

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

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

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

- id: run-unit-tests
name: 単体テストの実行
run: npm run test:unit:admin >> /var/tmp/unit-test-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-type-check.conclusion == 'failure') }}
uses: ./.github/workflows/file-to-summary
with:
body: /var/tmp/type-check-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:'

- name: 単体テストの結果出力
if: ${{ success() || (failure() && steps.run-unit-tests.conclusion == 'failure') }}
uses: ./.github/workflows/file-to-summary
with:
body: /var/tmp/unit-test-result.txt
header: '単体テストの結果 :memo:'
1 change: 1 addition & 0 deletions samples/Dressca/dressca-backend/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.3" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.3" />
<PackageVersion Include="Microsoft.AspNetCore.SpaProxy" Version="8.0.3" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.3" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.3" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.3" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
Expand Down
21 changes: 21 additions & 0 deletions samples/Dressca/dressca-backend/Dressca.Web.Admin.slnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"solution": {
"path": "Dressca.sln",
"projects": [
"src\\Dressca.ApplicationCore\\Dressca.ApplicationCore.csproj",
"src\\Dressca.EfInfrastructure\\Dressca.EfInfrastructure.csproj",
"src\\Dressca.Store.Assets.StaticFiles\\Dressca.Store.Assets.StaticFiles.csproj",
"src\\Dressca.SystemCommon\\Dressca.SystemCommon.csproj",
"src\\Dressca.Web.Admin.Dto\\Dressca.Web.Admin.Dto.csproj",
"src\\Dressca.Web.Admin\\Dressca.Web.Admin.csproj",
"src\\Dressca.Web\\Dressca.Web.csproj",
"src\\Maris.Logging.Testing\\Maris.Logging.Testing.csproj",
"tests\\Dressca.UnitTests.ApplicationCore\\Dressca.UnitTests.ApplicationCore.csproj",
"tests\\Dressca.UnitTests.SystemCommon\\Dressca.UnitTests.SystemCommon.csproj",
"tests\\Dressca.UnitTests.Web.Admin\\Dressca.UnitTests.Web.Admin.csproj",
"tests\\Dressca.UnitTests.Web\\Dressca.UnitTests.Web.csproj",
"tests\\Dressca.Web.Admin.IntegrationTest\\Dressca.Web.Admin.IntegrationTest.csproj",
"tests\\Maris.Logging.Testing.Tests\\Maris.Logging.Testing.Tests.csproj"
]
}
}
Loading
Loading