Skip to content

Commit 4a8f404

Browse files
committed
Add CI workflow for event schemas version check and publishing
1 parent c2c9daf commit 4a8f404

File tree

3 files changed

+106
-3
lines changed

3 files changed

+106
-3
lines changed

.github/workflows/pr_closed.yaml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,87 @@ jobs:
6262
--targetAccountGroup "nhs-notify-supplier-api-dev" \
6363
--targetComponent "${{ matrix.component }}" \
6464
--terraformAction "apply"
65+
66+
check-event-schemas-version-change:
67+
name: Check for event schemas package version change
68+
needs: check-merge-or-workflow-dispatch
69+
if: needs.check-merge-or-workflow-dispatch.outputs.deploy == 'true'
70+
outputs:
71+
version_changed: ${{ steps.check-version.outputs.version_changed }}
72+
runs-on: ubuntu-latest
73+
permissions:
74+
contents: read
75+
packages: read
76+
steps:
77+
- name: Checkout code
78+
uses: actions/[email protected]
79+
80+
- name: Use Node.js 20
81+
uses: actions/setup-node@v4
82+
with:
83+
node-version: '20.18.2'
84+
registry-url: 'https://npm.pkg.github.com'
85+
86+
- name: check if local version differs from latest published version
87+
id: check-version
88+
run: |
89+
published_version=$(npm view @nhsdigital/nhs-notify-event-schemas-supplier-api --json 2>/dev/null | jq -r '.["dist-tags"].latest // "null"')
90+
echo "Published version: $published_version"
91+
92+
local_version=$(jq -r '.version' internal/events/package.json)
93+
echo "Local version: $local_version"
94+
95+
if [[ $local_version = $published_version ]]; then
96+
echo "Local version is the same as the latest published version - skipping publish"
97+
echo "version_changed=false" >> $GITHUB_OUTPUT
98+
else
99+
echo "Local version is different to the latest published version - publishing new version"
100+
echo "version_changed=true" >> $GITHUB_OUTPUT
101+
fi
102+
103+
test-contract-provider:
104+
name: "Test contracts (provider)"
105+
needs: check-event-schemas-version-change
106+
if: needs.check-event-schemas-version-change.outputs.version_changed == 'true'
107+
runs-on: ubuntu-latest
108+
permissions:
109+
contents: read
110+
packages: read
111+
steps:
112+
- name: "Checkout code"
113+
uses: actions/[email protected]
114+
- name: "Install dependencies"
115+
run: npm ci
116+
- name: "Run provider contract tests"
117+
run: make test-contract-provider
118+
env:
119+
GITHUB_PACKAGES_TOKEN: ${{ secrets.GITHUB_TOKEN }}
120+
121+
publish-event-schemas:
122+
name: Publish event schemas package to GitHub package registry
123+
needs:
124+
- check-event-schemas-version-change
125+
- test-contract-provider
126+
if: needs.check-event-schemas-version-change.outputs.version_changed == 'true'
127+
runs-on: ubuntu-latest
128+
permissions:
129+
contents: read
130+
packages: write
131+
132+
steps:
133+
- name: Checkout code
134+
uses: actions/[email protected]
135+
136+
- name: Use Node.js 20
137+
uses: actions/setup-node@v4
138+
with:
139+
node-version: '20.18.2'
140+
registry-url: 'https://npm.pkg.github.com'
141+
142+
- name: Install dependencies
143+
run: npm ci
144+
145+
- name: Publish to GitHub Packages
146+
run: npm publish --workspace internal/events
147+
env:
148+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/stage-2-test.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,22 @@ jobs:
152152
sonar_organisation_key: "${{ vars.SONAR_ORGANISATION_KEY }}"
153153
sonar_project_key: "${{ vars.SONAR_PROJECT_KEY }}"
154154
sonar_token: "${{ secrets.SONAR_TOKEN }}"
155+
156+
157+
test-contract-provider:
158+
name: "Test contracts (provider)"
159+
runs-on: ubuntu-latest
160+
permissions:
161+
contents: read
162+
packages: read
163+
steps:
164+
- name: "Checkout code"
165+
uses: actions/[email protected]
166+
# - name: "Restore node_modules from cache"
167+
# uses: ./.github/actions/node-modules-cache
168+
# with:
169+
# node_version: "${{ inputs.nodejs_version }}"
170+
- name: "Run provider contract tests"
171+
run: make test-contract-provider
172+
env:
173+
GITHUB_PACKAGES_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,10 @@ construct-spec: guard-APIM_ENV
6868
$(MAKE) set-access APIM_ENV=$$APIM_ENV
6969
$(MAKE) set-security APIM_ENV=$$APIM_ENV
7070

71-
72-
7371
build-json-oas-spec: guard-APIM_ENV
7472
$(MAKE) construct-spec APIM_ENV=$$APIM_ENV
7573
$(MAKE) publish-oas
7674

77-
7875
build-yml-oas-spec: guard-APIM_ENV
7976
$(MAKE) construct-spec APIM_ENV=$$APIM_ENV
8077
$(MAKE) bundle-oas
@@ -106,6 +103,9 @@ config:: _install-dependencies version # Configure development environment (main
106103
test-component:
107104
(cd tests && npm install && npm run test:component)
108105

106+
test-contract-provider:
107+
echo "Contract tests should run here"
108+
109109
version:
110110
rm -f .version
111111
make version-create-effective-file dir=.

0 commit comments

Comments
 (0)