Skip to content

Commit c928dcd

Browse files
authored
Merge pull request #5445 from dfe-analytical-services/ees-5396
EES-5396 Sync public API OpenAPI changes with API docs
2 parents a38edd6 + baa94af commit c928dcd

File tree

17 files changed

+322
-87
lines changed

17 files changed

+322
-87
lines changed

.config/dotnet-tools.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@
66
"version": "8.0.7",
77
"commands": [
88
"dotnet-ef"
9-
]
9+
],
10+
"rollForward": false
11+
},
12+
"swashbuckle.aspnetcore.cli": {
13+
"version": "7.1.0",
14+
"commands": [
15+
"swagger"
16+
],
17+
"rollForward": false
1018
}
1119
}
1220
}

azure-pipelines-main.yml

+96-32
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ variables:
1111
BuildConfiguration: Release
1212
IsBranchDeployable: ${{ containsValue(parameters.DeployBranches, variables['Build.SourceBranchName']) }}
1313
CI: true
14+
DotNetVersion: '8.0.x'
1415
NodeVersion: '20.16.0'
1516
RubyVersion: '3.2'
1617
AcrServiceConnection: s101d-datahub-spn-ees-dfe-gov-uk-docker-managed-service-connection
18+
PublicApiDir: GovUk.Education.ExploreEducationStatistics.Public.Data.Api
19+
PublicApiDocsDir: explore-education-statistics-api-docs
1720

1821
trigger:
1922
branches:
@@ -31,36 +34,28 @@ pr:
3134
- test
3235

3336
jobs:
34-
- job: Backend
35-
pool: ees-ubuntu2204-xlarge
37+
- job: BackendVerify
38+
pool: ees-ubuntu2204-large
3639
workspace:
3740
clean: all
3841
steps:
3942
- task: UseDotNet@2
40-
displayName: Install .NET 8.0 SDK
43+
displayName: Install .NET $(DotNetVersion)
4144
inputs:
42-
version: 8.0.x
45+
version: $(DotNetVersion)
4346
performMultiLevelLookup: true
4447

45-
- task: DotNetCoreCLI@2
46-
displayName: Build
47-
inputs:
48-
projects: |
49-
**/GovUk.*/*csproj
50-
!**/GovUk.Education.ExploreEducationStatistics.Admin/*csproj
51-
arguments: --configuration $(BuildConfiguration)
52-
5348
# TODO: Uncomment this step once formatter has been run globally.
5449
# This is because whitespace rules cannot be warnings or suggestions; they will always be errors
5550
# - task: DotNetCoreCLI@2
56-
# displayName:'Verify Formatting and Style
51+
# displayName: Verify formatting
5752
# inputs:
5853
# command: custom
5954
# custom: format whitespace src/GovUk.Education.ExploreEducationStatistics.sln --verify-no-changes --severity error
6055
# arguments: --verify-no-changes --verbosity diagnostic
6156

6257
- task: DotNetCoreCLI@2
63-
displayName: Verify Formatting and Style
58+
displayName: Verify style
6459
inputs:
6560
command: custom
6661
custom: format
@@ -69,15 +64,45 @@ jobs:
6964
projects: src/GovUk.Education.ExploreEducationStatistics.sln
7065

7166
- task: DotNetCoreCLI@2
72-
displayName: Verify Formatting and Style
67+
displayName: Verify analyzers
7368
inputs:
7469
command: custom
7570
custom: format
7671
## TODO: Remove "--severity error" once work has been done to resolve build warnings (https://dfedigital.atlassian.net/browse/EES-4594).
7772
arguments: analyzers --verify-no-changes --verbosity diagnostic --severity error
7873
projects: src/GovUk.Education.ExploreEducationStatistics.sln
7974

80-
# TODO: Wrap these ^ three tasks up into a single `dotnet format` task once all 3 above TODOs are TO-DONE ;)
75+
# TODO: Wrap the above three tasks up into a single `dotnet format` task once all TODOs are done
76+
77+
- task: DotNetCoreCLI@2
78+
displayName: Build Public API
79+
inputs:
80+
projects: '**/GovUk.Education.ExploreEducationStatistics.Public.Data.Api.csproj'
81+
arguments: --configuration $(BuildConfiguration)
82+
83+
- task: Bash@3
84+
displayName: Diff Public API OpenAPI docs
85+
inputs:
86+
targetType: inline
87+
script: |
88+
docker run --rm -t \
89+
-v $(System.DefaultWorkingDirectory)/src/$(PublicApiDir)/bin/$(BuildConfiguration)/net8.0:/api \
90+
-v $(System.DefaultWorkingDirectory)/src/$(PublicApiDocsDir):/api-docs \
91+
-v $(System.DefaultWorkingDirectory)/ci/scripts:/scripts \
92+
--entrypoint /bin/sh \
93+
tufin/oasdiff \
94+
/scripts/public-api-openapi-diff.sh
95+
96+
- job: BackendTest
97+
pool: ees-ubuntu2204-xlarge
98+
workspace:
99+
clean: all
100+
steps:
101+
- task: UseDotNet@2
102+
displayName: Install .NET $(DotNetVersion)
103+
inputs:
104+
version: $(DotNetVersion)
105+
performMultiLevelLookup: true
81106

82107
- task: DotNetCoreCLI@2
83108
displayName: Test
@@ -88,6 +113,16 @@ jobs:
88113
!**/GovUk.Education.ExploreEducationStatistics.Admin.Tests/*csproj
89114
arguments: --configuration $(BuildConfiguration)
90115

116+
- job: BackendPublish
117+
pool:
118+
vmImage: ubuntu-22.04
119+
steps:
120+
- task: UseDotNet@2
121+
displayName: Install .NET $(DotNetVersion)
122+
inputs:
123+
version: $(DotNetVersion)
124+
performMultiLevelLookup: true
125+
91126
- task: DotNetCoreCLI@2
92127
displayName: Package Data API
93128
inputs:
@@ -97,8 +132,9 @@ jobs:
97132
arguments: --self-contained true -r win-x64 --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)/data-api
98133
zipAfterPublish: True
99134

100-
- task: PublishPipelineArtifact@0
135+
- task: PublishPipelineArtifact@1
101136
displayName: Publish Data API artifact
137+
condition: and(succeeded(), eq(variables.IsBranchDeployable, true))
102138
inputs:
103139
artifactName: data-api
104140
targetPath: $(Build.ArtifactStagingDirectory)/data-api
@@ -112,8 +148,9 @@ jobs:
112148
arguments: --self-contained true -r win-x64 --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)/content-api
113149
zipAfterPublish: True
114150

115-
- task: PublishPipelineArtifact@0
151+
- task: PublishPipelineArtifact@1
116152
displayName: Publish Content API artifact
153+
condition: and(succeeded(), eq(variables.IsBranchDeployable, true))
117154
inputs:
118155
artifactName: content-api
119156
targetPath: $(Build.ArtifactStagingDirectory)/content-api
@@ -126,7 +163,6 @@ jobs:
126163
projects: '**/GovUk.Education.ExploreEducationStatistics.Public.Data.Api.csproj'
127164
arguments: -r linux-musl-x64 --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)/public-api
128165
zipAfterPublish: False
129-
130166
- task: Docker@2
131167
displayName: Build Public API Docker image
132168
condition: and(succeeded(), eq(variables.IsBranchDeployable, true))
@@ -160,8 +196,9 @@ jobs:
160196
arguments: --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)/public-api-data-processor
161197
zipAfterPublish: True
162198

163-
- task: PublishPipelineArtifact@0
199+
- task: PublishPipelineArtifact@1
164200
displayName: Publish Public API Data Processor artifact
201+
condition: and(succeeded(), eq(variables.IsBranchDeployable, true))
165202
inputs:
166203
artifactName: public-api-data-processor
167204
targetPath: $(Build.ArtifactStagingDirectory)/public-api-data-processor
@@ -175,8 +212,9 @@ jobs:
175212
arguments: --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)/notifier
176213
zipAfterPublish: True
177214

178-
- task: PublishPipelineArtifact@0
215+
- task: PublishPipelineArtifact@1
179216
displayName: Publish Notifier artifact
217+
condition: and(succeeded(), eq(variables.IsBranchDeployable, true))
180218
inputs:
181219
artifactName: notifier
182220
targetPath: $(Build.ArtifactStagingDirectory)/notifier
@@ -190,8 +228,9 @@ jobs:
190228
arguments: --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)/publisher
191229
zipAfterPublish: True
192230

193-
- task: PublishPipelineArtifact@0
231+
- task: PublishPipelineArtifact@1
194232
displayName: Publish Publisher artifact
233+
condition: and(succeeded(), eq(variables.IsBranchDeployable, true))
195234
inputs:
196235
artifactName: publisher
197236
targetPath: $(Build.ArtifactStagingDirectory)/publisher
@@ -205,8 +244,9 @@ jobs:
205244
arguments: --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)/processor
206245
zipAfterPublish: True
207246

208-
- task: PublishPipelineArtifact@0
247+
- task: PublishPipelineArtifact@1
209248
displayName: Publish Processor artifact
249+
condition: and(succeeded(), eq(variables.IsBranchDeployable, true))
210250
inputs:
211251
artifactName: processor
212252
targetPath: $(Build.ArtifactStagingDirectory)/processor
@@ -229,9 +269,9 @@ jobs:
229269
script: corepack enable
230270

231271
- task: UseDotNet@2
232-
displayName: Install .NET 8.0 SDK
272+
displayName: Install .NET $(DotNetVersion)
233273
inputs:
234-
version: 8.0.x
274+
version: $(DotNetVersion)
235275
performMultiLevelLookup: true
236276

237277
- task: DotNetCoreCLI@2
@@ -267,13 +307,15 @@ jobs:
267307

268308
- task: DotNetCoreCLI@2
269309
displayName: Package Admin app
310+
condition: and(succeeded(), eq(variables.IsBranchDeployable, true))
270311
inputs:
271312
command: publish
272313
publishWebProjects: false
273314
projects: '**/GovUk.Education.ExploreEducationStatistics.Admin.csproj'
274315
arguments: --self-contained true -r win-x64 --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)
275316

276-
- task: PublishPipelineArtifact@0
317+
- task: PublishPipelineArtifact@1
318+
condition: and(succeeded(), eq(variables.IsBranchDeployable, true))
277319
displayName: Publish Admin artifact
278320
inputs:
279321
artifactName: admin
@@ -387,22 +429,44 @@ jobs:
387429
inputs:
388430
versionSpec: '>= $(RubyVersion)'
389431

432+
- task: Cache@2
433+
displayName: Cache Gems
434+
inputs:
435+
key: 'gems | "$(Agent.OS)" | $(WorkingDirectory)/Gemfile.lock'
436+
path: $(WorkingDirectory)/vendor
437+
restoreKeys: |
438+
gems | "$(Agent.OS)"
439+
gems
440+
441+
- task: Bash@3
442+
displayName: Set deployment config
443+
inputs:
444+
workingDirectory: $(WorkingDirectory)
445+
targetType: inline
446+
script: bundle config set deployment true
447+
448+
- task: Bash@3
449+
displayName: Install Gems
450+
inputs:
451+
workingDirectory: $(WorkingDirectory)
452+
targetType: inline
453+
script: bundle install
454+
390455
- task: Bash@3
391456
displayName: Build
392-
env:
393-
TECH_DOCS_API_URL: https://dev.statistics.api.education.gov.uk
394457
inputs:
395458
workingDirectory: $(WorkingDirectory)
396459
targetType: inline
397-
script: |
398-
bundle install
460+
script: |
399461
bundle exec middleman build
462+
# Remove afterwards as we don't want it in the artifact
463+
rm -rf build
400464
401465
- task: PublishPipelineArtifact@1
402-
displayName: Publish artifact
466+
displayName: Publish Public API docs artifact
403467
inputs:
404468
artifactName: public-api-docs
405-
targetPath: $(WorkingDirectory)/build
469+
targetPath: $(System.DefaultWorkingDirectory)/src/$(PublicApiDocsDir)
406470

407471
- job: MiscellaneousArtifacts
408472
pool:

ci/scripts/public-api-openapi-diff.sh

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#/usr/bin/env sh
2+
3+
set -u
4+
5+
# This script should be run from inside the oasdiff Docker container.
6+
# It checks for any undocumented changes in the public API.
7+
8+
has_undocumented_changes=false
9+
10+
for file in /api-docs/source/openapi-v*.json; do
11+
filename=$(basename $file)
12+
13+
echo "Checking $filename"
14+
oasdiff changelog --flatten-allof -o INFO $file /api/wwwroot/$filename
15+
16+
if [ $? != 0 ]; then
17+
has_undocumented_changes=true
18+
19+
cat <<- EOF
20+
ERROR: There were changes that must be documented in the public API docs.
21+
22+
To document these changes, you must update 'src/explore-education-statistics-api-docs/source/$filename'
23+
by copying the changes from the OpenAPI endpoint when running the public API locally.
24+
25+
The OpenAPI endpoint locally is: http://localhost:5050/$filename
26+
27+
You should ensure that these changes are expected. If there are error level changes reported above, this
28+
means there are breaking changes that are being introduced. If these changes are intentional, you should:
29+
30+
1. Create a new major API version in the public API project.
31+
2. Create a new 'openapi-v*.json' for the major version in the public API docs.
32+
3. Document the major version and its breaking changes in the public API docs (e.g. in a changelog).
33+
4. Review any existing API documentation and update accordingly.
34+
5. Deprecate the previous API version when appropriate.
35+
36+
Consult the following DevOps wiki page for more information:
37+
https://dfe-gov-uk.visualstudio.com.mcas.ms/s101-Explore-Education-Statistics/_wiki/wikis/s101-Explore-Education-Statistics.wiki/9070
38+
EOF
39+
fi
40+
done || true
41+
42+
if $has_undocumented_changes; then
43+
exit 1
44+
fi
45+
46+
has_undocumented_version=false
47+
48+
# Check there isn't an undocumented API version
49+
for file in /api/wwwroot/openapi-v*.json; do
50+
filename=$(basename $file)
51+
52+
if [ ! -f "/api-docs/source/$filename" ]; then
53+
has_undocumented_version=true
54+
echo "ERROR: $filename is required in the public API docs"
55+
fi
56+
done
57+
58+
if $has_undocumented_version; then
59+
exit 1
60+
fi

infrastructure/templates/public-api/application/public-api/publicApiApp.bicep

+7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ param resourceAndScalingConfig ContainerAppResourceConfig
3636
@description('Whether to create or update Azure Monitor alerts during this deploy')
3737
param deployAlerts bool
3838

39+
@description('Enable the Swagger UI')
40+
param enableSwagger bool
41+
3942
@description('Specifies a set of tags with which to tag the resource in Azure.')
4043
param tagValues object
4144

@@ -113,6 +116,10 @@ module apiContainerAppModule '../../components/containerApp.bicep' = {
113116
name: 'App__Url'
114117
value: publicApiUrl
115118
}
119+
{
120+
name: 'App__EnableSwagger'
121+
value: enableSwagger ? 'true' : 'false'
122+
}
116123
{
117124
name: 'AppInsights__ConnectionString'
118125
value: appInsightsConnectionString

0 commit comments

Comments
 (0)