Skip to content

Commit

Permalink
Merge pull request #511 from DFE-Digital/mattb/SWCD-2424-schema-deplo…
Browse files Browse the repository at this point in the history
…yment

Mattb/swcd 2424 schema deployment
  • Loading branch information
mattb-hippo authored Sep 19, 2024
2 parents c01c7fb + ca0bed9 commit 602ee9d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 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
2 changes: 1 addition & 1 deletion Contentful-Schema/migrations/manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
0005-create-employer-standards-page-category.cjs
0006-accordion-component.cjs
0007-add-header-field-to-navigation-menu.cjs
0008-details-component.cjs
0008-details-component.cjs
Binary file modified Contentful-Schema/migrations/migrations.tar.gz
Binary file not shown.

0 comments on commit 602ee9d

Please sign in to comment.