Skip to content

Commit be30ebc

Browse files
authored
Merge pull request #605 from YOU54F/feat/optional_arch_specific_binaries
Feat/optional arch specific binaries
2 parents 6959602 + 809775e commit be30ebc

16 files changed

+427
-67
lines changed

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,33 +64,36 @@ jobs:
6464

6565
steps:
6666
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
67+
if: github.ref == 'refs/heads/master'
6768
with:
6869
fetch-depth: 0
6970

7071
- name: Use Node.js ${{ env.NODE_VERSION }}
7172
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4
73+
if: github.ref == 'refs/heads/master'
7274
with:
7375
node-version: ${{ env.NODE_VERSION }}
7476

75-
- if: runner.os == 'Windows'
77+
- if: ${{ runner.os == 'Windows' && github.ref == 'refs/heads/master'}}
7678
run: echo "ONLY_DOWNLOAD_PACT_FOR_WINDOWS=true" >> $GITHUB_ENV
7779

78-
- if: ${{ matrix.docker == true && matrix.alpine == true }}
80+
- if: ${{ matrix.docker == true && matrix.alpine == true && github.ref == 'refs/heads/master'}}
7981
name: prebuild linux ${{ matrix.arch }} musl
8082
run: docker run -v $PWD:/home --platform linux/${{ matrix.arch }} --rm node:20-alpine bin/sh -c 'apk add bash && cd /home && bash -c "/home/script/ci/prebuild-alpine.sh" && rm -rf ffi node_modules'
8183

82-
- if: ${{ matrix.docker == true && matrix.alpine != true }}
84+
- if: ${{ matrix.docker == true && matrix.alpine != true && github.ref == 'refs/heads/master' }}
8385
name: prebuild linux ${{ matrix.arch }}
8486
run: docker run -v $PWD:/home --platform linux/${{ matrix.arch }} --rm node:20 bin/bash -c 'cd /home && /home/script/ci/prebuild.sh && rm -rf ffi node_modules'
8587

8688
- run: sudo chown -R $(id -u):$(id -g) prebuilds
87-
if: ${{ matrix.docker == true }}
89+
if: ${{ matrix.docker == true && github.ref == 'refs/heads/master' }}
8890

8991
- run: ./script/ci/prebuild.sh
90-
if: ${{ matrix.docker != true }}
92+
if: ${{ matrix.docker != true && github.ref == 'refs/heads/master'}}
9193

9294
- name: Upload prebuild for ${{ runner.os }}-${{ runner.arch }}
9395
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4
96+
if: github.ref == 'refs/heads/master'
9497
with:
9598
path: prebuilds/*.tar.gz
9699
name: artifact-${{ matrix.docker == true && matrix.alpine == true && 'linux-musl' || matrix.docker == true && matrix.alpine == false && 'linux' || matrix.os }}-${{ matrix.arch }}
@@ -156,7 +159,12 @@ jobs:
156159
fetch-depth: 0
157160

158161
- name: Download prebuilds
162+
if: github.ref == 'refs/heads/master'
159163
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
164+
- run: FETCH_ASSETS=true REPO=pact-foundation/pact-js-core ./script/ci/check-release-libs.sh --fetch-assets
165+
if: github.ref != 'refs/heads/master'
166+
env:
167+
GITHUB_TOKEN: ${{ github.token }}
160168

161169
- name: Use Node.js ${{ env.NODE_VERSION }}
162170
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4
@@ -173,11 +181,11 @@ jobs:
173181

174182
- if: ${{ matrix.docker == true && matrix.alpine == true && matrix.arch == 'amd64' && matrix.os == 'ubuntu-latest' }}
175183
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'
184+
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'
177185

178186
- if: ${{ matrix.docker == true && matrix.alpine == true && matrix.arch == 'arm64' && matrix.os == 'ubuntu-24.04-arm' }}
179187
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'
188+
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'
181189

182190
release_dry_run:
183191
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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,17 @@ script
8484
binding.gyp
8585
native
8686

87-
.cirrus
8887
.gitattributes
8988
DEVELOPER.md
9089
RELEASING.md
9190
test.js
9291
tsconfig.build.json
93-
tsconfig.json
92+
tsconfig.json
93+
94+
# Standalone Binaries - Published as seperate packages
95+
@pact-foundation/
96+
97+
# Cross packaging files
98+
Makefile
99+
package.json.tmpl
100+
prebuilds

DEVELOPER.md

Lines changed: 85 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,25 @@ 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-glibc`
19+
- `linux-arm64-glibc`
20+
- `linux-x64-musl`
21+
- `linux-arm64-musl`
22+
- `darwin-x64`
23+
- `darwin-arm64`
24+
- `windows-x64`
25+
1426
_notes_ -
1527

1628
As a developer, you need to run `bash script/ci/prebuild.sh` to
@@ -32,61 +44,103 @@ Alternatively you can run the following, which will not create a prebuild, but i
3244
bash script/download-libs.sh
3345
npm ci
3446
npm run build
35-
npm test
47+
npm run test
3648
```
3749

38-
### Linux x86_64 Task
50+
## Creating Platform specific packages
3951

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

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

45-
### CI Locally
56+
```sh
57+
./script/ci/build_opt_dependencies.sh libs v15.2.1
58+
```
4659

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

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

54-
### MacOS ARM64 Task
68+
### Building all platform specific npm packages
5569

56-
#### Pre Reqs
70+
```sh
71+
./script/ci/build_opt_dependencies.sh build
72+
```
73+
74+
### Building individual platform specific npm package
5775

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

78+
- linux-x64-glibc
79+
- linux-arm64-glibc
80+
- linux-x64-musl
81+
- linux-arm64-musl
82+
- darwin-x64
83+
- darwin-arm64
84+
- windows-x64
85+
86+
You can detect your platform with
6287

6388
```sh
64-
cirrus run --output github-actions macos_arm --artifacts-dir tmp
89+
./script/ci/build-opt-dependencies.sh determine_platform
6590
```
6691

67-
### Linux ARM64 Task
92+
You can build with one
6893

69-
#### Pre Reqs
94+
```sh
95+
supported_platforms=$(./script/ci/build-opt-dependencies.sh determine_platform) ./script/ci/build-opt-dependencies.sh build
96+
```
7097

71-
1. Arm64 Machine
98+
or all
7299

73-
### CI Locally
100+
```sh
101+
./script/ci/build-opt-dependencies.sh build
102+
```
74103

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

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

80108
```sh
81-
cirrus run --output github-actions linux_arm --artifacts-dir tmp
109+
./script/ci/build-opt-dependencies.sh
82110
```
83111

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

86-
MacOS ARM64
118+
### Publishing packages
87119

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;`
120+
Dry run publishing optional packages, (default)
121+
122+
```sh
123+
./script/ci/build-opt-dependencies.sh publish
124+
```
89125

90-
Linux ARM64
126+
Publishing packages with `--dry-run` option removed.
91127

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;`
128+
```sh
129+
PUBLISH=true ./script/ci/build-opt-dependencies.sh publish
130+
```
131+
132+
### Linux x86_64 Task
133+
134+
#### Pre Reqs
135+
136+
1. x86_64 Machine
137+
1. ARM64 Mac - If you have Rosetta (MacOS)
138+
139+
### CI Locally
140+
141+
1. Docker/Podman
142+
2. Act
143+
144+
```sh
145+
act --container-architecture linux/amd64 -W .github/workflows/build-and-test.yml --artifact-server-path tmp
146+
```

package-lock.json

Lines changed: 24 additions & 0 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
@@ -44,6 +44,7 @@
4444
},
4545
"dependencies": {
4646
"check-types": "7.4.0",
47+
"detect-libc": "^2.0.3",
4748
"node-gyp-build": "^4.6.0",
4849
"pino": "^8.7.0",
4950
"pino-pretty": "^9.1.1",
@@ -160,5 +161,14 @@
160161
}
161162
]
162163
},
163-
"snyk": true
164+
"snyk": true,
165+
"optionalDependencies": {
166+
"@pact-foundation/pact-core-darwin-arm64": "15.2.1",
167+
"@pact-foundation/pact-core-darwin-x64": "15.2.1",
168+
"@pact-foundation/pact-core-linux-arm64-glibc": "15.2.1",
169+
"@pact-foundation/pact-core-linux-arm64-musl": "15.2.1",
170+
"@pact-foundation/pact-core-linux-x64-glibc": "15.2.1",
171+
"@pact-foundation/pact-core-linux-x64-musl": "15.2.1",
172+
"@pact-foundation/pact-core-windows-x64": "15.2.1"
173+
}
164174
}

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_pkg_os}"
15+
],
16+
${libc}
17+
"cpu": [
18+
"${node_arch}"
19+
]
20+
}

script/ci/build-and-test.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@ 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
30+
# ensure we test against the linked npm package, not the prebuild
31+
rm -rf prebuilds
2532
npm run format:check
2633
npm run lint
2734
npm run build
28-
npm run test
29-
ls -1
35+
npm run test

0 commit comments

Comments
 (0)