Skip to content

Commit

Permalink
Merge pull request #513 from DFE-Digital/next
Browse files Browse the repository at this point in the history
feat: Details component, and schema deployment hardening
  • Loading branch information
Maria-C1 authored Sep 19, 2024
2 parents 0c443a4 + c260032 commit 9ec3638
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 102 deletions.
53 changes: 35 additions & 18 deletions .github/workflows/contentful-schema-migrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@ on:
inputs:
target_environment:
required: true
type: string

env:
MANAGEMENT_TOKEN: ${{ secrets.CONTENTFUL_MANAGEMENT_TOKEN }}
DELIVERY_KEY: ${{ secrets.TF_VAR_CPD_DELIVERY_KEY }}
SPACE_ID: ${{ secrets.TF_VAR_CPD_SPACE_ID }}
ENVIRONMENT: ${{ inputs.target_environment }}
SPACE_CAPACITY: ${{ vars.CONTENTFUL_SPACE_CAPACITY }}
default: 'dev'
type: choice
options:
- dev
- test
- prod

jobs:
setup:
runs-on: ubuntu-latest
environment: ${{inputs.target_environment}}

env:
MANAGEMENT_TOKEN: ${{ secrets.CONTENTFUL_MANAGEMENT_TOKEN }}
DELIVERY_KEY: ${{ secrets.TF_VAR_CPD_DELIVERY_KEY }}
ENVIRONMENT: ${{ inputs.target_environment == 'prod' && 'master' || inputs.target_environment }}
SPACE_CAPACITY: ${{ vars.CONTENTFUL_SPACE_CAPACITY }}
SPACE_ID: ${{ secrets.TF_VAR_CPD_SPACE_ID }}

outputs:
staging-environment: ${{ steps.staging-env.outputs.staging-environment }}
Expand All @@ -33,21 +39,21 @@ jobs:
working-directory: ./Contentful-Schema
run: npm ci

- name: Verify contentful space has available environment capacity
working-directory: ./Contentful-Schema/utils
run: node verify-space-capacity.js

- name: Get target environment current migration version
id: current-migration-version
working-directory: ./Contentful-Schema/utils
run: node get-environment-version.js

- name: Verify contentful space has available environment capacity
working-directory: ./Contentful-Schema/utils
run: node verify-space-capacity.js

- name: Determine timestamp for new staging environment
run: echo "TIMESTAMP=$(date +%Y-%m-%d-%H-%M-%S)" >> $GITHUB_ENV

- name: Set var for name of new environment
id: staging-env
run: echo "staging-environment=$(echo ${{ inputs.target_environment }}-${{ env.TIMESTAMP }})" >> $GITHUB_OUTPUT
run: echo "staging-environment=$(echo ${{ inputs.target_environment == 'prod' && 'master' || inputs.target_environment }}-${{ env.TIMESTAMP }})" >> $GITHUB_OUTPUT

- name: Extract migration files from archive
working-directory: ./Contentful-Schema/migrations
Expand All @@ -66,19 +72,23 @@ jobs:
if: ${{ join(needs.setup.outputs.required-migrations, '') != '[]' }}
needs: [setup]
runs-on: ubuntu-latest
steps:

env:
MANAGEMENT_TOKEN: ${{ secrets.CONTENTFUL_MANAGEMENT_TOKEN }}
SPACE_ID: ${{ secrets.TF_VAR_CPD_SPACE_ID }}

steps:
- name: Install Contentful CLI
run: npm install -g contentful-cli

- name: Login to Contentful with management token
run: contentful login --management-token "${{ env.MANAGEMENT_TOKEN }}"

- name: Set target space
run: contentful space use --space-id ${{ env.SPACE_ID }} --environment-id ${{ inputs.target_environment }}
run: contentful space use --space-id ${{ env.SPACE_ID }} --environment-id ${{ inputs.target_environment == 'prod' && 'master' || inputs.target_environment }}

- name: Clone target environment ${{ inputs.target_environment }} to staging environment ${{ needs.setup.outputs.staging-environment }}
run: contentful space environment create --name ${{ needs.setup.outputs.staging-environment }} --environment-id ${{ needs.setup.outputs.staging-environment }} --source ${{ inputs.target_environment }}
- name: Clone target environment ${{ inputs.target_environment == 'prod' && 'master' || inputs.target_environment }} to staging environment ${{ needs.setup.outputs.staging-environment }}
run: contentful space environment create --name ${{ needs.setup.outputs.staging-environment }} --environment-id ${{ needs.setup.outputs.staging-environment }} --source ${{ inputs.target_environment == 'prod' && 'master' || inputs.target_environment }}

migrate:
if: ${{ join(needs.setup.outputs.required-migrations, '') != '[]' }}
Expand All @@ -89,6 +99,10 @@ jobs:
matrix:
value: ${{fromJSON(needs.setup.outputs.required-migrations)}}

env:
MANAGEMENT_TOKEN: ${{ secrets.CONTENTFUL_MANAGEMENT_TOKEN }}
SPACE_ID: ${{ secrets.TF_VAR_CPD_SPACE_ID }}

steps:
- uses: actions/checkout@v3

Expand Down Expand Up @@ -124,6 +138,9 @@ jobs:
runs-on: ubuntu-latest
env:
STAGING_ENVIRONMENT: ${{ needs.setup.outputs.staging-environment }}
MANAGEMENT_TOKEN: ${{ secrets.CONTENTFUL_MANAGEMENT_TOKEN }}
ENVIRONMENT: ${{ inputs.target_environment == 'prod' && 'master' || inputs.target_environment }}
SPACE_ID: ${{ secrets.TF_VAR_CPD_SPACE_ID }}

steps:
- uses: actions/checkout@v3
Expand All @@ -136,6 +153,6 @@ jobs:
working-directory: ./Contentful-Schema
run: npm ci

- name: Run script to point alias ${{ inputs.target_environment }} at new environment ${{ env.STAGING_ENVIRONMENT }}
- name: Run script to point alias ${{ inputs.target_environment == 'prod' && 'master' || inputs.target_environment }} at new environment ${{ env.STAGING_ENVIRONMENT }}
working-directory: ./Contentful-Schema/utils
run: node point-alias-at-environment.js
128 changes: 65 additions & 63 deletions .github/workflows/sonarqube.yml
Original file line number Diff line number Diff line change
@@ -1,66 +1,68 @@
name: Static code analysis
on:
pull_request:
branches:
- main
- next
jobs:
code-analysis:
name: Static code analysis
on:
pull_request:
branches:
- main
- next
jobs:
code-analysis:
name: Static code analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu' # Alternative distribution options are available.

- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v3
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Cache SonarCloud coverage
id: cache-sonar-coverage
uses: actions/cache@v3
with:
path: ~\sonar\cache
key: ${{ runner.os }}-coverage
restore-keys: ${{ runner.os }}-coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install SonarCloud scanners
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
run: dotnet tool install --global dotnet-sonarscanner

- name: Install SonarCloud coverage
if: steps.cache-sonar-coverage.outputs.cache-hit != 'true'
run: dotnet tool install --global dotnet-coverage
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: "zulu" # Alternative distribution options are available.

- name: Build, Test and Analyze
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
dotnet-sonarscanner begin \
/k:"DFE-Digital_childrens-social-care-cpd" \
/o:"dfe-digital" \
/d:sonar.qualitygate.wait=true \
/d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml \
/d:sonar.exclusions="**/*.css,**/*.scss,**/Models/*,**/Program.cs,**/WebApplicationBuilderExtensions.cs,**/GraphQL/Queries/*" \
/d:sonar.test.exclusions="Childrens-Social-Care-CPD-Tests/**/*" \
/d:sonar.token="${{ secrets.SONAR_TOKEN }}" \
/d:sonar.host.url="https://sonarcloud.io"
dotnet build --no-incremental
dotnet-coverage collect --settings dotnet-cover-config.xml -f xml -o coverage.xml "dotnet test"
dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
- name: Cache SonarCloud packages
uses: actions/cache@v1
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v3
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Cache SonarCloud coverage
id: cache-sonar-coverage
uses: actions/cache@v3
with:
path: ~\sonar\cache
key: ${{ runner.os }}-coverage
restore-keys: ${{ runner.os }}-coverage

- name: Install SonarCloud scanners
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
run: dotnet tool install --global dotnet-sonarscanner

- name: Install SonarCloud coverage
if: steps.cache-sonar-coverage.outputs.cache-hit != 'true'
run: dotnet tool install --global dotnet-coverage

- name: Build, Test and Analyze
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
dotnet-sonarscanner begin \
/k:"DFE-Digital_childrens-social-care-cpd" \
/o:"dfe-digital" \
/d:sonar.qualitygate.wait=true \
/d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml \
/d:sonar.exclusions="**/*.css,**/*.scss,**/Models/*,**/Program.cs,**/WebApplicationBuilderExtensions.cs,**/GraphQL/Queries/*,**/Contentful-Schema/migrations/*.cjs" \
/d:sonar.test.exclusions="Childrens-Social-Care-CPD-Tests/**/*" \
/d:sonar.token="${{ secrets.SONAR_TOKEN }}" \
/d:sonar.host.url="https://sonarcloud.io"
dotnet build --no-incremental
dotnet-coverage collect --settings dotnet-cover-config.xml -f xml -o coverage.xml "dotnet test"
dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class EntityResolverTests
[TestCase("contentSeparator", typeof(ContentSeparator))]
[TestCase("detailedPathway", typeof(DetailedPathway))]
[TestCase("detailedRole", typeof(DetailedRole))]
[TestCase("details", typeof(Details))]
[TestCase("feedback", typeof(Feedback))]
[TestCase("heroBanner", typeof(HeroBanner))]
[TestCase("imageCard", typeof(ImageCard))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public partial class PartialsFactoryTests
new object[] { new ContentsAnchor(), "_ContentsAnchor" },
new object[] { new DetailedPathway(), "_DetailedPathway" },
new object[] { new DetailedRole(), "_DetailedRole" },
new object[] { new Details(), "_Details" },
new object[] { new Feedback(), "_Feedback" },
new object[] { new HeroBanner(), string.Empty },
new object[] { new LinkCard(), "_LinkCard" },
Expand Down
1 change: 1 addition & 0 deletions Childrens-Social-Care-CPD/Contentful/EntityResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public Type Resolve(string contentTypeId)
"contentSeparator" => typeof(ContentSeparator),
"detailedPathway" => typeof(DetailedPathway),
"detailedRole" => typeof(DetailedRole),
"details" => typeof(Details),
"feedback" => typeof(Feedback),
"heroBanner" => typeof(HeroBanner),
"imageCard" => typeof(ImageCard),
Expand Down
9 changes: 9 additions & 0 deletions Childrens-Social-Care-CPD/Contentful/Models/Details.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Contentful.Core.Models;

namespace Childrens_Social_Care_CPD.Contentful.Models;

public class Details : IContent
{
public string SummaryText { get; set; }
public Document DetailsText { get; set; }
}
1 change: 1 addition & 0 deletions Childrens-Social-Care-CPD/Contentful/PartialsFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static string GetPartialFor(IContent item)
ContentsAnchor => "_ContentsAnchor",
DetailedRole => "_DetailedRole",
DetailedPathway => "_DetailedPathway",
Details => "_Details",
Feedback => "_Feedback",
HeroBanner => string.Empty,// skip - handled in specific layout section
ImageCard => "_ImageCard",
Expand Down
6 changes: 3 additions & 3 deletions Childrens-Social-Care-CPD/Views/Shared/_AudioResource.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
@if (Model.Transcript.Content != null)
{
<details class="govuk-details govuk-!-margin-top-3" data-module="govuk-details">
<summary class="govuk-details__summary"> <span class="govuk-details__summary-text">View transcript </span></summary>
<summary class="govuk-details__summary"> <span class="govuk-details__summary-text">View transcript </span>
</summary>
<div class="govuk-details__text">
@{
await Html.RenderPartialAsync("_RichText", Model.Transcript);
Expand All @@ -23,5 +24,4 @@
</details>
}
</div>
</div>

</div>
16 changes: 16 additions & 0 deletions Childrens-Social-Care-CPD/Views/Shared/_Details.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@using Childrens_Social_Care_CPD.Contentful;
@using Childrens_Social_Care_CPD.Contentful.Models;
@using Childrens_Social_Care_CPD.Contentful.Renderers;

@model Details

<details class="govuk-details">
<summary class="govuk-details__summary">
<span class="govuk-details__summary-text">
@Model.SummaryText
</span>
</summary>
<div class="govuk-details__text">
<partial name="_RichText" model="Model.DetailsText" />
</div>
</details>
Loading

0 comments on commit 9ec3638

Please sign in to comment.