-
Notifications
You must be signed in to change notification settings - Fork 2
195 lines (170 loc) · 6.15 KB
/
pr_closed.yaml
File metadata and controls
195 lines (170 loc) · 6.15 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
name: PR Closed
on:
workflow_dispatch:
pull_request:
types: [closed]
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
check-merge-or-workflow-dispatch:
runs-on: ubuntu-latest
outputs:
deploy: ${{ steps.check.outputs.deploy }}
steps:
- name: Check if PR was merged or workflow is triggered by workflow_dispatch
id: check
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "deploy=true" >> $GITHUB_OUTPUT
echo "Job triggered by workflow_dispatch - running 'deploy-main'"
elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.merged }}" == "true" ]]; then
echo "deploy=true" >> $GITHUB_OUTPUT
echo "Job triggered by Merged PR - running 'deploy-main'"
else
echo "deploy=false" >> $GITHUB_OUTPUT
echo "Job not triggered by workflow_dispatch or Merged PR - Skipping 'deploy-main'"
fi
deploy-main:
needs: check-merge-or-workflow-dispatch
name: Deploy changes to main in dev AWS account
runs-on: ubuntu-latest
if: needs.check-merge-or-workflow-dispatch.outputs.deploy == 'true'
permissions:
id-token: write
contents: read
strategy:
max-parallel: 1
matrix:
component: [api]
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Updating Main Environment
env:
APP_CLIENT_ID: ${{ secrets.APP_CLIENT_ID }}
APP_PEM_FILE: ${{ secrets.APP_PEM_FILE }}
run: |
bash .github/scripts/dispatch_internal_repo_workflow.sh \
--releaseVersion "main" \
--targetWorkflow "dispatch-deploy-static-notify-supplier-api-env.yaml" \
--targetEnvironment "main" \
--targetAccountGroup "nhs-notify-supplier-api-dev" \
--targetComponent "${{ matrix.component }}" \
--terraformAction "apply"
check-event-schemas-version-change:
name: Check for event schemas package version change
needs: check-merge-or-workflow-dispatch
if: needs.check-merge-or-workflow-dispatch.outputs.deploy == 'true'
outputs:
version_changed: ${{ steps.check-version.outputs.version_changed }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
steps:
- name: Checkout code
uses: actions/checkout@v5.0.0
- name: Setup NodeJS
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.nodejs_version }}
registry-url: 'https://npm.pkg.github.com'
- name: check if local version differs from latest published version
id: check-version
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
published_version=$(npm view @nhsdigital/nhs-notify-event-schemas-supplier-api --json 2>/dev/null | jq -r '.["dist-tags"].latest // "null"')
echo "Published version: $published_version"
local_version=$(jq -r '.version' internal/events/package.json)
echo "Local version: $local_version"
if [[ $local_version = $published_version ]]; then
echo "Local version is the same as the latest published version - skipping publish"
echo "version_changed=false" >> $GITHUB_OUTPUT
else
echo "Local version is different to the latest published version - publishing new version"
echo "version_changed=true" >> $GITHUB_OUTPUT
fi
test-contract:
name: "Test contracts (provider)"
needs: check-event-schemas-version-change
if: needs.check-event-schemas-version-change.outputs.version_changed == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
steps:
- name: "Checkout code"
uses: actions/checkout@v5.0.0
- name: Setup NodeJS
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.nodejs_version }}
registry-url: 'https://npm.pkg.github.com'
- name: "Install dependencies"
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm ci
- name: "Run provider contract tests"
run: make test-contract
env:
GITHUB_PACKAGES_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-event-schemas:
name: Publish event schemas package to GitHub package registry
needs:
- check-event-schemas-version-change
- test-contract
if: needs.check-event-schemas-version-change.outputs.version_changed == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v5.0.0
- name: Setup NodeJS
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.nodejs_version }}
registry-url: 'https://npm.pkg.github.com'
- name: Install dependencies
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm ci
- name: Publish to GitHub Packages
run: npm publish --workspace internal/events
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-api-specs:
name: Generate and publish API specs to APIM pre-release artefacts
#if: needs.check-merge-or-workflow-dispatch.outputs.deploy == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
apim-env: [internal-dev, int, ref, prod]
steps:
- name: Checkout code
uses: actions/checkout@v5.0.0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Install dependencies
working-directory: .
run: npm ci
shell: bash
- name: Generate OpenAPI specification
run: |
echo "Building env specific OAS spec"
make build-json-oas-spec APIM_ENV=${{ matrix.apim-env }}
- name: Upload API spec artefact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.apim-env }}-build-output
path: ./build