Skip to content

Commit

Permalink
Merge pull request #490 from DFE-Digital/next
Browse files Browse the repository at this point in the history
New Components Release
  • Loading branch information
mattb-hippo authored Aug 6, 2024
2 parents 2a70046 + 23c0ce4 commit 7e7163c
Show file tree
Hide file tree
Showing 115 changed files with 28,697 additions and 12,456 deletions.
141 changes: 141 additions & 0 deletions .github/workflows/contentful-schema-migrate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
name: Contentful Schema Migrate

on:
workflow_dispatch:
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 }}

jobs:
setup:
runs-on: ubuntu-latest

outputs:
staging-environment: ${{ steps.staging-env.outputs.staging-environment }}
required-migrations: ${{ steps.required-migrations.outputs.required-migrations }}

steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install npm packages used by util scripts
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: 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

- name: Extract migration files from archive
working-directory: ./Contentful-Schema/migrations
run: rm *.cjs && rm manifest.txt && tar -zxf migrations.tar.gz && rm migrations.tar.gz

- name: Verify migration files against manifest
working-directory: ./Contentful-Schema/utils
run: node verify-migrations-against-manifest.js

- name: Determine required migrations for environment
id: required-migrations
working-directory: ./Contentful-Schema/utils
run: node get-required-migrations.js --currentVersion ${{ steps.current-migration-version.outputs.migration-version }}

clone:
if: ${{ join(needs.setup.outputs.required-migrations, '') != '[]' }}
needs: [setup]
runs-on: ubuntu-latest
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 }}

- 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 }}

migrate:
if: ${{ join(needs.setup.outputs.required-migrations, '') != '[]' }}
needs: [setup,clone]
runs-on: ubuntu-latest
strategy:
max-parallel: 1
matrix:
value: ${{fromJSON(needs.setup.outputs.required-migrations)}}

steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install npm packages used by migration script
working-directory: ./Contentful-Schema
run: npm ci

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

- name: Extract migration files from archive
working-directory: ./Contentful-Schema/migrations
run: rm *.cjs && rm manifest.txt && tar -zxf migrations.tar.gz && rm migrations.tar.gz

- name: Run migration script ${{ matrix.value }}
working-directory: ./Contentful-Schema/migrations
run: contentful space migration --space-id "${{ env.SPACE_ID }}" --environment-id ${{ needs.setup.outputs.staging-environment }} --management-token "${{ env.MANAGEMENT_TOKEN }}" ${{ matrix.value }} --yes

- name: Update environment's migration version
working-directory: ./Contentful-Schema/utils
env:
STAGING_ENVIRONMENT: ${{ needs.setup.outputs.staging-environment }}
MIGRATION_FILENAME: ${{ matrix.value }}
run: node set-environment-version.js

repoint-alias:
if: ${{ join(needs.setup.outputs.required-migrations, '') != '[]' }}
needs: [setup,migrate]
runs-on: ubuntu-latest
env:
STAGING_ENVIRONMENT: ${{ needs.setup.outputs.staging-environment }}

steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install npm packages used by migration script
working-directory: ./Contentful-Schema
run: npm ci

- name: Run script to point alias ${{ inputs.target_environment }} at new environment ${{ env.STAGING_ENVIRONMENT }}
working-directory: ./Contentful-Schema/utils
run: node point-alias-at-environment.js
27 changes: 0 additions & 27 deletions .github/workflows/create-schema-release.yml

This file was deleted.

6 changes: 1 addition & 5 deletions .github/workflows/docker-dev-integration-tests.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
---
name: Run integration tests
on:
pull_request:
branches:
- main
- next
on: workflow_dispatch
jobs:
build-test-scan:
name: Build image and integration test
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/prepare-environment-for-migrations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Prepare Contentful Environment for Migrations

on:
workflow_dispatch:
inputs:
target_environment:
required: true
type: string

env:
MANAGEMENT_TOKEN: ${{ secrets.CONTENTFUL_MANAGEMENT_TOKEN }}
SPACE_ID: ${{ secrets.TF_VAR_CPD_SPACE_ID }}
ENVIRONMENT: ${{ inputs.target_environment }}

jobs:
prepare-environment:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install npm packages used by migration script
working-directory: ./Contentful-Schema
run: npm ci

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

- name: Run script to create migrationVersion content type
working-directory: ./Contentful-Schema/utils
run: contentful space migration --space-id "${{ secrets.TF_VAR_CPD_SPACE_ID }}" --environment-id ${{ inputs.target_environment }} --management-token "${{ secrets.CONTENTFUL_MANAGEMENT_TOKEN }}" create-migration-version-content-type.cjs --yes

- name: Run script to create inital migration version entry
working-directory: ./Contentful-Schema/utils
run: node create-initial-migration-version.js

28 changes: 0 additions & 28 deletions .github/workflows/rollback-master-alias-to-previous-release.yml

This file was deleted.

28 changes: 0 additions & 28 deletions .github/workflows/switch-master-alias-to-new-release.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ namespace Childrens_Social_Care_CPD_Tests.Contentful;
public class EntityResolverTests
{
[Test]
[TestCase("accordion", typeof(Accordion))]
[TestCase("accordionSection", typeof(AccordionSection))]
[TestCase("areaOfPractice", typeof(AreaOfPractice))]
[TestCase("areaOfPracticeList", typeof(AreaOfPracticeList))]
[TestCase("applicationFeature", typeof(ApplicationFeature))]
[TestCase("applicationFeatures", typeof(ApplicationFeatures))]
[TestCase("audioResource", typeof(AudioResource))]
[TestCase("backToTop", typeof(BackToTop))]
[TestCase("columnLayout", typeof(ColumnLayout))]
[TestCase("content", typeof(Content))]
[TestCase("contentLink", typeof(ContentLink))]
[TestCase("contentsAnchor", typeof(ContentsAnchor))]
[TestCase("contentSeparator", typeof(ContentSeparator))]
[TestCase("detailedPathway", typeof(DetailedPathway))]
[TestCase("detailedRole", typeof(DetailedRole))]
Expand All @@ -26,12 +30,15 @@ public class EntityResolverTests
[TestCase("imageCard", typeof(ImageCard))]
[TestCase("linkCard", typeof(LinkCard))]
[TestCase("linkListCard", typeof(LinkListCard))]
[TestCase("pageContents", typeof(PageContents))]
[TestCase("pageContentsItem", typeof(PageContentsItem))]
[TestCase("pdfFileResource", typeof(PdfFileResource))]
[TestCase("richTextBlock", typeof(RichTextBlock))]
[TestCase("roleList", typeof(RoleList))]
[TestCase("navigationMenu", typeof(NavigationMenu))]
[TestCase("textBlock", typeof(TextBlock))]
[TestCase("videoResource", typeof(VideoResource))]
[TestCase("infoBox", typeof(InfoBox))]
public void Resolves_Correctly(string contentTypeId, Type expectedType)
{
var resolver = new EntityResolver();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ public partial class PartialsFactoryTests
{
private static readonly object[] Successful_Resolves =
{
new object[] { new Accordion(), "_Accordion" },
new object[] { new AccordionSection(), "_AccordionSection" },
new object[] { new AreaOfPractice(), "_AreaOfPractice" },
new object[] { new AreaOfPracticeList(), "_AreaOfPracticeList" },
new object[] { new AudioResource(), "_AudioResource" },
new object[] { new BackToTop(), "_BackToTop" },
new object[] { new ColumnLayout(), "_ColumnLayout" },
new object[] { new Content(), "_Content" },
new object[] { new ContentLink(), "_ContentLink" },
new object[] { new ContentSeparator(), "_ContentSeparator" },
new object[] { new ContentsAnchor(), "_ContentsAnchor" },
new object[] { new DetailedPathway(), "_DetailedPathway" },
new object[] { new DetailedRole(), "_DetailedRole" },
new object[] { new Feedback(), "_Feedback" },
Expand All @@ -26,11 +30,14 @@ public partial class PartialsFactoryTests
new object[] { new ImageCard(), "_ImageCard" },
new object[] { new NavigationMenu(), "_NavigationMenu" },
new object[] { new LinkListCard(), "_LinkListCard" },
new object[] { new PageContents(), "_PageContents" },
new object[] { new PageContentsItem(), "_PageContentsItem" },
new object[] { new PdfFileResource(), "_PdfFileResource" },
new object[] { new RichTextBlock(), "_RichTextBlock" },
new object[] { new RoleList(), "_RoleList" },
new object[] { new TextBlock(), "_TextBlock" },
new object[] { new VideoResource(), "_VideoResource" },
new object[] { new InfoBox(), "_InfoBox" },
};

[TestCaseSource(nameof(Successful_Resolves))]
Expand Down
Loading

0 comments on commit 7e7163c

Please sign in to comment.