From 07dff61fd28e64e5731395531bec69f76fa25401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Susa=C3=B1a?= Date: Fri, 13 Sep 2024 19:31:44 -0400 Subject: [PATCH] Execute all scripts before publish (#6) * fix(test): redis adapter * ci: check * ups * fix: xd? * redis? * ups 2 --- .github/workflows/check.yml | 59 +++++++++++++++++++++++ .github/workflows/pkg.yml | 25 ---------- package.json | 4 +- packages/cooldown/package.json | 3 +- packages/cooldown/test/manager.test.js | 6 +-- packages/redis-adapter/test/cache.test.js | 14 ++---- turbo.json | 21 +++----- 7 files changed, 78 insertions(+), 54 deletions(-) create mode 100644 .github/workflows/check.yml delete mode 100644 .github/workflows/pkg.yml diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..c922c41 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,59 @@ +name: Build, Lint, Format & Publish +on: + push: + +jobs: + build: + runs-on: ubuntu-latest + + services: + redis: + image: redis:latest + ports: + - 6379:6379 + + steps: + - name: check out code + uses: actions/checkout@v4 + with: + ref: ${{ github.ref }} + + - run: corepack enable + - uses: actions/setup-node@v4 + with: + node-version: '20.x' + registry-url: 'https://registry.npmjs.org' + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + # For some reason, in actions, run check can execute test before build + - name: Run formating + run: pnpm run format lint + id: biome + + - name: Building + run: pnpm run build + id: build + + - name: Testing + run: pnpm run test + id: test + + - name: Commit and Push changes + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com' + git add -A + if ! git diff-index --quiet HEAD; then + git commit -m "chore: apply formatting" + git push origin HEAD:${{ github.ref }} + fi + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + HUSKY: 0 + + - name: Publish in pkg.pr.new + run: pnpx pkg-pr-new publish './packages/*' + if: github.repository == 'tiramisulabs/extra' \ No newline at end of file diff --git a/.github/workflows/pkg.yml b/.github/workflows/pkg.yml deleted file mode 100644 index 2828dac..0000000 --- a/.github/workflows/pkg.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Publish Any Commit -on: - push: - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - run: corepack enable - - uses: actions/setup-node@v4 - with: - node-version: 20 - cache: "pnpm" - - - name: Install dependencies - run: pnpm install - - - name: Build - run: pnpm build - - - run: pnpx pkg-pr-new publish './packages/*' diff --git a/package.json b/package.json index ce644cc..b575435 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,9 @@ "build": "turbo build", "dev": "turbo dev", "lint": "turbo lint", - "format": "turbo format" + "format": "turbo format", + "test": "turbo test", + "check": "turbo run lint format build test" }, "devDependencies": { "@biomejs/biome": "1.8.3", diff --git a/packages/cooldown/package.json b/packages/cooldown/package.json index fb7be4e..857ffc2 100644 --- a/packages/cooldown/package.json +++ b/packages/cooldown/package.json @@ -17,8 +17,7 @@ "build": "tsc", "lint": "biome lint --write ./src", "format": "biome format --write ./src", - "turbo:build": "turbo build", - "test": "pnpm turbo:build && node --test ./test/*" + "test": "node --test ./test/*" }, "devDependencies": { "@types/node": "^22.4.0", diff --git a/packages/cooldown/test/manager.test.js b/packages/cooldown/test/manager.test.js index ee18138..017993f 100644 --- a/packages/cooldown/test/manager.test.js +++ b/packages/cooldown/test/manager.test.js @@ -17,7 +17,7 @@ describe('CooldownManager', async () => { const handler = new CommandHandler(new Logger({ active: true }), client); cooldownData = { type: CooldownType.User, - interval: 10000, + interval: 1000, uses: 3 } handler.values = [ @@ -39,7 +39,7 @@ describe('CooldownManager', async () => { const data = cooldownManager.getCommandData('testCommand'); assert.deepEqual(data, { type: CooldownType.User, - interval: 10000, + interval: 1000, uses: 3 }); }); @@ -86,7 +86,7 @@ describe('CooldownManager', async () => { cooldownManager.use('testCommand', 'user1'); // Simulate time passing - await new Promise(resolve => setTimeout(resolve, 10000)); + await new Promise(resolve => setTimeout(resolve, 1000)); const data = cooldownManager.resource.get('testCommand:user:user1'); const props = cooldownManager.getCommandData('testCommand'); diff --git a/packages/redis-adapter/test/cache.test.js b/packages/redis-adapter/test/cache.test.js index df080d4..20876b1 100644 --- a/packages/redis-adapter/test/cache.test.js +++ b/packages/redis-adapter/test/cache.test.js @@ -1,7 +1,6 @@ -const { describe, test, after, before } = require('node:test'); -const { Cache, Client } = require('seyfert'); +const { describe, test } = require('node:test'); +const { Client } = require('seyfert'); const { RedisAdapter } = require('../lib/index'); -const { setTimeout } = require('node:timers/promises'); const { doesNotThrow } = require('node:assert/strict'); // all intents @@ -33,13 +32,8 @@ describe('Test Adapter cache', async t => { } }) await client.cache.testAdapter(); - }); - await setTimeout(2e3); - }); - - after(async () => { - await adapter.flush() - await adapter.client.quit(); + await adapter.client.quit(); + }); }); }); diff --git a/turbo.json b/turbo.json index d3cba46..4c91f50 100644 --- a/turbo.json +++ b/turbo.json @@ -3,26 +3,21 @@ "ui": "tui", "tasks": { "build": { - "dependsOn": [ - "^build" - ], - "outputs": [ - "lib/**" - ] + "dependsOn": ["^build"], + "outputs": ["lib/**"] }, "lint": { - "dependsOn": [ - "^lint" - ] + "dependsOn": ["^lint"] }, "format": { - "dependsOn": [ - "^format" - ] + "dependsOn": ["^format"] + }, + "test": { + "dependsOn": ["^test"] }, "dev": { "cache": false, "persistent": true } } -} \ No newline at end of file +}