generated from DFE-Digital/govuk-dotnet-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 2
158 lines (124 loc) · 6.01 KB
/
contentful-schema-migrate.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
name: Contentful Schema Migrate
on:
workflow_dispatch:
inputs:
target_environment:
required: true
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 }}
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: 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 == 'prod' && 'master' || 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
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 == 'prod' && 'master' || 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, '') != '[]' }}
needs: [setup,clone]
runs-on: ubuntu-latest
strategy:
max-parallel: 1
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
- 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 }}
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
- 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 == 'prod' && 'master' || inputs.target_environment }} at new environment ${{ env.STAGING_ENVIRONMENT }}
working-directory: ./Contentful-Schema/utils
run: node point-alias-at-environment.js