From ee715f62736d7e260bfa62a0bb9a1541c41a864c Mon Sep 17 00:00:00 2001 From: Luis Lobo Borobia Date: Sat, 30 Sep 2023 23:18:22 -0500 Subject: [PATCH] Switch to Github Actions --- .github/workflows/lint.yaml | 25 ++++++++++ .github/workflows/test-ubuntu.yaml | 42 +++++++++++++++++ .github/workflows/test-windows.yaml | 62 ++++++++++++++++++++++++ .travis.yml | 70 ---------------------------- appveyor.yml | 67 -------------------------- docker-compose.yml | 44 ++++++++--------- package.json | 28 +++++------ scripts/appveyor/install_mongodb.ps1 | 20 -------- scripts/travis/install_mongodb.sh | 2 +- test/run-adapter-specific-tests.js | 1 - 10 files changed, 168 insertions(+), 193 deletions(-) create mode 100644 .github/workflows/lint.yaml create mode 100644 .github/workflows/test-ubuntu.yaml create mode 100644 .github/workflows/test-windows.yaml delete mode 100644 .travis.yml delete mode 100644 appveyor.yml delete mode 100644 scripts/appveyor/install_mongodb.ps1 diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 000000000..e26fbfa9a --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,25 @@ +name: sails-mongo lint + +on: + push + +jobs: + lint: + runs-on: ubuntu-22.04 + + strategy: + matrix: + node-version: [20] + + steps: + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install dependencies + run: | + npm install --no-audit --no-fund + + - name: Lint the code + run: | + npm run lint-test diff --git a/.github/workflows/test-ubuntu.yaml b/.github/workflows/test-ubuntu.yaml new file mode 100644 index 000000000..79f636983 --- /dev/null +++ b/.github/workflows/test-ubuntu.yaml @@ -0,0 +1,42 @@ +name: sails-mongo test (Ubuntu) + +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: + test-ubuntu: + runs-on: ubuntu-22.04 + container: node:${{ matrix.node-version }} + + strategy: + matrix: + node-version: [16, 18, 20] + mongodb-version: ['4.4', '5', '6', '7'] + + services: + mongo: + image: mongo:${{ matrix.mongodb-version }} + ports: + - 27027:27017 + + steps: + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install dependencies + run: | + node --eval "console.log('Running Node.js: ' + process.version)" + node --eval "console.log('Current directory: ' + process.cwd())" + node --eval "console.log('Files in directory: ' + require('fs').readdirSync(process.cwd()))" + npm install --no-audit --no-fund + + - name: Test it out + run: | + npm run custom-tests diff --git a/.github/workflows/test-windows.yaml b/.github/workflows/test-windows.yaml new file mode 100644 index 000000000..059838402 --- /dev/null +++ b/.github/workflows/test-windows.yaml @@ -0,0 +1,62 @@ +name: sails-mongo test (Windows) + +on: + push + +env: + WATERLINE_ADAPTER_TESTS_URL: 127.0.0.1/testdb + WATERLINE_ADAPTER_TESTS_HOST: 127.0.0.1 + WATERLINE_ADAPTER_TESTS_DATABASE: sails-mongo + NODE_ENV: test + +jobs: + test-windows: + runs-on: windows-2022 + + strategy: + matrix: + node-version: [16.x, 18.x, 20.x] + mongodb-version: ['5.0'] + + steps: + - uses: ankane/setup-mongodb@ce30d9041565cb469945895d5bde3384a254dd2e # use commit ID until action is versioned, see https://github.com/ankane/setup-mongodb/issues/2 + with: + mongodb-version: ${{ matrix.mongodb-version }} + + - name: Wait for MongoDB to start + run: | + while ($true) { + $status = Get-Service MongoDB | Select-Object -ExpandProperty Status + if ($status -eq "Running") { + Write-Host "MongoDB is running." + break + } + Write-Host "Waiting for MongoDB to start..." + Start-Sleep -Seconds 5 + } + shell: pwsh + + - name: Install Mongodb Shell + run: | + choco install mongodb-shell -y + shell: pwsh + + - name: Check connection to Mongodb using mongodb shell + run: | + mongosh --eval "db.adminCommand('listDatabases')" + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Checkout repository + uses: actions/checkout@v3 + + - 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/docker-compose.yml b/docker-compose.yml index f4a773433..ebaa59eed 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,22 +1,24 @@ -adapter: - image: node:12 - volumes: - - $PWD:/home/node/sails-mongo - links: - - mongo - environment: - - WATERLINE_ADAPTER_TESTS_DATABASE=sails-mongo - - WATERLINE_ADAPTER_TESTS_URL=mongo/testdb - - WATERLINE_ADAPTER_TESTS_HOST=mongo - - NODE_ENV=test - user: node - working_dir: /home/node/sails-mongo - command: - - bash -c "npm test" +version: "3.8" +services: + adapter: + image: node:20 + volumes: + - $PWD:/home/node/sails-mongo + links: + - mongo + environment: + - WATERLINE_ADAPTER_TESTS_DATABASE=sails-mongo + - WATERLINE_ADAPTER_TESTS_URL=mongo/testdb + - WATERLINE_ADAPTER_TESTS_HOST=mongo + - NODE_ENV=test + user: node + working_dir: /home/node/sails-mongo + command: + - bash -c "npm test" -mongo: - image: mongo:4.2 - restart: always - command: "--logpath=/dev/null" - ports: - - "27017:27017" + mongo: + image: mongo:7 + restart: always + command: "--logpath=/dev/null" + ports: + - "27017:27017" diff --git a/package.json b/package.json index 842ac4f32..1a6f6c85c 100644 --- a/package.json +++ b/package.json @@ -4,14 +4,15 @@ "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", - "stop-mongodb": "docker-compose down", - "docker": "docker-compose run adapter bash", - "mongodb-shell": "docker-compose exec mongo mongo", - "docker-test": "docker-compose run adapter bash -c \"npm test\" && docker-compose down" + "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 mongosh", + "docker-test": "docker compose run adapter bash -c \"npm test\" && docker compose down" }, "keywords": [ "mongo", @@ -30,7 +31,7 @@ "url": "git://github.com/balderdashy/sails-mongo.git" }, "dependencies": { - "@sailshq/lodash": "^3.10.4", + "@sailshq/lodash": "3.10.4", "async": "3.2.4", "flaverr": "^1.10.0", "machine": "^15.2.2", @@ -39,12 +40,13 @@ }, "devDependencies": { "benchmark": "2.1.4", - "eslint": "8.41.0", - "eslint-plugin-eslint-comments": "^3.2.0", + "eslint": "8.50.0", + "eslint-plugin-eslint-comments": "3.2.0", "mocha": "3.0.2", - "waterline": "^0.13.6", - "waterline-adapter-tests": "^1.0.1", - "waterline-utils": "^1.4.2" + "debug": "4.3.4", + "waterline": "0.15.2", + "waterline-adapter-tests": "1.0.1", + "waterline-utils": "1.4.5" }, "waterlineAdapter": { "interfaces": [ 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 diff --git a/test/run-adapter-specific-tests.js b/test/run-adapter-specific-tests.js index 946cdfcd9..1eeeb88a3 100644 --- a/test/run-adapter-specific-tests.js +++ b/test/run-adapter-specific-tests.js @@ -775,4 +775,3 @@ function createModel(identity, options) { return model; } -