diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 000000000..175f3135b --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,142 @@ +name: Node CI + +on: + push + +env: + WATERLINE_ADAPTER_TESTS_URL: mongo/testdb:27027 + WATERLINE_ADAPTER_TESTS_HOST: mongo + WATERLINE_ADAPTER_TESTS_DATABASE: sails-mongo + NODE_ENV: test + +jobs: + lint-and-test-ubuntu: + runs-on: ubuntu-20.04 + container: node:${{ matrix.node-version }} + + # Service containers to run with `container-job` + services: + # Label used to access the service container + mongo: + # Docker Hub image + image: mongo:${{ matrix.mongodb-version }} + # Set health checks to wait until redis has started + options: >- + --health-cmd "mongo --eval 'db.runCommand({ ping: 1 })'" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 27027:27017 + + strategy: + matrix: + node-version: [16, 18, 20] + mongodb-version: ['4.4', '5.0'] + + steps: + + - name: Checkout repository + uses: actions/checkout@v3 + +# - name: Cache node modules +# id: cache-npm +# uses: actions/cache@v3 +# env: +# cache-name: cache-node-modules +# with: +# # npm cache files are stored in `~/.npm` on Linux/macOS +# path: ~/.npm +# key: build-${{ env.cache-name }}-${{ matrix.node-version }}-${{ hashFiles('**/package.json') }} +# restore-keys: | +# ${{ runner.os }}-build-${{ env.cache-name }}- +# ${{ runner.os }}-build- +# ${{ runner.os }}- +# +# - if: ${{ steps.cache-npm.outputs.cache-hit != 'true' }} +# name: List the state of node modules +# continue-on-error: true +# run: npm list + + - name: Install dependencies + run: | + npm install --no-audit --no-fund + + - name: Lint the code + run: | + npm run lint-test + if: matrix.node-version == '16' + + - name: Test it out + run: | + npm run custom-tests + +# lint-and-test-windows: +# runs-on: windows-2022 +# +# strategy: +# matrix: +# node-version: [16.x] # , 18.x, 20.x] +# mongodb-version: [4.4] +# +# steps: +# - name: Use MongoDB ${{ matrix.mongodb-version }} +# run: | +# # Get versions +# $url = "https://raw.githubusercontent.com/mkevenaar/chocolatey-packages/master/automatic/mongodb.portable/mongodb.portable.json" +# $response = Invoke-WebRequest -Uri $url +# $content = $response.Content.TrimStart([Char]0xFEFF) # Remove BOM +# $global:versions = $content | ConvertFrom-Json +# $version = "${{ matrix.mongodb-version }}" +# +# $fullVersion = $global:versions.$version +# $url = "https://fastdl.mongodb.org/windows/mongodb-windows-x86_64-$fullVersion.zip" +# $zipfile = "mongodb.zip" +# Invoke-WebRequest -Uri $url -OutFile $zipfile +# +# $destination = "C:\mongodb" +# $mongodbPath = "$destination\$version" +# & Expand-Archive -LiteralPath $zipfile -DestinationPath $destination +# & Move-Item -Path "$destination\mongodb-win32-x86_64-windows-$fullVersion" -Destination "$mongodbPath" +# dir $destination +# +# $dataDir = Join-Path -Path $mongodbPath -ChildPath "\data\db" +# New-Item -ItemType Directory -Force -Path $dataDir +# $port = 27027 +# & Start-Process -NoNewWindow "$mongodbPath\bin\mongod.exe" -ArgumentList '--quiet', '--dbpath', $dataDir, '--port', $port, '--nojournal', '--oplogSize', 1, '--bind_ip', '127.0.0.1' +# +# echo "Checking MongoDB $version instance..." +# $connected = $false +# $attempts = 0 +# do { +# & "$mongodbPath\bin\mongo.exe" --port "$port" --eval "db.runCommand({ ping: 1 })" +# if ($LASTEXITCODE -eq 0) { +# $connected = $true +# } else { +# Write-Output "Unable to connect, retrying..." +# Start-Sleep -Seconds 1 +# $attempts++ +# } +# } while (!$connected -and $attempts -lt 10) +# +# if (!$connected) { +# Write-Output "Failed to connect to MongoDB $version instance after 10 attempts" +# exit 1 +# } +# +# - name: Checkout repository +# uses: actions/checkout@v3 +# +# - name: Use Node.js ${{ matrix.node-version }} +# uses: actions/setup-node@v3 +# with: +# node-version: ${{ matrix.node-version }} +# +# - name: Install dependencies +# run: | +# npm install --no-audit --no-fund +# +# - name: Test code +# run: | +# npm run custom-tests + diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index bfbf3773f..000000000 --- a/.travis.yml +++ /dev/null @@ -1,70 +0,0 @@ -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # -# ╔╦╗╦═╗╔═╗╦ ╦╦╔═╗ ┬ ┬┌┬┐┬ # -# ║ ╠╦╝╠═╣╚╗╔╝║╚═╗ └┬┘││││ # -# o ╩ ╩╚═╩ ╩ ╚╝ ╩╚═╝o ┴ ┴ ┴┴─┘ # -# # -# This file configures Travis CI. # -# (i.e. how we run the tests... mainly) # -# # -# https://docs.travis-ci.com/user/customizing-the-build # -# # # # # # # # # # # # # # # # # # # # # # # # # # # # # - -dist: xenial - -language: node_js - -node_js: - - "16" - - "18" - - "19" - - "20" - -env: - global: - - WATERLINE_ADAPTER_TESTS_URL=localhost/testdb - - WATERLINE_ADAPTER_TESTS_HOST=localhost - - WATERLINE_ADAPTER_TESTS_DATABASE=sails-mongo - - NODE_ENV=test - - matrix: - - MONGODB=3.6.18 - - MONGODB=4.0.18 - - MONGODB=4.2.7 - -cache: - directories: - - "$TRAVIS_BUILD_DIR/mongodb" - - "$HOME/.npm" - -matrix: - fast_finish: true - -before_install: - - chmod +x "$TRAVIS_BUILD_DIR/scripts/travis/install_mongodb.sh" "$TRAVIS_BUILD_DIR/scripts/travis/run_mongodb.sh" - - npm i -g npm@8.11.0 - -install: - # Don't let npm send metrics as it creates a file in the .npm folder invalidating the cache every time - - npm config set send-metrics false - - npm i --no-audit - - "$TRAVIS_BUILD_DIR/scripts/travis/install_mongodb.sh" - -before_script: - - "$TRAVIS_BUILD_DIR/scripts/travis/run_mongodb.sh" - -script: - - npm test - -after_script: - - pkill mongod - -branches: - only: - - master - - upgrade-mongodb-drivers - - update-test-environment - -notifications: - email: - - ci@sailsjs.com - - luislobo@gmail.com diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index c68b2724d..000000000 --- a/appveyor.yml +++ /dev/null @@ -1,67 +0,0 @@ -# # # # # # # # # # # # # # # # # # # # # # # # # # -# ╔═╗╔═╗╔═╗╦ ╦╔═╗╦ ╦╔═╗╦═╗ ┬ ┬┌┬┐┬ # -# ╠═╣╠═╝╠═╝╚╗╔╝║╣ ╚╦╝║ ║╠╦╝ └┬┘││││ # -# ╩ ╩╩ ╩ ╚╝ ╚═╝ ╩ ╚═╝╩╚═o ┴ ┴ ┴┴─┘ # -# # -# This file configures Appveyor CI. # -# (i.e. how we run the tests on Windows) # -# # -# https://www.appveyor.com/docs/lang/nodejs-iojs/ # -# # # # # # # # # # # # # # # # # # # # # # # # # # - - -# Test against these versions of Node.js. -environment: - WATERLINE_ADAPTER_TESTS_URL: localhost/testdb - WATERLINE_ADAPTER_TESTS_HOST: localhost - WATERLINE_ADAPTER_TESTS_DATABASE: sails-mongo - NODE_ENV: test - matrix: - - nodejs_version: "10" - - nodejs_version: "12" - - nodejs_version: "14" - -# Install scripts. (runs after repo cloning) -install: - # Get the latest stable version of Node.js - # (Not sure what this is for, it's just in Appveyor's example.) - - ps: Install-Product node $env:nodejs_version - # Don't let npm send metrics as it creates a file in the .npm folder invalidating the cache every time - - npm config set send-metrics false - # Install declared dependencies - - npm install --no-audit - -branches: - only: - - master - - upgrade-mongodb-drivers - - update-test-environment - -# Post-install test scripts. -test_script: - # Output Node and NPM version info. - # (Presumably just in case Appveyor decides to try any funny business? - # But seriously, always good to audit this kind of stuff for debugging.) - - node --version - - npm --version - # Run the actual tests. - - npm test - -# Setup Mongo Database -services: - - mongodb - - -# Don't actually build. -# (Not sure what this is for, it's just in Appveyor's example. -# I'm not sure what we're not building... but I'm OK with not -# building it. I guess.) -build: off - - -# # # # # # # # # # # # # # # # # # # # # # # # # # # # - -# TODO: Set up appveyor + mongo*: -# https://www.appveyor.com/docs/services-databases/ -# Old example on how to install different versions of MongoDB added to `scripts/appveyor/install_mongodb.ps1` -# # # # # # # # # # # # # # # # # # # # # # # # # # # # diff --git a/package.json b/package.json index 842ac4f32..095269e29 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,10 @@ "description": "Mongo DB adapter for Sails.js/Waterline.", "main": "./lib", "scripts": { - "test": "npm run lint && npm run custom-tests", + "test": "npm run lint-test && npm run custom-tests", "custom-tests": "node node_modules/mocha/bin/mocha test/run-adapter-specific-tests && node node_modules/mocha/bin/mocha test/connectable/ && node test/run-standard-tests", - "lint": "node node_modules/eslint/bin/eslint . --max-warnings=0", - "start-mongodb": "docker-compose up -d mongo", + "lint": "node node_modules/eslint/bin/eslint . --max-warnings=0 ", + "lint-test": "node node_modules/eslint/bin/eslint --rule \"linebreak-style: 0\" --max-warnings=0 . ", "start-mongodb": "docker-compose up -d mongo", "stop-mongodb": "docker-compose down", "docker": "docker-compose run adapter bash", "mongodb-shell": "docker-compose exec mongo mongo", diff --git a/scripts/appveyor/install_mongodb.ps1 b/scripts/appveyor/install_mongodb.ps1 deleted file mode 100644 index 0c3cfdb68..000000000 --- a/scripts/appveyor/install_mongodb.ps1 +++ /dev/null @@ -1,20 +0,0 @@ -# Example. Not yet being used -$msiPath = "$($env:USERPROFILE)\mongodb-win32-x86_64-2008plus-ssl-3.0.4-signed.msi" -(New-Object Net.WebClient).DownloadFile('https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-3.0.4-signed.msi', $msiPath) -cmd /c start /wait msiexec /q /i $msiPath INSTALLLOCATION=C:\mongodb ADDLOCAL="all" -del $msiPath - -mkdir c:\mongodb\data\db | Out-Null -mkdir c:\mongodb\log | Out-Null - -'systemLog: - destination: file - path: c:\mongodb\log\mongod.log -storage: - dbPath: c:\mongodb\data\db' | Out-File C:\mongodb\mongod.cfg -Encoding utf8 - -cmd /c start /wait sc create MongoDB binPath= "C:\mongodb\bin\mongod.exe --service --config=C:\mongodb\mongod.cfg" DisplayName= "MongoDB" start= "demand" - -& c:\mongodb\bin\mongod --version - -Start-Service mongodb diff --git a/scripts/travis/install_mongodb.sh b/scripts/travis/install_mongodb.sh index 499b7190f..edc50fdbf 100755 --- a/scripts/travis/install_mongodb.sh +++ b/scripts/travis/install_mongodb.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -MDB_TGZ=mongodb-linux-x86_64-ubuntu1604-${MONGODB}.tgz +MDB_TGZ=mongodb-linux-x86_64-ubuntu2004-${MONGODB}.tgz MDB_ROOT=${TRAVIS_BUILD_DIR}/mongodb/${MONGODB} MDB_DATA=${TRAVIS_BUILD_DIR}/mongodb-data