From a3917ea19e98e54d8932395c21f789d2c1a51a5f Mon Sep 17 00:00:00 2001 From: eslam3bed <20760072+Eslam3bed@users.noreply.github.com> Date: Sun, 22 Sep 2024 19:15:29 +0300 Subject: [PATCH] update the test configrations and the ci/cd --- .github/workflows/ci-cd.yml | 68 +++++++++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 32 +++++++++++++++++ jest.config.js | 8 +++++ package.json | 5 ++- 4 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci-cd.yml create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml new file mode 100644 index 0000000..11f8de4 --- /dev/null +++ b/.github/workflows/ci-cd.yml @@ -0,0 +1,68 @@ +name: CI/CD Pipeline + +on: + push: + branches: + - main + release: + types: [published] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' + + - name: Install dependencies + run: npm install + + - name: Run tests + run: npm run test + + - name: Build the package + run: npm run build + + - name: Bump version and generate changelog + run: npm run release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Commit changelog and version bump + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git add . + git commit -m "chore(release): $(node -p -e "require('./package.json').version") [skip ci]" + git tag v$(node -p -e "require('./package.json').version") + + - name: Push changes to main branch + run: git push --follow-tags + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Publish to npm + if: github.event_name == 'release' && github.event.action == 'published' + run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + release: + needs: build + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Create a release on GitHub + uses: softprops/action-gh-release@v1 + with: + files: dist/* + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3d97fbb --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,32 @@ +name: Node.js CI + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [16.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm run ci + - name: Publish to npm + if: github.ref == 'refs/heads/main' + run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/jest.config.js b/jest.config.js index 0a2e077..3f8fa41 100644 --- a/jest.config.js +++ b/jest.config.js @@ -6,4 +6,12 @@ module.exports = { '\\.(css|scss)$': 'identity-obj-proxy', }, setupFilesAfterEnv: ['/src/__test__/setupTests.ts'], + coverageThreshold: { + global: { + branches: 80, + functions: 80, + lines: 80, + statements: 80, + }, + }, }; \ No newline at end of file diff --git a/package.json b/package.json index 5e5b8b2..8d3e471 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,9 @@ "module": "dist/index.esm.js", "scripts": { "build": "rollup -c ", - "test": "jest --watch " + "test": "jest --coverage", + "ci": "npm run build && npm run test", + "release": "standard-version" }, "author": "", "license": "ISC", @@ -19,6 +21,7 @@ "@types/jest": "^29.5.13", "jest": "^29.7.0", "rollup-plugin-dts": "^6.1.1", + "standard-version": "^9.5.0", "ts-jest": "^29.2.5" }, "dependencies": {