From 30ce0852f84fa5a215f29a88612c0aa2739a48eb Mon Sep 17 00:00:00 2001 From: Nicholas Tsim Date: Thu, 12 Dec 2024 23:37:46 +0000 Subject: [PATCH] fixup! EES-5396 Update public API docs to use generated OpenAPI docs when deploying --- azure-pipelines-main.yml | 40 ++++++++++++++----- .../public-api/ci/jobs/deploy-api-docs.yml | 8 +++- .../config.rb | 3 +- .../lib/utils/env.rb | 13 ++++++ 4 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 src/explore-education-statistics-api-docs/lib/utils/env.rb diff --git a/azure-pipelines-main.yml b/azure-pipelines-main.yml index 1ee7ca5a90d..0c0c2222c63 100644 --- a/azure-pipelines-main.yml +++ b/azure-pipelines-main.yml @@ -320,7 +320,7 @@ jobs: projects: '**/GovUk.Education.ExploreEducationStatistics.Admin.csproj' arguments: --self-contained true -r win-x64 --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory) - - task: PublishPipelineArtifact@0 + - task: PublishPipelineArtifact@1 condition: and(succeeded(), eq(variables.IsBranchDeployable, true)) displayName: Publish Admin artifact inputs: @@ -423,6 +423,7 @@ jobs: workspace: clean: all variables: + BUNDLE_PATH: $(Pipeline.Workspace)/.bundle WorkingDirectory: src/explore-education-statistics-api-docs steps: - task: UseNode@1 @@ -435,23 +436,40 @@ jobs: inputs: versionSpec: '>= $(RubyVersion)' + - task: Cache@2 + displayName: Cache Gems + inputs: + key: 'gems | "$(Agent.OS)" | $(WorkingDirectory)/Gemfile.lock' + path: $(BUNDLE_PATH) + restoreKeys: | + gems | "$(Agent.OS)" + gems + - task: Bash@3 - displayName: Build - env: - TECH_DOCS_API_URL: https://dev.statistics.api.education.gov.uk + displayName: Install Gems inputs: workingDirectory: $(WorkingDirectory) targetType: inline - script: | - bundle install - bundle exec middleman build + script: bundle install + - task: Bash@3 + displayName: Build + inputs: + workingDirectory: $(WorkingDirectory) + targetType: inline + script: bundle exec middleman build + + # Note that we're not publishing the built API docs as an artifact as + # we're to re-building the API docs for each environment during + # the deployment stages so we can inject different env variables. + # + # We're still building the API docs so that we can get earlier + # feedback on any build errors at PR stage. - task: PublishPipelineArtifact@1 - displayName: Publish artifact + displayName: Publish Public API docs gems artifact inputs: - artifactName: public-api-docs - targetPath: $(WorkingDirectory)/build - + artifactName: public-api-docs-gems + path: $(BUNDLE_PATH) - job: MiscellaneousArtifacts pool: diff --git a/infrastructure/templates/public-api/ci/jobs/deploy-api-docs.yml b/infrastructure/templates/public-api/ci/jobs/deploy-api-docs.yml index 05ccfac61d6..db5ee8b9523 100644 --- a/infrastructure/templates/public-api/ci/jobs/deploy-api-docs.yml +++ b/infrastructure/templates/public-api/ci/jobs/deploy-api-docs.yml @@ -16,6 +16,7 @@ jobs: docsPath: $(Pipeline.Workspace)/MainBuild/public-api-docs nodeVersion: '20.16.0' rubyVersion: '3.2' + BUNDLE_PATH: $(Pipeline.Workspace)/MainBuild/public-api-docs-gems strategy: runOnce: deploy: @@ -24,6 +25,10 @@ jobs: displayName: Download Public API docs artifact artifact: public-api-docs + - download: MainBuild + displayName: Download Public API docs gems artifact + artifact: public-api-docs-gems + - task: UseNode@1 displayName: Install Node.js $(nodeVersion) inputs: @@ -44,7 +49,8 @@ jobs: - task: Bash@3 displayName: Build API docs env: - TECH_DOCS_API_URL: $(publicApiUrl) + TECH_DOCS_API_URL: $(apiAppUrl) + TECH_DOCS_ALLOW_INDEXING: $(docsPreventIndexing) inputs: workingDirectory: $(docsPath) targetType: inline diff --git a/src/explore-education-statistics-api-docs/config.rb b/src/explore-education-statistics-api-docs/config.rb index a8c3f0fdd16..709f96569be 100644 --- a/src/explore-education-statistics-api-docs/config.rb +++ b/src/explore-education-statistics-api-docs/config.rb @@ -1,5 +1,6 @@ require 'dotenv' require 'govuk_tech_docs' +require 'lib/utils/env' require 'lib/api_reference_pages_extension' require 'lib/helpers' require 'lib/api_reference_helpers' @@ -19,7 +20,7 @@ end if ENV.has_key?("TECH_DOCS_PREVENT_INDEXING") - config[:tech_docs][:prevent_indexing] = ENV["TECH_DOCS_PREVENT_INDEXING"] + config[:tech_docs][:prevent_indexing] = EnvUtils.get_bool("TECH_DOCS_PREVENT_INDEXING") end if ENV.has_key?("TECH_DOCS_API_URL") diff --git a/src/explore-education-statistics-api-docs/lib/utils/env.rb b/src/explore-education-statistics-api-docs/lib/utils/env.rb new file mode 100644 index 00000000000..f1c54f3ab6c --- /dev/null +++ b/src/explore-education-statistics-api-docs/lib/utils/env.rb @@ -0,0 +1,13 @@ +class EnvUtils + + # @param [String] key + # @return [Boolean] + def self.get_bool(key) + case ENV[key] + when "false", "f", "no", "n", "0", "" + false + else + true + end + end +end