diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf39eb5..ed842bc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,14 +1,32 @@ -name: ci +name: CI -on: - push: - branches: - - master - pull_request: +on: [push, pull_request] jobs: - build: + lint: runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v3 + + - name: Install Dependency + run: npm install + + - name: Run Lint + run: npm run lint + + - name: Run Format Check + run: npm run format:check + + coverage: + needs: [lint] + runs-on: ubuntu-latest + permissions: + contents: read services: postgres: @@ -30,35 +48,97 @@ jobs: steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 with: - node-version: 22.21.1 - - run: npm i - - run: npx prisma generate - - run: npx prisma db push - - run: npm run format:check - - run: npm run lint - - run: npx jest --coverage --forceExit - - name: Coveralls Parallel + node-version: ^20 + + - name: Install Dependency + run: npm install + + - name: Generate Prisma Client + run: npx prisma generate + + - name: Push Database Schema + run: npx prisma db push + + - name: Run Coverage + run: npx jest --coverage --forceExit + + - name: Coveralls uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} + parallel: true - finish: - needs: build + test: + needs: [lint] runs-on: ubuntu-latest + permissions: + contents: read + strategy: + matrix: + node: [^20] + + services: + postgres: + image: postgres:latest + ports: + - 5432:5432 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: casbin + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + env: + DATABASE_URL: postgresql://postgres:postgres@localhost:5432/casbin + steps: - - name: Coveralls Finished - uses: coverallsapp/github-action@master + - uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v3 with: - github-token: ${{ secrets.GITHUB_TOKEN }} - parallel-finished: true + node-version: ${{ matrix.node }} + + - name: Install Dependency + run: npm install + + - name: Generate Prisma Client + run: npx prisma generate + + - name: Push Database Schema + run: npx prisma db push + + - name: Run Unit test + run: npm run test + + semantic-release: + needs: [lint, test, coverage] + runs-on: ubuntu-latest + permissions: + contents: write + packages: write + steps: - uses: actions/checkout@v2 - - run: npm i - - run: npm run build - - name: Release - if: github.event_name == 'push' && github.repository == 'node-casbin/prisma-adapter' - run: npx semantic-release + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: ^20 + + - name: Run semantic-release + if: github.repository == 'node-casbin/prisma-adapter' && github.event_name == 'push' + run: | + npm install + npm run build + npx semantic-release env: - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/README.md b/README.md index 2679636..bd99c11 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,15 @@ # Prisma Adapter +[![CI](https://github.com/node-casbin/prisma-adapter/actions/workflows/ci.yml/badge.svg)](https://github.com/node-casbin/prisma-adapter/actions/workflows/ci.yml) +[![Coverage Status](https://coveralls.io/repos/github/node-casbin/prisma-adapter/badge.svg?branch=master)](https://coveralls.io/github/node-casbin/prisma-adapter?branch=master) [![NPM version][npm-image]][npm-url] [![NPM download][download-image]][download-url] -[![Build Status][ci-image]][ci-url] [![Discord](https://img.shields.io/discord/1022748306096537660?logo=discord&label=discord&color=5865F2)](https://discord.gg/S5UjpzGZjN) -[npm-image]: https://img.shields.io/npm/v/casbin-prisma-adapter.svg -[npm-url]: https://npmjs.org/package/casbin-prisma-adapter -[download-image]: https://img.shields.io/npm/dm/casbin-prisma-adapter.svg -[download-url]: https://npmjs.org/package/casbin-prisma-adapter -[ci-image]: https://github.com/node-casbin/prisma-adapter/workflows/ci/badge.svg?branch=master -[ci-url]: https://github.com/node-casbin/prisma-adapter/actions +[npm-image]: https://img.shields.io/npm/v/casbin-prisma-adapter.svg?style=flat-square +[npm-url]: https://npmjs.com/package/casbin-prisma-adapter +[download-image]: https://img.shields.io/npm/dm/casbin-prisma-adapter.svg?style=flat-square +[download-url]: https://npmjs.com/package/casbin-prisma-adapter Prisma Adapter is the [Prisma](https://github.com/prisma/prisma) adapter for [Node-Casbin](https://github.com/casbin/node-casbin). With this library, Node-Casbin can load policy from Prisma supported database or save policy to it.