Skip to content

Commit af156d1

Browse files
committed
Run AppGateway tests in app-gateway workflow, split SonarCloud tests per slnf, and drop leftover SonarScanner steps from account and main workflows
1 parent 45de7b0 commit af156d1

8 files changed

Lines changed: 67 additions & 64 deletions

File tree

.github/workflows/_deploy-container.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ on:
3838
required: true
3939
type: string
4040

41+
concurrency:
42+
group: ${{ inputs.image_name }}-${{ inputs.azure_environment }}-deploy
43+
cancel-in-progress: false
44+
4145
jobs:
4246
deploy:
4347
name: Deploy

.github/workflows/_deploy-infrastructure.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ on:
4949
type: string
5050
default: "-"
5151

52+
concurrency:
53+
group: ${{ inputs.unique_prefix }}-${{ inputs.azure_environment }}-infrastructure
54+
cancel-in-progress: false
55+
5256
jobs:
5357
plan:
5458
name: Plan
@@ -67,6 +71,7 @@ jobs:
6771
should_deploy="false"
6872
fi
6973
echo "should_deploy=$should_deploy" >> $GITHUB_OUTPUT
74+
7075
- name: Checkout Code
7176
uses: actions/checkout@v6
7277

.github/workflows/_migrate-database.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ jobs:
106106
run: |
107107
ENTRA_USER=$(az postgres flexible-server microsoft-entra-admin list --resource-group ${{ env.CLUSTER_RESOURCE_GROUP_NAME }} --server-name ${{ env.POSTGRES_SERVER_NAME }} --query "[0].principalName" --output tsv)
108108
CONNECTION_STRING="Host=${{ env.POSTGRES_HOST }};Database=${{ inputs.database_name }};Username=$ENTRA_USER;Password=$(az account get-access-token --resource-type oss-rdbms --query accessToken --output tsv);Ssl Mode=VerifyFull;"
109-
109+
110110
echo "Checking for pending migrations..."
111111
MIGRATION_INFO=$(dotnet ef migrations list \
112112
--project ${{ inputs.relative_project_path }} \
@@ -115,12 +115,12 @@ jobs:
115115
--connection "$CONNECTION_STRING" \
116116
--no-build \
117117
--json)
118-
118+
119119
MIGRATION_JSON=$(echo "$MIGRATION_INFO" | sed -n '/^[{[]/,$p')
120120
PENDING_MIGRATIONS_JSON=$(echo "$MIGRATION_JSON" | jq '[.[] | select(.applied == false)]')
121121
PENDING_MIGRATIONS_COUNT=$(echo "$PENDING_MIGRATIONS_JSON" | jq '. | length')
122122
LAST_APPLIED_MIGRATION=$(echo "$MIGRATION_JSON" | jq -r '[.[] | select(.applied == true) | .id] | sort | last // "0"')
123-
123+
124124
if [ "$PENDING_MIGRATIONS_COUNT" -gt "0" ]; then
125125
LAST_PENDING_MIGRATION=$(echo "$PENDING_MIGRATIONS_JSON" | jq -r '.[-1].id')
126126
echo "$PENDING_MIGRATIONS_COUNT pending migration(s) detected:"
@@ -135,13 +135,13 @@ jobs:
135135
--idempotent \
136136
--no-build \
137137
--output migration.sql
138-
138+
139139
echo "has_migrations_to_apply=true" >> $GITHUB_OUTPUT
140-
140+
141141
echo "migration_script<<EOF" >> $GITHUB_OUTPUT
142142
cat migration.sql >> $GITHUB_OUTPUT
143143
echo "EOF" >> $GITHUB_OUTPUT
144-
144+
145145
echo "migration_json<<EOF" >> $GITHUB_OUTPUT
146146
echo "$PENDING_MIGRATIONS_JSON" >> $GITHUB_OUTPUT
147147
echo "EOF" >> $GITHUB_OUTPUT
@@ -178,22 +178,22 @@ jobs:
178178
with:
179179
script: |
180180
const migrationJson = JSON.parse(process.env.MIGRATION_JSON);
181-
181+
182182
const migrationsList = migrationJson.map(m => `- ${m.name} (${m.id})`).join('\n');
183-
183+
184184
const migrationInfo = `## Approve Database Migration \`${{ inputs.database_name }}\` database on \`${{ inputs.azure_environment }}\`
185-
185+
186186
The following pending migration(s) will be applied to the database when approved:
187187
${migrationsList}
188-
188+
189189
### Migration Script
190190
\`\`\`sql
191191
${process.env.MIGRATION_SCRIPT}
192192
\`\`\`
193193
`;
194-
194+
195195
console.log(migrationInfo);
196-
196+
197197
core.setOutput('markdown', migrationInfo);
198198
199199
- name: Add Migration Information to Pull Request

.github/workflows/account.yml

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ on:
1212
- ".github/workflows/account.yml"
1313
- ".github/workflows/_deploy-container.yml"
1414
- ".github/workflows/_migrate-database.yml"
15-
- ".github/workflows/_preview-migrations.yml"
1615
- "!**.md"
1716
pull_request:
1817
paths:
@@ -23,7 +22,6 @@ on:
2322
- ".github/workflows/account.yml"
2423
- ".github/workflows/_deploy-container.yml"
2524
- ".github/workflows/_migrate-database.yml"
26-
- ".github/workflows/_preview-migrations.yml"
2725
- "!**.md"
2826
workflow_dispatch:
2927

@@ -93,32 +91,15 @@ jobs:
9391
# Generate a 512-bit key and set it as a user secret that can be use for token signing when running tests
9492
dotnet user-secrets set "authentication-token-signing-key" "$(openssl rand -base64 64)" --id $USER_SECRETS_ID
9593
96-
- name: Setup Java JDK for SonarScanner
97-
uses: actions/setup-java@v5
98-
with:
99-
distribution: "microsoft"
100-
java-version: "17"
101-
10294
- name: Build Email Templates
10395
working-directory: application
10496
run: npx turbo run build --filter=@repo/emails
10597

106-
- name: Run Tests with SonarScanner Analysis
98+
- name: Run Tests
10799
working-directory: application
108-
env:
109-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
110-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
111100
run: |
112-
if [[ "${{ vars.SONAR_PROJECT_KEY }}" == "" ]] || [[ "${{ vars.SONAR_ORGANIZATION }}" == "" ]] || [[ "${{ secrets.SONAR_TOKEN }}" == "" ]]; then
113-
echo "SonarCloud is not enabled. Skipping SonarCloud analysis."
114-
dotnet build account/Account.slnf --no-restore /p:Version=${{ steps.generate_version.outputs.version }} /p:DeploymentCommitHash=${{ github.event.pull_request.head.sha || github.sha }} /p:DeploymentGithubActionId=${{ github.run_id }} &&
115-
dotnet test account/Account.slnf --no-build
116-
else
117-
dotnet sonarscanner begin /k:"${{ vars.SONAR_PROJECT_KEY }}" /o:"${{ vars.SONAR_ORGANIZATION }}" /d:sonar.host.url="https://sonarcloud.io" &&
118-
dotnet build account/Account.slnf --no-restore /p:Version=${{ steps.generate_version.outputs.version }} /p:DeploymentCommitHash=${{ github.event.pull_request.head.sha || github.sha }} /p:DeploymentGithubActionId=${{ github.run_id }} &&
119-
dotnet test account/Account.slnf --no-build &&
120-
dotnet sonarscanner end
121-
fi
101+
dotnet build account/Account.slnf --no-restore /p:Version=${{ steps.generate_version.outputs.version }} /p:DeploymentCommitHash=${{ github.event.pull_request.head.sha || github.sha }} /p:DeploymentGithubActionId=${{ github.run_id }} &&
102+
dotnet test account/Account.slnf --no-build
122103
123104
- name: Save Backend Build Artifacts for Migration Plan
124105
if: ${{ vars.STAGING_CLUSTER_ENABLED == 'true' }}
@@ -149,7 +130,8 @@ jobs:
149130
if: ${{ steps.determine_deployment.outputs.deploy_staging == 'true' }}
150131
working-directory: application/account
151132
run: |
152-
dotnet publish ./Api/Account.Api.csproj --no-restore --configuration Release --output ./Api/publish /p:Version=${{ steps.generate_version.outputs.version }} /p:DeploymentCommitHash=${{ github.event.pull_request.head.sha || github.sha }} /p:DeploymentGithubActionId=${{ github.run_id }}
133+
dotnet publish ./Api/Account.Api.csproj --configuration Release --no-restore --output ./Api/publish /p:Version=${{ steps.generate_version.outputs.version }} /p:DeploymentCommitHash=${{ github.event.pull_request.head.sha || github.sha }} /p:DeploymentGithubActionId=${{ github.run_id }}
134+
153135
- name: Save API Artifacts
154136
if: ${{ steps.determine_deployment.outputs.deploy_staging == 'true' }}
155137
uses: actions/upload-artifact@v7
@@ -161,13 +143,15 @@ jobs:
161143
if: ${{ steps.determine_deployment.outputs.deploy_staging == 'true' }}
162144
working-directory: application/account
163145
run: |
164-
dotnet publish ./Workers/Account.Workers.csproj --no-restore --configuration Release --output ./Workers/publish /p:Version=${{ steps.generate_version.outputs.version }} /p:DeploymentCommitHash=${{ github.event.pull_request.head.sha || github.sha }} /p:DeploymentGithubActionId=${{ github.run_id }}
146+
dotnet publish ./Workers/Account.Workers.csproj --configuration Release --no-restore --output ./Workers/publish /p:Version=${{ steps.generate_version.outputs.version }} /p:DeploymentCommitHash=${{ github.event.pull_request.head.sha || github.sha }} /p:DeploymentGithubActionId=${{ github.run_id }}
147+
165148
- name: Save Workers Artifacts
166149
if: ${{ steps.determine_deployment.outputs.deploy_staging == 'true' }}
167150
uses: actions/upload-artifact@v7
168151
with:
169152
name: account-workers
170153
path: application/account/Workers/publish/**/*
154+
171155
database-migrations-stage:
172156
name: Database Staging
173157
if: ${{ vars.STAGING_CLUSTER_ENABLED == 'true' }}

.github/workflows/app-gateway.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
run: |
5252
deploy_staging="${{ github.ref == 'refs/heads/main' && vars.STAGING_CLUSTER_ENABLED == 'true' || (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'Deploy to Staging')) }}"
5353
echo "deploy_staging=$deploy_staging" >> $GITHUB_OUTPUT
54-
54+
5555
deploy_production="${{ github.ref == 'refs/heads/main' && vars.PRODUCTION_CLUSTER1_ENABLED == 'true' }}"
5656
echo "deploy_production=$deploy_production" >> $GITHUB_OUTPUT
5757
@@ -77,22 +77,40 @@ jobs:
7777
working-directory: application
7878
run: dotnet restore
7979

80+
- name: Generate and Set User Secret for Token Signing Key
81+
working-directory: application/shared-kernel/SharedKernel
82+
run: |
83+
# Extract UserSecretsId from the .csproj file
84+
USER_SECRETS_ID=$(grep -oP '(?<=<UserSecretsId>).*?(?=</UserSecretsId>)' SharedKernel.csproj)
85+
86+
# Generate a 512-bit key and set it as a user secret that can be use for token signing when running tests
87+
dotnet user-secrets set "authentication-token-signing-key" "$(openssl rand -base64 64)" --id $USER_SECRETS_ID
88+
89+
- name: Run Tests
90+
working-directory: application
91+
run: |
92+
dotnet build AppGateway.Tests/AppGateway.Tests.csproj --no-restore &&
93+
dotnet test AppGateway.Tests/AppGateway.Tests.csproj --no-build
94+
8095
- name: Build Backend Solution
8196
if: ${{ steps.determine_deployment.outputs.deploy_staging == 'true' }}
8297
working-directory: application
8398
run: |
8499
dotnet build PlatformPlatform.slnx --no-restore /p:Version=${{ steps.generate_version.outputs.version }} /p:DeploymentCommitHash=${{ github.event.pull_request.head.sha || github.sha }} /p:DeploymentGithubActionId=${{ github.run_id }}
100+
85101
- name: Publish Build
86102
if: ${{ steps.determine_deployment.outputs.deploy_staging == 'true' }}
87103
working-directory: application
88104
run: |
89-
dotnet publish ./AppGateway/AppGateway.csproj --no-restore --configuration Release --output ./AppGateway/publish /p:Version=${{ steps.generate_version.outputs.version }} /p:DeploymentCommitHash=${{ github.event.pull_request.head.sha || github.sha }} /p:DeploymentGithubActionId=${{ github.run_id }}
105+
dotnet publish ./AppGateway/AppGateway.csproj --configuration Release --no-restore --output ./AppGateway/publish /p:Version=${{ steps.generate_version.outputs.version }} /p:DeploymentCommitHash=${{ github.event.pull_request.head.sha || github.sha }} /p:DeploymentGithubActionId=${{ github.run_id }}
106+
90107
- name: Save Artifacts
91108
if: ${{ steps.determine_deployment.outputs.deploy_staging == 'true' }}
92109
uses: actions/upload-artifact@v7
93110
with:
94111
name: app-gateway
95112
path: application/AppGateway/publish/**/*
113+
96114
api-stage:
97115
name: Staging
98116
if: ${{ needs.build-and-test.outputs.deploy_staging == 'true' }}

.github/workflows/code-style.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ jobs:
137137
- name: Run Backend Linting
138138
working-directory: developer-cli
139139
run: |
140+
set -o pipefail
140141
dotnet run lint --backend ${{ needs.detect-scope.outputs.backend_scope }} --no-build | tee lint-output.log
141142
142143
if ! grep -q "No backend issues found!" lint-output.log; then
@@ -272,7 +273,13 @@ jobs:
272273
exit 0
273274
fi
274275
276+
# Run test assemblies sequentially via per-SCS slnf files. Running `dotnet test
277+
# PlatformPlatform.slnx` parallelizes test assemblies across processes, which races on
278+
# PortAllocation.Load() (`.workspace/port.txt` half-created between O_CREAT and write).
279+
# AppGateway.Tests is covered by app-gateway.yml. SharedKernel.Tests is included in both
280+
# slnf files and will run twice; that is acceptable.
275281
dotnet sonarscanner begin /k:"${{ vars.SONAR_PROJECT_KEY }}" /o:"${{ vars.SONAR_ORGANIZATION }}" /d:sonar.host.url="https://sonarcloud.io" &&
276282
dotnet build PlatformPlatform.slnx --no-restore &&
277-
dotnet test PlatformPlatform.slnx --no-build &&
283+
dotnet test account/Account.slnf --no-build &&
284+
dotnet test main/Main.slnf --no-build &&
278285
dotnet sonarscanner end

.github/workflows/developer-cli.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
- name: Run Code Linting
5252
working-directory: developer-cli
5353
run: |
54+
set -o pipefail
5455
dotnet run --no-build -- lint --cli --no-build | tee lint-output.log
5556
5657
if ! grep -q "No developer-cli issues found!" lint-output.log; then

.github/workflows/main.yml

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ on:
1212
- ".github/workflows/main.yml"
1313
- ".github/workflows/_deploy-container.yml"
1414
- ".github/workflows/_migrate-database.yml"
15-
- ".github/workflows/_preview-migrations.yml"
1615
- "!**.md"
1716
pull_request:
1817
paths:
@@ -23,7 +22,6 @@ on:
2322
- ".github/workflows/main.yml"
2423
- ".github/workflows/_deploy-container.yml"
2524
- ".github/workflows/_migrate-database.yml"
26-
- ".github/workflows/_preview-migrations.yml"
2725
- "!**.md"
2826
workflow_dispatch:
2927

@@ -89,36 +87,19 @@ jobs:
8987
run: |
9088
# Extract UserSecretsId from the .csproj file
9189
USER_SECRETS_ID=$(grep -oP '(?<=<UserSecretsId>).*?(?=</UserSecretsId>)' SharedKernel.csproj)
92-
90+
9391
# Generate a 512-bit key and set it as a user secret that can be use for token signing when running tests
9492
dotnet user-secrets set "authentication-token-signing-key" "$(openssl rand -base64 64)" --id $USER_SECRETS_ID
9593
96-
- name: Setup Java JDK for SonarScanner
97-
uses: actions/setup-java@v5
98-
with:
99-
distribution: "microsoft"
100-
java-version: "17"
101-
10294
- name: Build Email Templates
10395
working-directory: application
10496
run: npx turbo run build --filter=@repo/emails
10597

106-
- name: Run Tests with SonarScanner Analysis
98+
- name: Run Tests
10799
working-directory: application
108-
env:
109-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
110-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
111100
run: |
112-
if [[ "${{ vars.SONAR_PROJECT_KEY }}" == "" ]] || [[ "${{ vars.SONAR_ORGANIZATION }}" == "" ]] || [[ "${{ secrets.SONAR_TOKEN }}" == "" ]]; then
113-
echo "SonarCloud is not enabled. Skipping SonarCloud analysis."
114-
dotnet build main/Main.slnf --no-restore /p:Version=${{ steps.generate_version.outputs.version }} /p:DeploymentCommitHash=${{ github.event.pull_request.head.sha || github.sha }} /p:DeploymentGithubActionId=${{ github.run_id }} &&
115-
dotnet test main/Main.slnf --no-build
116-
else
117-
dotnet sonarscanner begin /k:"${{ vars.SONAR_PROJECT_KEY }}" /o:"${{ vars.SONAR_ORGANIZATION }}" /d:sonar.host.url="https://sonarcloud.io" &&
118-
dotnet build main/Main.slnf --no-restore /p:Version=${{ steps.generate_version.outputs.version }} /p:DeploymentCommitHash=${{ github.event.pull_request.head.sha || github.sha }} /p:DeploymentGithubActionId=${{ github.run_id }} &&
119-
dotnet test main/Main.slnf --no-build &&
120-
dotnet sonarscanner end
121-
fi
101+
dotnet build main/Main.slnf --no-restore /p:Version=${{ steps.generate_version.outputs.version }} /p:DeploymentCommitHash=${{ github.event.pull_request.head.sha || github.sha }} /p:DeploymentGithubActionId=${{ github.run_id }} &&
102+
dotnet test main/Main.slnf --no-build
122103
123104
- name: Save Backend Build Artifacts for Migration Plan
124105
if: ${{ vars.STAGING_CLUSTER_ENABLED == 'true' }}
@@ -144,7 +125,8 @@ jobs:
144125
if: ${{ steps.determine_deployment.outputs.deploy_staging == 'true' }}
145126
working-directory: application/main
146127
run: |
147-
dotnet publish ./Api/Main.Api.csproj --no-restore --configuration Release --output ./Api/publish /p:Version=${{ steps.generate_version.outputs.version }} /p:DeploymentCommitHash=${{ github.event.pull_request.head.sha || github.sha }} /p:DeploymentGithubActionId=${{ github.run_id }}
128+
dotnet publish ./Api/Main.Api.csproj --configuration Release --no-restore --output ./Api/publish /p:Version=${{ steps.generate_version.outputs.version }} /p:DeploymentCommitHash=${{ github.event.pull_request.head.sha || github.sha }} /p:DeploymentGithubActionId=${{ github.run_id }}
129+
148130
- name: Save API Artifacts
149131
if: ${{ steps.determine_deployment.outputs.deploy_staging == 'true' }}
150132
uses: actions/upload-artifact@v7
@@ -156,13 +138,15 @@ jobs:
156138
if: ${{ steps.determine_deployment.outputs.deploy_staging == 'true' }}
157139
working-directory: application/main
158140
run: |
159-
dotnet publish ./Workers/Main.Workers.csproj --no-restore --configuration Release --output ./Workers/publish /p:Version=${{ steps.generate_version.outputs.version }} /p:DeploymentCommitHash=${{ github.event.pull_request.head.sha || github.sha }} /p:DeploymentGithubActionId=${{ github.run_id }}
141+
dotnet publish ./Workers/Main.Workers.csproj --configuration Release --no-restore --output ./Workers/publish /p:Version=${{ steps.generate_version.outputs.version }} /p:DeploymentCommitHash=${{ github.event.pull_request.head.sha || github.sha }} /p:DeploymentGithubActionId=${{ github.run_id }}
142+
160143
- name: Save Workers Artifacts
161144
if: ${{ steps.determine_deployment.outputs.deploy_staging == 'true' }}
162145
uses: actions/upload-artifact@v7
163146
with:
164147
name: main-workers
165148
path: application/main/Workers/publish/**/*
149+
166150
database-migrations-stage:
167151
name: Database Staging
168152
if: ${{ vars.STAGING_CLUSTER_ENABLED == 'true' }}

0 commit comments

Comments
 (0)