diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..7f80a11 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,74 @@ +name: Run Tests + +on: [push, pull_request] + +jobs: + test: + name: Test on Node ${{ matrix.node }} on ubuntu-latest with Mongoose@${{ matrix.mongoose }} + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + node: [14, 16, 18] + mongoose: [5, 6, 7] + + steps: + - name: Clone repo + uses: actions/checkout@v2 + + - name: Set Node.js version + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node }} + + - name: Install dependencies + run: | + npm install + npm install mongoose@${{ matrix.mongoose }} + + - name: Lint + run: npm run lint + + - name: Test with Coverage + run: npm run test + + - name: Publish on Coveralls + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + flag-name: node-${{ matrix.node }} + parallel: true + + report-coverage: + needs: test + runs-on: ubuntu-latest + steps: + - name: Coveralls Finished + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.github_token }} + parallel-finished: true + + publish: + needs: report-coverage + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/v') + steps: + - name: Clone repo + uses: actions/checkout@v2 + + - name: Set Node.js version + uses: actions/setup-node@v1 + with: + node-version: 16 + + - name: Check Version + run: ./version.sh + + - name: Publish to npm + run: | + cp .npmrc.config .npmrc + npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/.npmrc.config b/.npmrc.config new file mode 100644 index 0000000..696ea04 --- /dev/null +++ b/.npmrc.config @@ -0,0 +1,2 @@ +//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN} +registry=https://registry.npmjs.org \ No newline at end of file diff --git a/version.sh b/version.sh new file mode 100755 index 0000000..3e3568e --- /dev/null +++ b/version.sh @@ -0,0 +1,6 @@ +PACKAGE_NAME=$(npm pkg get name | tr -d '"') +PACKAGE_VERSION=$(npm pkg get version | tr -d '"') +PACKAGE=$PACKAGE_NAME@$PACKAGE_VERSION + +PUBLISHED_VERSION=$(npm view $PACKAGE version || echo "") +if [[ -n $PUBLISHED_VERSION ]]; then echo "The version is already published"; exit 1; fi