Skip to content

Commit 0deb34d

Browse files
committed
CCM-15633: Updated scripts following review
1 parent 2dd0367 commit 0deb34d

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

scripts/publish-pact-contracts.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,27 @@ published_version=$(npm view @nhsdigital/notify-digital-letters-consumer-contrac
55

66
set -euo pipefail
77

8+
cd "$(git rev-parse --show-toplevel)"
9+
810
# Fail if there are uncommitted changes as this indicates unexpected changes to the contracts
911
git diff --quiet tests/pact-tests
1012

11-
local_version=$(cat pact-contracts/package.json | jq -r '.version')
12-
13-
if [[ ! $BRANCH_NAME == "main" ]]; then
13+
branch_name=${BRANCH_NAME:-$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "")}
14+
if [[ "$branch_name" != "main" ]]; then
1415
echo "Not publishing package because this is not the main branch"
1516
exit 0
1617
fi
1718

19+
local_version=$(cat pact-contracts/package.json | jq -r '.version')
1820
if [[ $local_version == $published_version ]]; then
1921
echo "Local version is the same as the latest published version - skipping publish"
2022
exit 0
2123
fi
2224

25+
if ! ls pact-contracts/pacts/**/*.json >/dev/null 2>&1; then
26+
echo "Cannot publish package: no pact .json files found under pact-contracts/pacts"
27+
exit 1
28+
fi
29+
2330
echo "Local version is different to the latest published version - publishing new version"
2431
npm publish ./pact-contracts

scripts/tests/contract.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,26 @@
22

33
set -euo pipefail
44

5+
schema_package="@nhsdigital/nhs-notify-event-schemas-status-published"
6+
57
cd "$(git rev-parse --show-toplevel)"
68

7-
if [[ $(npm outdated @nhsdigital/nhs-notify-event-schemas-status-published) ]]; then
8-
echo "The provider schema package (@nhsdigital/nhs-notify-event-schemas-status-published) is outdated."
9-
echo "Please run \`npm update @nhsdigital/nhs-notify-event-schemas-status-published\` to update to the latest version and re-run."
9+
if npm outdated "$schema_package" >/dev/null 2>&1; then
10+
outdated_status=0
11+
else
12+
outdated_status=$?
13+
fi
14+
15+
if [[ $outdated_status -eq 1 ]]; then
16+
echo "The provider schema package ($schema_package) is outdated."
17+
echo "Please run npm update $schema_package to update to the latest version and re-run."
1018
echo
1119
exit 1
1220
fi
1321

22+
if [[ $outdated_status -gt 1 ]]; then
23+
echo "Failed to check provider schema package version (npm outdated exited with status $outdated_status)."
24+
exit $outdated_status
25+
fi
26+
1427
npm run test:contract

0 commit comments

Comments
 (0)