Skip to content

Commit

Permalink
build in GHA
Browse files Browse the repository at this point in the history
  • Loading branch information
baileympearson committed Jun 25, 2024
1 parent 658c858 commit c00034b
Show file tree
Hide file tree
Showing 9 changed files with 641 additions and 797 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ runs:
registry-url: 'https://registry.npmjs.org'
- run: npm install -g npm@latest
shell: bash
- run: npm clean-install
- run: npm clean-install --ignore-scripts
shell: bash
19 changes: 19 additions & 0 deletions .github/docker/Dockerfile.glibc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM ubuntu:bionic AS build

# Possible values: s390x, arm64, x64
ARG NODE_ARCH
ADD https://nodejs.org/dist/v16.20.1/node-v16.20.1-linux-${NODE_ARCH}.tar.gz /
RUN mkdir -p /nodejs && tar -xzf /node-v16.20.1-linux-${NODE_ARCH}.tar.gz --strip-components=1 -C /nodejs
ENV PATH=$PATH:/nodejs/bin

WORKDIR /kerberos
COPY . .

RUN apt-get -qq update && apt-get -qq install -y python3 build-essential && ldd --version

RUN npm clean-install --ignore-scripts
RUN npm run prebuild

FROM scratch

COPY --from=build /kerberos/prebuilds/ /
66 changes: 66 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
on:
pull_request:
branches: [main]
workflow_dispatch: {}

name: Build and Test

permissions:
contents: write
pull-requests: write
id-token: write

jobs:
host_builds:
strategy:
matrix:
os: [macos-latest, windows-2019]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

- name: Build ${{ matrix.os }} Prebuild
run: |
npm clean-install --ignore-scripts
npm run prebuild
- id: upload
name: Upload prebuild
uses: actions/upload-artifact@v4
with:
name: build-${{ matrix.os }}
path: prebuilds/
if-no-files-found: 'error'
retention-days: 1
compression-level: 0

container_builds:
outputs:
artifact_id: ${{ steps.upload.outputs.artifact-id }}
runs-on: ubuntu-latest
strategy:
matrix:
linux_arch: [s390x, arm64, amd64]
steps:
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Run Buildx
run: |
docker buildx create --name builder --bootstrap --use
docker buildx build --platform linux/${{ matrix.linux_arch }} --output type=local,dest=./prebuilds,platform-split=false -f ./.github/docker/Dockerfile.glibc .
- id: upload
name: Upload prebuild
uses: actions/upload-artifact@v4
with:
name: build-linux-${{ matrix.linux_arch }}
path: prebuilds/
if-no-files-found: 'error'
retention-days: 1
compression-level: 0
35 changes: 24 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,42 @@
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch: {}

name: Release

permissions:
contents: write
pull-requests: write
id-token: write

name: release

jobs:
release-please:
release_please:
runs-on: ubuntu-latest
outputs:
release_created: ${{ steps.release.outputs.release_created }}
steps:
- id: release
uses: googleapis/release-please-action@v4

# If release-please created a release, publish to npm
- if: ${{ steps.release.outputs.release_created }}
uses: actions/checkout@v4
- if: ${{ steps.release.outputs.release_created }}
name: actions/setup
uses: ./.github/actions/setup
- if: ${{ steps.release.outputs.release_created }}
run: npm publish --provenance
build:
needs: [release_please]
name: "Build native code"
uses: ./.github/workflows/build.yml

publish:
needs: [release_please, build]
environment: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Node and dependencies
uses: baileympearson/drivers-github-tools/node/setup@add-signing-env-action-for-node

- run: npm publish --provenance --tag=latest
if: ${{ needs.release_please.outputs.release_created }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,49 @@ Now you can install `kerberos` with the following:
npm install kerberos
```

#### Prebuild Platforms

Below are the platforms that are available as prebuilds on each github release.
`prebuild-install` downloads these automatically depending on the platform you are running npm install on.

- Linux GLIBC 2.23 or later
- s390x
- arm64
- x64
- MacOS universal binary
- x64
- arm64
- Windows
- x64

### Release Integrity

Releases are created automatically and signed using the [Node team's GPG key](https://pgp.mongodb.com/node-driver.asc). This applies to the git tag as well as all release packages provided as part of a GitHub release. To verify the provided packages, download the key and import it using gpg:

```
gpg --import node-driver.asc
```

The GitHub release contains a detached signature file for the NPM package (named
`kerberos-X.Y.Z.tgz.sig`).

The following command returns the link npm package.
```shell
npm view [email protected] dist.tarball
```

Using the result of the above command, a `curl` command can return the official npm package for the release.

To verify the integrity of the downloaded package, run the following command:
```shell
gpg --verify kerberos-X.Y.Z.tgz.sig kerberos-X.Y.Z.tgz
```

>[!Note]
No verification is done when using npm to install the package. To ensure release integrity when using npm, download the tarball manually from the GitHub release, verify the signature, then install the package from the downloaded tarball using npm install mongodb-X.Y.Z.tgz.

To verify the native `.node` packages, follow the same steps as above.

### Testing

Run the test suite using:
Expand Down
10 changes: 9 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
'xcode_settings': {
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'CLANG_CXX_LIBRARY': 'libc++',
'MACOSX_DEPLOYMENT_TARGET': '10.12'
'MACOSX_DEPLOYMENT_TARGET': '10.12',
"OTHER_CFLAGS": [
"-arch x86_64",
"-arch arm64"
],
"OTHER_LDFLAGS": [
"-arch x86_64",
"-arch arm64"
]
},
'cflags!': [ '-fno-exceptions' ],
'cflags_cc!': [ '-fno-exceptions' ],
Expand Down
Loading

0 comments on commit c00034b

Please sign in to comment.