Skip to content

Commit 2e4ceee

Browse files
committed
feat: build platform/arch specific npm packages
support libpact_ffi & pact-js-core node bindings to be published in seperate npm packages. these are segmented by os-arch-libc users should not need to require these automatically, npm should determine the required optional dependency to download at install time. supported_platforms "@pact-foundation/pact-core-darwin-arm64": "16.0.0", "@pact-foundation/pact-core-darwin-x64": "16.0.0", "@pact-foundation/pact-core-linux-arm64-glibc": "16.0.0", "@pact-foundation/pact-core-linux-arm64-musl": "16.0.0", "@pact-foundation/pact-core-linux-x64-glibc": "16.0.0", "@pact-foundation/pact-core-linux-x64-musl": "16.0.0", "@pact-foundation/pact-core-windows-x64": "16.0.0"
1 parent 6959602 commit 2e4ceee

14 files changed

+390
-42
lines changed

.github/workflows/build-and-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ jobs:
173173

174174
- if: ${{ matrix.docker == true && matrix.alpine == true && matrix.arch == 'amd64' && matrix.os == 'ubuntu-latest' }}
175175
name: test linux amd64 musl
176-
run: docker run -v $PWD:/home --platform linux/${{ matrix.arch }} --rm node:${{ matrix.node-version }}-alpine bin/sh -c 'apk add bash curl gcompat file && cd /home && /home/script/ci/unpack-and-test.sh'
176+
run: docker run -v $PWD:/home --platform linux/${{ matrix.arch }} --rm node:${{ matrix.node-version }}-alpine bin/sh -c 'apk add jq gettext-envsubst bash curl gcompat file && cd /home && /home/script/ci/unpack-and-test.sh'
177177

178178
- if: ${{ matrix.docker == true && matrix.alpine == true && matrix.arch == 'arm64' && matrix.os == 'ubuntu-24.04-arm' }}
179179
name: test linux arm64 musl
180-
run: docker run -v $PWD:/home --platform linux/${{ matrix.arch }} --rm node:${{ matrix.node-version }}-alpine bin/sh -c 'apk add bash curl file protoc protobuf-dev && cd /home && /home/script/ci/unpack-and-test.sh'
180+
run: docker run -v $PWD:/home --platform linux/${{ matrix.arch }} --rm node:${{ matrix.node-version }}-alpine bin/sh -c 'apk add jq gettext-envsubst bash curl file protoc protobuf-dev && cd /home && /home/script/ci/unpack-and-test.sh'
181181

182182
release_dry_run:
183183
runs-on: ubuntu-latest

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,6 @@ reports
7272
tmp
7373
.tmp
7474
test/__testoutput__
75+
76+
# platform-arch specific packages
77+
@pact-foundation/*

.npmignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,11 @@ DEVELOPER.md
9090
RELEASING.md
9191
test.js
9292
tsconfig.build.json
93-
tsconfig.json
93+
tsconfig.json
94+
95+
# Standalone Binaries - Published as seperate packages
96+
@pact-foundation/
97+
98+
# Cross packaging files
99+
Makefile
100+
package.json.tmpl

DEVELOPER.md

Lines changed: 83 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@ Pact-Js-Core uses FFI bindings from the pact-reference project, which are prebui
44

55
Do this and you should be 👌👌👌:
66

7-
```
7+
```sh
88
bash script/ci/prebuild.sh
9-
npm ci --ignore-scripts
9+
supported_platforms=$(./script/ci/build-opt-dependencies.sh determine_platform)
10+
./script/ci/build-opt-dependencies.sh build
11+
./script/ci/build-opt-dependencies.sh link
1012
npm run build
11-
npm test
13+
npm run test
1214
```
1315

16+
set supported platform to one of these values
17+
18+
- `linux-x64`
19+
- `linux-arm64`
20+
- `darwin-x64`
21+
- `darwin-arm64`
22+
- `windows-x64`
23+
1424
_notes_ -
1525

1626
As a developer, you need to run `bash script/ci/prebuild.sh` to
@@ -32,61 +42,103 @@ Alternatively you can run the following, which will not create a prebuild, but i
3242
bash script/download-libs.sh
3343
npm ci
3444
npm run build
35-
npm test
45+
npm run test
3646
```
3747

38-
### Linux x86_64 Task
48+
## Creating Platform specific packages
3949

40-
#### Pre Reqs
50+
We create cross-platform and architecture binaries which are published individually to NPM, and consumed in this project.
4151

42-
1. x86_64 Machine
43-
1. ARM64 Mac - If you have Rosetta (MacOS)
52+
### Download prebuilt binaries for all platforms
4453

45-
### CI Locally
54+
```sh
55+
./script/ci/build_opt_dependencies.sh libs v15.2.1
56+
```
4657

47-
1. Docker/Podman
48-
2. Act
58+
Tag is optional and defaults to latest
59+
60+
This will run the following script, which will grab the latest prebuilt binaries from GitHub.
4961

5062
```sh
51-
act --container-architecture linux/amd64 -W .github/workflows/build-and-test.yml --artifact-server-path tmp
63+
FETCH_ASSETS=true ./script/ci/check-release-libs.sh --fetch-assets -t v15.2.1
5264
```
5365

54-
### MacOS ARM64 Task
66+
### Building all platform specific npm packages
5567

56-
#### Pre Reqs
68+
```sh
69+
./script/ci/build_opt_dependencies.sh build
70+
```
71+
72+
### Building individual platform specific npm package
5773

58-
1. Arm64 Mac
59-
2. Cirrus-Cli
60-
3. Tart.run
74+
Supported platforms are
6175

76+
- linux-x64-glibc
77+
- linux-arm64-glibc
78+
- linux-x64-musl
79+
- linux-arm64-musl
80+
- darwin-x64
81+
- darwin-arm64
82+
- windows-x64
83+
84+
You can detect your platform with
6285

6386
```sh
64-
cirrus run --output github-actions macos_arm --artifacts-dir tmp
87+
./script/ci/build-opt-dependencies.sh determine_platform
6588
```
6689

67-
### Linux ARM64 Task
90+
You can build with one
6891

69-
#### Pre Reqs
92+
```sh
93+
supported_platforms=$(./script/ci/build-opt-dependencies.sh determine_platform) ./script/ci/build-opt-dependencies.sh build
94+
```
7095

71-
1. Arm64 Machine
96+
or all
7297

73-
### CI Locally
98+
```sh
99+
./script/ci/build-opt-dependencies.sh build
100+
```
74101

75-
1. Arm64 Machine
76-
2. Docker / Podman
77-
3. Cirrus-Cli
102+
### Linking arch specific package, for your local build
78103

104+
Make link will try to link all available packages, for all available platforms, and will link any that apply
79105

80106
```sh
81-
cirrus run --output github-actions linux_arm --artifacts-dir tmp
107+
./script/ci/build-opt-dependencies.sh
82108
```
83109

84-
#### Publishing Assets
110+
You can scope it with `supported_platforms`
111+
112+
```sh
113+
supported_platforms=$(./script/ci/build-opt-dependencies.sh determine_platform) ./script/ci/build-opt-dependencies.sh link
114+
```
85115

86-
MacOS ARM64
116+
### Publishing packages
87117

88-
`cirrus run --output github-actions macos_arm --artifacts-dir tmp --environment GITHUB_TOKEN=$GITHUB_TOKEN --environment CIRRUS_RELEASE=test --environment CIRRUS_REPO_FULL_NAME=pact-foundation/pact-js-core;`
118+
Dry run publishing optional packages, (default)
119+
120+
```sh
121+
./script/ci/build-opt-dependencies.sh publish
122+
```
89123

90-
Linux ARM64
124+
Publishing packages with `--dry-run` option removed.
91125

92-
`cirrus run --output github-actions linux_arm --artifacts-dir tmp --environment GITHUB_TOKEN=$GITHUB_TOKEN --environment CIRRUS_RELEASE=test --environment CIRRUS_REPO_FULL_NAME=pact-foundation/pact-js-core;`
126+
```sh
127+
PUBLISH=true ./script/ci/build-opt-dependencies.sh publish
128+
```
129+
130+
### Linux x86_64 Task
131+
132+
#### Pre Reqs
133+
134+
1. x86_64 Machine
135+
1. ARM64 Mac - If you have Rosetta (MacOS)
136+
137+
### CI Locally
138+
139+
1. Docker/Podman
140+
2. Act
141+
142+
```sh
143+
act --container-architecture linux/amd64 -W .github/workflows/build-and-test.yml --artifact-server-path tmp
144+
```

package-lock.json

Lines changed: 25 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pact-foundation/pact-core",
3-
"version": "15.2.1",
3+
"version": "16.0.0",
44
"description": "Core of @pact-foundation/pact. You almost certainly don't want to depend on this directly.",
55
"main": "src/index.js",
66
"homepage": "https://github.com/pact-foundation/pact-js-core#readme",
@@ -42,8 +42,18 @@
4242
"publishConfig": {
4343
"access": "public"
4444
},
45+
"optionalDependencies": {
46+
"@pact-foundation/pact-core-darwin-arm64": "16.0.0",
47+
"@pact-foundation/pact-core-darwin-x64": "16.0.0",
48+
"@pact-foundation/pact-core-linux-arm64-glibc": "16.0.0",
49+
"@pact-foundation/pact-core-linux-arm64-musl": "16.0.0",
50+
"@pact-foundation/pact-core-linux-x64-glibc": "16.0.0",
51+
"@pact-foundation/pact-core-linux-x64-musl": "16.0.0",
52+
"@pact-foundation/pact-core-windows-x64": "16.0.0"
53+
},
4554
"dependencies": {
4655
"check-types": "7.4.0",
56+
"detect-libc": "^2.0.3",
4757
"node-gyp-build": "^4.6.0",
4858
"pino": "^8.7.0",
4959
"pino-pretty": "^9.1.1",

package.json.tmpl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "${node_pkg}",
3+
"version": "${pkg_version}",
4+
"description": "Platform/arch specific libpact_ffi binaries for @pact-foundation/pact-core",
5+
"license": "MIT",
6+
"repository": {
7+
"type": "git",
8+
"url": "git://github.com/pact-foundation/pact-js-core.git"
9+
},
10+
"scripts": {},
11+
"author": "Yousaf Nabi <you@saf.dev>",
12+
"homepage": "https://github.com/pact-foundation/pact-js-core#readme",
13+
"os": [
14+
"${node_os}"
15+
],
16+
${libc}
17+
"cpu": [
18+
"${node_arch}"
19+
]
20+
}

script/ci/build-and-test.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ fi
1919

2020
node --version
2121
npm --version
22+
# Update main package.json optional dependencies versions, with those created earlier
23+
current_platform=$("$SCRIPT_DIR"/build-opt-dependencies.sh determine_platform)
24+
supported_platforms="$current_platform" "$SCRIPT_DIR"/build-opt-dependencies.sh update
25+
# update lockfile post building updated opt deps
26+
npm ci --ignore-scripts || npm i --ignore-scripts
27+
# Link os/arch specific npm package, for running os/arch system
2228

23-
npm ci --ignore-scripts
24-
29+
supported_platforms="$current_platform" "$SCRIPT_DIR"/build-opt-dependencies.sh link
2530
npm run format:check
2631
npm run lint
2732
npm run build
28-
npm run test
29-
ls -1
33+
npm run test

0 commit comments

Comments
 (0)