Skip to content

Commit d529b58

Browse files
committed
CCM-15633: Publish pact contracts package
1 parent 8f2ddb4 commit d529b58

6 files changed

Lines changed: 74 additions & 2 deletions

File tree

.github/workflows/cicd-1-pull-request.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ on:
1515
permissions:
1616
id-token: write
1717
contents: write
18-
packages: read
18+
packages: write
1919

2020
jobs:
2121
metadata:

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ jobs:
163163
- name: "Run contract test suite"
164164
run: |
165165
make test-contract
166+
- name: "Upload generated contracts"
167+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
168+
with:
169+
name: pact-contracts
170+
path: "tests/pact-tests/.pacts"
171+
include-hidden-files: true
166172

167173
test-lint:
168174
name: "Linting"

.github/workflows/stage-5-publish.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,35 @@ jobs:
4040
name: "Publish packages"
4141
runs-on: ubuntu-latest
4242
timeout-minutes: 10
43+
permissions:
44+
contents: read
45+
packages: write
4346

4447
steps:
4548
- name: "Checkout code"
4649
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
50+
- uses: ./.github/actions/node-install
51+
with:
52+
node-version: ${{ inputs.nodejs_version }}
53+
GITHUB_TOKEN: ${{ github.token }}
4754
- name: "Get artifacts: jekyll docs"
4855
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5
4956
with:
5057
path: ./artifacts/jekyll-docs-${{ inputs.version }}
5158
name: jekyll-docs-${{ inputs.version }}
52-
5359
- name: "Get artifacts: schema"
5460
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5
5561
with:
5662
path: ./artifacts/schemas-${{ inputs.version }}
5763
name: schemas-${{ inputs.version }}
64+
- name: "Get artifacts: pact contracts"
65+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5
66+
with:
67+
path: ./pact-contracts/pacts
68+
name: pact-contracts
69+
- name: "Publish pact contracts package"
70+
run: |
71+
scripts/publish-pact-contracts.sh
5872
5973
6074
- name: Draft Release

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ coverage.xml
5757
coverage/
5858
coverage-*/
5959
**/.pacts
60+
/pact-contracts/pacts
6061
**/playwright-report
6162
**/test-results
6263
plugin-cache

pact-contracts/package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"description": "NHS Notify Digital Letters Pact contracts",
3+
"exports": {
4+
"./pacts/*.json": {
5+
"default": "./pacts/*.json"
6+
}
7+
},
8+
"files": [
9+
"pacts"
10+
],
11+
"license": "MIT",
12+
"name": "@nhsdigital/notify-digital-letters-consumer-contracts",
13+
"private": false,
14+
"publishConfig": {
15+
"access": "public",
16+
"registry": "https://npm.pkg.github.com"
17+
},
18+
"scripts": {
19+
"lint": "echo Linting not required",
20+
"lint:fix": "echo Linting not required",
21+
"test:unit": "echo Unit tests not required",
22+
"test:unit:coverage": "echo Unit tests not required",
23+
"typecheck": "echo Typecheck not required"
24+
},
25+
"version": "0.0.1"
26+
}

scripts/publish-pact-contracts.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
published_version=$(npm view @nhsdigital/notify-digital-letters-consumer-contracts --json 2>/dev/null | jq -r '.["dist-tags"].latest')
4+
5+
set -euo pipefail
6+
7+
# Fail if there are uncommitted changes as this indicates unexpected changes to the contracts
8+
git diff --quiet tests/pact-tests
9+
10+
local_version=$(cat pact-contracts/package.json | jq -r '.version')
11+
12+
branch=$(git branch --show-current)
13+
14+
if [[ ! $branch == "main" ]]; then
15+
echo "Not publishing package because this is not the main branch"
16+
exit 0
17+
fi
18+
19+
if [[ $local_version == $published_version ]]; then
20+
echo "Local version is the same as the latest published version - skipping publish"
21+
exit 0
22+
fi
23+
24+
echo "Local version is different to the latest published version - publishing new version"
25+
npm publish ./pact-contracts

0 commit comments

Comments
 (0)