Skip to content

Commit 6b81211

Browse files
authored
CCM-12869: Implement event builder for supplier config events (#38)
* Feature: Add initial schemas and events for supplier configuration * Fix: dependencies * Remove domain prefix from subject in event envelope * Remove documentation examples + fix event-builder tests * Remove generated files from git * Add contract events * Remove stray readme * Add supplier model events * Refactor contract references to volume group in schemas and events * Add volume group events and update JSON generation * Refactor status handling to use $EnvironmentStatus across configurations * Update tests * Add approval status validation and update enums in specifications * Update deliverySLA to deliveryDays and change status references to PROD * Refactor colour property to restrict to WHITE and update description * Add DISABLED status to various entities and update related schemas * Add optional description to PackSpecification and update tests * Add duplex field validation to PackSpecification and update tests * Add ATTACHMENT type to PackSpecification $Insert schema * Add constraints validation to PackSpecification and related tests * Rename specification-supplier.test.ts to supplier-pack.test.ts * Enhance constraint validation by adding GREATER_THAN_OR_EQUAL and LESS_THAN_OR_EQUAL options; update billingId metadata in PackSpecification * Event Builder: tools for constructing valid config events from payload data * Remove content that lives on other branches * Refactor event builder tests to remove unnecessary imports and use string literals for VolumeGroupId * Add billingId to PackSpecification in event builder tests + remove redundant CLI tool and libs * Add billingId to specification in event builder tests * Add billingId to PackSpecification examples in specification-examples.ts * Update package-lock.json to upgrade js-yaml, diff, and glob dependencies * Add AsyncAPI bundling and event schema package publishing * Update documentation for event-builder package and clarify CloudEvent functions * Add script to validate version increments for packages * Bump schema patch version (changes to examples and asyncapi bundling, but no schema changes) * Refactor imports in volume-group-event-builder.ts and update jest.config.ts for module mapping
1 parent 9019638 commit 6b81211

30 files changed

Lines changed: 2583 additions & 340 deletions

.github/workflows/pr_closed.yaml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
name: PR Closed
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
types: [closed]
7+
branches:
8+
- main
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: false
13+
14+
jobs:
15+
check-merge-or-workflow-dispatch:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
deploy: ${{ steps.check.outputs.deploy }}
19+
steps:
20+
- name: Check if PR was merged or workflow is triggered by workflow_dispatch
21+
id: check
22+
run: |
23+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
24+
echo "deploy=true" >> $GITHUB_OUTPUT
25+
echo "Job triggered by workflow_dispatch - processing jobs"
26+
elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.merged }}" == "true" ]]; then
27+
echo "deploy=true" >> $GITHUB_OUTPUT
28+
echo "Job triggered by Merged PR - processing jobs"
29+
else
30+
echo "deploy=false" >> $GITHUB_OUTPUT
31+
echo "Job not triggered by workflow_dispatch or Merged PR - Skipping jobs"
32+
fi
33+
34+
check-event-schemas-version-change:
35+
name: Check for event schemas package version change
36+
needs: check-merge-or-workflow-dispatch
37+
if: needs.check-merge-or-workflow-dispatch.outputs.deploy == 'true'
38+
outputs:
39+
version_changed: ${{ steps.check-version.outputs.version_changed }}
40+
runs-on: ubuntu-latest
41+
permissions:
42+
contents: read
43+
packages: read
44+
steps:
45+
- name: Checkout code
46+
uses: actions/checkout@v5.0.0
47+
48+
- name: Setup NodeJS
49+
uses: actions/setup-node@v4
50+
with:
51+
node-version: ${{ inputs.nodejs_version }}
52+
registry-url: 'https://npm.pkg.github.com'
53+
54+
- name: check if local version differs from latest published version
55+
id: check-version
56+
env:
57+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
run: |
59+
published_version=$(npm view @nhsdigital/nhs-notify-event-schemas-supplier-config --json 2>/dev/null | jq -r '.["dist-tags"].latest // "null"')
60+
echo "Published version: $published_version"
61+
62+
local_version=$(jq -r '.version' packages/events/package.json)
63+
echo "Local version: $local_version"
64+
65+
if [[ $local_version = $published_version ]]; then
66+
echo "Local version is the same as the latest published version - skipping publish"
67+
echo "version_changed=false" >> $GITHUB_OUTPUT
68+
else
69+
echo "Local version is different to the latest published version - publishing new version"
70+
echo "version_changed=true" >> $GITHUB_OUTPUT
71+
fi
72+
73+
test-contract:
74+
name: "Test contracts (provider)"
75+
needs: check-event-schemas-version-change
76+
if: needs.check-event-schemas-version-change.outputs.version_changed == 'true'
77+
runs-on: ubuntu-latest
78+
permissions:
79+
contents: read
80+
packages: read
81+
steps:
82+
- name: "Checkout code"
83+
uses: actions/checkout@v5.0.0
84+
- name: Setup NodeJS
85+
uses: actions/setup-node@v4
86+
with:
87+
node-version: ${{ inputs.nodejs_version }}
88+
registry-url: 'https://npm.pkg.github.com'
89+
- name: "Install dependencies"
90+
env:
91+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92+
run: npm ci
93+
- name: "Run provider contract tests"
94+
run: make test-contract
95+
env:
96+
GITHUB_PACKAGES_TOKEN: ${{ secrets.GITHUB_TOKEN }}
97+
98+
publish-event-schemas:
99+
name: Publish event schemas package to GitHub package registry
100+
needs:
101+
- check-event-schemas-version-change
102+
- test-contract
103+
if: needs.check-event-schemas-version-change.outputs.version_changed == 'true'
104+
runs-on: ubuntu-latest
105+
permissions:
106+
contents: read
107+
packages: write
108+
109+
steps:
110+
- name: Checkout code
111+
uses: actions/checkout@v5.0.0
112+
113+
- name: Setup NodeJS
114+
uses: actions/setup-node@v4
115+
with:
116+
node-version: ${{ inputs.nodejs_version }}
117+
registry-url: 'https://npm.pkg.github.com'
118+
119+
- name: Install dependencies
120+
env:
121+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
122+
run: npm ci
123+
124+
- name: Publish to GitHub Packages
125+
run: npm publish --workspace packages/events
126+
env:
127+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/stage-1-commit.yaml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,107 @@ jobs:
188188
idp_aws_report_upload_region: "${{ secrets.IDP_AWS_REPORT_UPLOAD_REGION }}"
189189
idp_aws_report_upload_role_name: "${{ secrets.IDP_AWS_REPORT_UPLOAD_ROLE_NAME }}"
190190
idp_aws_report_upload_bucket_endpoint: "${{ secrets.IDP_AWS_REPORT_UPLOAD_BUCKET_ENDPOINT }}"
191+
192+
193+
detect-event-schema-package-changes:
194+
name: "Check for changes to event schema package compared to main branch"
195+
runs-on: ubuntu-latest
196+
permissions:
197+
contents: read
198+
outputs:
199+
changed: ${{ steps.check.outputs.changed }}
200+
main_version: ${{ steps.check.outputs.main_version }}
201+
202+
steps:
203+
- name: "Checkout code"
204+
uses: actions/checkout@v4
205+
with:
206+
fetch-depth: 0
207+
208+
- name: Detect package changes and current version
209+
id: check
210+
run: |
211+
git fetch origin main
212+
213+
if git diff --quiet origin/main...HEAD -- packages/events; then
214+
echo "No changes in event schemas package"
215+
echo "changed=false" >> $GITHUB_OUTPUT
216+
else
217+
echo "Changes detected in event schemas"
218+
echo "changed=true" >> $GITHUB_OUTPUT
219+
fi
220+
221+
if content=$(git show origin/main:packages/events/package.json 2>/dev/null); then
222+
version=$(jq -r .version <<< $content);
223+
else
224+
version=null;
225+
fi
226+
227+
echo "Detected package version $version in main branch"
228+
echo "main_version=$version" >> $GITHUB_OUTPUT
229+
230+
check-schema-version-change:
231+
name: Check event schema version has been updated
232+
needs: detect-event-schema-package-changes
233+
if: needs.detect-event-schema-package-changes.outputs.changed == 'true'
234+
runs-on: ubuntu-latest
235+
permissions:
236+
contents: read
237+
steps:
238+
- name: Checkout code
239+
uses: actions/checkout@v4
240+
241+
- name: Check schema versions
242+
run: |
243+
source scripts/is_valid_increment.sh
244+
245+
main_version="${{ needs.detect-event-schema-package-changes.outputs.main_version }}"
246+
echo "Main version: ${{ needs.detect-event-schema-package-changes.outputs.main_version }}"
247+
248+
local_version=$(jq -r '.version' packages/events/package.json)
249+
echo "Local version: $local_version"
250+
251+
if ! is_valid_increment "$main_version" "$local_version" ; then
252+
echo "Error: Event Schema package has changed, but new version ($local_version) is not a valid increment from latest version on main branch ($main_version)."
253+
exit 1
254+
fi
255+
256+
check-event-schemas-version-change:
257+
name: Check for event schemas package version change
258+
needs: detect-event-schema-package-changes
259+
if: needs.detect-event-schema-package-changes.outputs.changed == 'true'
260+
outputs:
261+
version_changed: ${{ steps.check-version.outputs.version_changed }}
262+
runs-on: ubuntu-latest
263+
permissions:
264+
contents: read
265+
packages: read
266+
steps:
267+
- name: Checkout code
268+
uses: actions/checkout@v5.0.0
269+
270+
- name: Setup NodeJS
271+
uses: actions/setup-node@v4
272+
with:
273+
node-version: ${{ inputs.nodejs_version }}
274+
registry-url: "https://npm.pkg.github.com"
275+
276+
- name: check if local version differs from latest published version
277+
id: check-version
278+
env:
279+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
280+
run: |
281+
published_version=$(npm view @nhsdigital/nhs-notify-event-schemas-supplier-config --json 2>/dev/null | jq -r '.["dist-tags"].latest // "null"')
282+
echo "Published version: $published_version"
283+
284+
local_version=$(jq -r '.version' packages/events/package.json)
285+
echo "Local version: $local_version"
286+
287+
if [[ $local_version = $published_version ]]; then
288+
echo "ERROR: Local version is the same as the latest published version, but event schemas have changed"
289+
echo "version_changed=false" >> $GITHUB_OUTPUT
290+
exit 1
291+
else
292+
echo "Local version is different to the latest published version - a new version will be published"
293+
echo "version_changed=true" >> $GITHUB_OUTPUT
294+
fi

0 commit comments

Comments
 (0)