Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ If you want to push some code :
You could also be critic with existing ticket/PR : all constructive feedbacks are welcome.

## test
* launch tests using `npm test`.
* launch tests using `pnpm test`.

Think about environment setup.

## linter
* launch lint using `npm run lint`.
* launch lint using `pnpm run lint`.

About linter :
- locally ESLint 9.0 is used as dev dependencies and rely on `eslint.config.js` ([doc](https://eslint.org/docs/latest/use/configure/configuration-files))
Expand All @@ -36,7 +36,7 @@ this will make a new version and on version tag, the main ci workflow will push
# provide PAT with permissions to create release on current repository
export GREN_GITHUB_TOKEN=your_token_here
# one time setup
npm install github-release-notes -g
pnpm install github-release-notes -g

git fetch --all && git pull
# make a release vX with all history
Expand Down
31 changes: 17 additions & 14 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,35 @@ jobs:
strategy:
matrix:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
node-version: [16.x]
node-version: [ 18.x ]

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v5

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
# version from package.json
run_install: false

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v5
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: |
package-lock.json
cache: 'pnpm'

- name: Install dependencies
# - run: npm ci # need package.json.lock
run: |
echo "install"
npm install
pnpm install
echo "show outdated (if any)"
npm outdated --depth=3 || echo "you must think about update your dependencies :)"
pnpm outdated --depth=3 || echo "you must think about update your dependencies :)"

- name: Npm audit
uses: oke-py/npm-audit-action@v2
- name: pnpm audit & comment on PR
uses: JamesRobertWiseman/pnpm-audit@v1.0.6
with:
audit_level: moderate
github_token: ${{ secrets.GITHUB_TOKEN }}
dedupe_issues: true
production_flag: true
level: moderate
fails: true
97 changes: 52 additions & 45 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,63 +21,70 @@ jobs:
strategy:
matrix:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
node-version: [16.x]
node-version: [ 18.x ]

services:
mongodb:
image: mongo:4.2.11
image: mongo:5
ports:
- 27017:27017

steps:
- uses: actions/checkout@v3
- name: Checkout code
uses: actions/checkout@v5

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
# version from package.json
run_install: false

- name: Install dependencies
# npx force-resolutions : in case of Permission denied: run it locally to fix package-lock.json
run: |
echo "install"
npm run preinstall
npm install
echo "show outdated (if any)"
npm outdated --depth=3 || echo "you must think about update your dependencies :)"
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v5
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'

- name: Setup mongo tools # add mongosh and mongodump/mongorestore
uses: boly38/action-mongo-tools@stable
- name: Install dependencies
# npx force-resolutions : in case of Permission denied: run it locally to fix package-lock.json
run: |
echo "install"
pnpm run preinstall
pnpm install
echo "show outdated (if any)"
pnpm outdated --depth=3 || echo "you must think about update your dependencies :)"

- name: Setup mongo user
# doc: https://docs.mongodb.com/manual/reference/built-in-roles/ "Backup and Restoration Roles"
# doc: https://docs.mongodb.com/manual/reference/method/db.createUser/
run: mongosh admin --eval 'db.createUser({user:"root",pwd:"mypass",roles:[{"role":"readWrite","db":"myDbForTest"}, "restore"]});'
- name: Setup mongo tools # add mongosh and mongodump/mongorestore
uses: boly38/action-mongo-tools@stable

- name: Run tests
env:
MT_MONGO_USER: root
MT_MONGO_PWD: mypass
run: npm run ci-test
- name: Setup mongo user
# doc: https://docs.mongodb.com/manual/reference/built-in-roles/ "Backup and Restoration Roles"
# doc: https://docs.mongodb.com/manual/reference/method/db.createUser/
run: mongosh admin --eval 'db.createUser({user:"root",pwd:"mypass",roles:[{"role":"readWrite","db":"myDbForTest"}, "restore"]});'

- name: Report coverage
continue-on-error: true
uses: romeovs/lcov-reporter-action@v0.2.16
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
lcov-file: ./coverage/lcov.info
- name: Run tests
env:
MT_MONGO_USER: root
MT_MONGO_PWD: mypass
run: pnpm run ci-test

- name: Npm audit
uses: oke-py/npm-audit-action@v2
with:
audit_level: moderate
github_token: ${{ secrets.GITHUB_TOKEN }}
dedupe_issues: true
production_flag: true
- name: Report coverage
continue-on-error: true
uses: romeovs/lcov-reporter-action@v0.3.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
lcov-file: ./coverage/lcov.info

- name: Publish NpmJS package
if: github.ref == 'refs/heads/npmjs'
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_DEPLOY_TOKEN }}" > .npmrc
npm whoami # rely on .npmrc
npm publish
- name: pnpm audit & comment on PR
uses: JamesRobertWiseman/pnpm-audit@v1.0.6
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
level: moderate
fails: true

- name: Publish NpmJS package
if: github.ref == 'refs/heads/npmjs'
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_DEPLOY_TOKEN }}" > .npmrc
npm whoami # rely on .npmrc
npm publish
20 changes: 12 additions & 8 deletions .github/workflows/major.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,30 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
node-version: [18.x]

steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Checkout code
uses: actions/checkout@v5

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
ref: 'npmjs'
token: ${{ secrets.GH_ACTIONS_TOKEN }}
# version from package.json
run_install: false

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v5
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'

- name: Major
run: |
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git config --global user.name 'github-actions[bot]'
git fetch --all
git checkout main
npm version major
pnpm version major
git branch -f npmjs
git push origin main npmjs --tags
18 changes: 11 additions & 7 deletions .github/workflows/minor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,27 @@ jobs:
node-version: [16.x]

steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Checkout code
uses: actions/checkout@v5

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
ref: 'npmjs'
token: ${{ secrets.GH_ACTIONS_TOKEN }}
# version from package.json
run_install: false

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v5
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'

- name: Minor
run: |
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git config --global user.name 'github-actions[bot]'
git fetch --all
git checkout main
npm version minor
pnpm version minor
git branch -f npmjs
git push origin main npmjs --tags
18 changes: 11 additions & 7 deletions .github/workflows/patch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,27 @@ jobs:
node-version: [16.x]

steps:
- name: Git checkout
uses: actions/checkout@v2
- name: Checkout code
uses: actions/checkout@v5

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
ref: 'npmjs'
token: ${{ secrets.GH_ACTIONS_TOKEN }}
# version from package.json
run_install: false

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v5
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'

- name: Patch
run: |
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git config --global user.name 'github-actions[bot]'
git fetch --all
git checkout main
npm version patch
pnpm version patch
git branch -f npmjs
git push origin main npmjs --tags
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ You should decide to install it globally without getting source or by cloning re

### Install globally (beta)
```bash
npm install -g node-mongotools@latest
pnpm install -g node-mongotools@latest
```
When using a global install `node-mongotools` command must be directly available (ie. you can replace `node mt` by `node-mongotools` in examples).

You could revert thins by using
```bash
npm uninstall -g node-mongotools
pnpm uninstall -g node-mongotools
```

### Install by getting source
```bash
git clone https://github.com/boly38/node-mongotools.git
# install dependencies
npm install
pnpm install
```

### Environment setup - first time only
Expand Down Expand Up @@ -121,7 +121,7 @@ node mt rotation

You have to import as dependency
```
npm install node-mongotools
pnpm install node-mongotools
```

### Define the requirements, example:
Expand Down Expand Up @@ -326,8 +326,8 @@ You're not a dev ? just submit an issue (bug, improvements, questions). Or else:
* Then mocha tests
```
git clone https://github.com/boly38/node-mongotools.git
npm install
npm run test
pnpm install
pnpm run test
```
* you could also fork, feature branch, then submit a pull request.

Expand Down
2 changes: 1 addition & 1 deletion lib/MTFilesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MTFilesystem {
listFromFilesystem(path) {
return new Promise((resolve, reject) => {
if (!fs.existsSync(path)) {
return reject(new Error(`no dump path ${path}`));
fs.mkdirSync(path, {recursive: true});
}
fs.readdir(path, (err, files) => {
if (err) {
Expand Down
Loading