From 39d898a98dd7e1b9229520deb3ad76f84c173807 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Tue, 11 Jun 2024 10:04:57 -0600 Subject: [PATCH] ci(NODE-6185): add test and lint tasks to CI (#4) --- .github/docker/Dockerfile.glibc | 3 ++- .github/workflows/build.yml | 6 +++++- .github/workflows/lint.yml | 38 +++++++++++++++++++++++++++++++++ package.json | 1 + test/release.test.ts | 14 +++++++++--- 5 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/lint.yml diff --git a/.github/docker/Dockerfile.glibc b/.github/docker/Dockerfile.glibc index c114db0..d15188a 100644 --- a/.github/docker/Dockerfile.glibc +++ b/.github/docker/Dockerfile.glibc @@ -4,7 +4,8 @@ FROM $NODE_BUILD_IMAGE AS build WORKDIR /mongodb-client-encryption COPY . . -RUN node /mongodb-client-encryption/.github/scripts/libmongocrypt.mjs +RUN npm run install:libmongocrypt +RUN npm run test FROM scratch diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 25c60bd..a96ea03 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,7 +5,7 @@ on: branches: [main] workflow_dispatch: {} -name: build +name: Build and Test jobs: host_builds: @@ -20,6 +20,10 @@ jobs: run: node .github/scripts/libmongocrypt.mjs ${{ runner.os == 'Windows' && '--build' || '' }} shell: bash + - name: Test ${{ matrix.os }} + shell: bash + run: npm run test + - id: upload name: Upload prebuild uses: actions/upload-artifact@v4 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..5b71978 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,38 @@ +name: Lint + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + + name: ${{ matrix.lint-target }} + strategy: + matrix: + lint-target: ["c++", "typescript"] + + steps: + - uses: actions/checkout@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - name: "Build libmongocrypt" + shell: bash + run: | + npm run install:libmongocrypt + + - if: matrix.lint-target == 'c++' + shell: bash + run: | + npm run check:clang-format + + - if: matrix.lint-target == 'typescript' + shell: bash + run: | + npm run check:eslint diff --git a/package.json b/package.json index 090045a..b7dc921 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "lib": "lib" }, "scripts": { + "install:libmongocrypt": "node .github/scripts/libmongocrypt.mjs", "install": "prebuild-install --runtime napi || node-gyp rebuild", "clang-format": "clang-format --style=file:.clang-format --Werror -i addon/*", "check:eslint": "eslint src test", diff --git a/test/release.test.ts b/test/release.test.ts index 11e1250..c503c22 100644 --- a/test/release.test.ts +++ b/test/release.test.ts @@ -24,8 +24,14 @@ const REQUIRED_FILES = [ describe(`Release ${packFile}`, function () { this.timeout(10000); + beforeEach(function () { + if (process.arch !== 'x64') { + this.skip(); + } + }); + let tarFileList; - before(() => { + beforeEach(() => { expect(fs.existsSync(packFile)).to.equal(false); cp.execSync('npm pack', { stdio: 'ignore' }); tarFileList = []; @@ -38,8 +44,10 @@ describe(`Release ${packFile}`, function () { }); }); - after(() => { - fs.unlinkSync(packFile); + afterEach(() => { + if (process.arch === 'x64') { + fs.unlinkSync(packFile); + } }); for (const requiredFile of REQUIRED_FILES) {