From 5acfa0cd58f5e026100cd8ec483c745bcfe12d41 Mon Sep 17 00:00:00 2001 From: Petr Heinz Date: Tue, 19 Sep 2023 14:36:00 +0200 Subject: [PATCH 01/13] Add CI check for Bun runtime --- .github/workflows/tests.yml | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6a30888..529ecc3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -49,3 +49,46 @@ jobs: - name: Run tests run: yarn test + + tests-bun: + runs-on: ubuntu-latest + + strategy: + matrix: + bun-version: [latest, 1.0.0] + fail-fast: false + + steps: + - uses: actions/checkout@v3 + + - name: Set up Bun ${{ matrix.bun-version }} + uses: oven-sh/setup-bun@v1 + with: + bun-version: ${{ matrix.bun-version }} + + - name: Setup yarn + run: npm install -g yarn + + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT + + - name: Cache yarn dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Bootstrap packages + run: yarn bootstrap + + - name: Build packages + run: yarn build + + - name: Run tests + run: yarn test From 387a4998f7702d9826c2bfe308feffbfb2818436 Mon Sep 17 00:00:00 2001 From: Petr Heinz Date: Tue, 19 Sep 2023 14:43:57 +0200 Subject: [PATCH 02/13] Is node installed? --- .github/workflows/tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 529ecc3..a64735a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -92,3 +92,6 @@ jobs: - name: Run tests run: yarn test + + - name: Is node installed? + run: node -v From 6da1e0f4027e103b3ed687aa64d2e69924cd9d7e Mon Sep 17 00:00:00 2001 From: Petr Heinz Date: Tue, 19 Sep 2023 15:43:55 +0200 Subject: [PATCH 03/13] Run tests in bun --- .github/workflows/tests.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a64735a..d165103 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -91,7 +91,4 @@ jobs: run: yarn build - name: Run tests - run: yarn test - - - name: Is node installed? - run: node -v + run: bun test From 9244dc15a521197f8bf12ad61d471d4965da733c Mon Sep 17 00:00:00 2001 From: Petr Heinz Date: Tue, 19 Sep 2023 15:44:46 +0200 Subject: [PATCH 04/13] Revert changes in CI: 'yarn test' runs Node, 'bun test' fails on mocked requests (and more) --- .github/workflows/tests.yml | 43 ------------------------------------- 1 file changed, 43 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d165103..6a30888 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -49,46 +49,3 @@ jobs: - name: Run tests run: yarn test - - tests-bun: - runs-on: ubuntu-latest - - strategy: - matrix: - bun-version: [latest, 1.0.0] - fail-fast: false - - steps: - - uses: actions/checkout@v3 - - - name: Set up Bun ${{ matrix.bun-version }} - uses: oven-sh/setup-bun@v1 - with: - bun-version: ${{ matrix.bun-version }} - - - name: Setup yarn - run: npm install -g yarn - - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT - - - name: Cache yarn dependencies - uses: actions/cache@v3 - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - - name: Install dependencies - run: yarn install --frozen-lockfile - - - name: Bootstrap packages - run: yarn bootstrap - - - name: Build packages - run: yarn build - - - name: Run tests - run: bun test From ddceafe866dc0fda228d244709f131b95a6d8135 Mon Sep 17 00:00:00 2001 From: Petr Heinz Date: Tue, 19 Sep 2023 15:53:51 +0200 Subject: [PATCH 05/13] Add E2E test for example project --- .github/workflows/end-to-end.yml | 60 ++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 .github/workflows/end-to-end.yml diff --git a/.github/workflows/end-to-end.yml b/.github/workflows/end-to-end.yml new file mode 100644 index 0000000..6b824d6 --- /dev/null +++ b/.github/workflows/end-to-end.yml @@ -0,0 +1,60 @@ +name: E2E Tests + +on: + push: + branches: + - master + schedule: + - cron: '20 5 * * 1' + workflow_dispatch: + +jobs: + node: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [16.x, 18.x, 20.x] + fail-fast: false + + steps: + - uses: actions/checkout@v3 + + - name: Set up Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: npm + cache-dependency-path: example-project/package-lock.json + + - name: Install dependencies + run: npm install + working-directory: ./example-project + + - name: Run tests + run: node index.js ${{ secrets.SOURCE_TOKEN }} + working-directory: ./example-project + + tests-bun: + runs-on: ubuntu-latest + + strategy: + matrix: + bun-version: [latest, 1.0.0] + fail-fast: false + + steps: + - uses: actions/checkout@v3 + + - name: Set up Bun ${{ matrix.bun-version }} + uses: oven-sh/setup-bun@v1 + with: + bun-version: ${{ matrix.bun-version }} + + - name: Install dependencies + run: bun install + working-directory: ./example-project + + - name: Run tests + run: bun run index.js ${{ secrets.SOURCE_TOKEN }} + working-directory: ./example-project From 668ddbfd12b7e3d56c4659326c827aa4b4d5493b Mon Sep 17 00:00:00 2001 From: Petr Heinz Date: Tue, 19 Sep 2023 15:54:51 +0200 Subject: [PATCH 06/13] Make test project fail when... it fails. --- example-project/index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/example-project/index.js b/example-project/index.js index e9bfa30..5902e1a 100644 --- a/example-project/index.js +++ b/example-project/index.js @@ -50,8 +50,15 @@ try { // Logging methods are async function returning Promises Promise.all([debugLog, infoLog, warningLog, errorLog]).then( - // OnResolve write message function() { - console.log("All done! You can check your logs now.") + console.info("All done! You can check your logs now."); + + console.log("Logs created: ", logger.logged); + console.log("Successfully synced logs: ", logger.synced); + + if (logger.logged !== logger.synced) { + console.error("Not all logs have been synced!"); + process.exit(1); + } } ); From ddc95a9b04d8f474442b26cab58f5a036b51568a Mon Sep 17 00:00:00 2001 From: Petr Heinz Date: Tue, 19 Sep 2023 16:08:01 +0200 Subject: [PATCH 07/13] Test invalid token --- .github/workflows/end-to-end.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/end-to-end.yml b/.github/workflows/end-to-end.yml index 6b824d6..69bdd58 100644 --- a/.github/workflows/end-to-end.yml +++ b/.github/workflows/end-to-end.yml @@ -31,10 +31,14 @@ jobs: run: npm install working-directory: ./example-project - - name: Run tests + - name: Run example project with valid token run: node index.js ${{ secrets.SOURCE_TOKEN }} working-directory: ./example-project + - name: Run example project with invalid token + run: if node index.js INVALID_TOKEN; then echo "This should have failed but didn't"; exit 1; else "Failed successfully"; fi + working-directory: ./example-project + tests-bun: runs-on: ubuntu-latest @@ -55,6 +59,10 @@ jobs: run: bun install working-directory: ./example-project - - name: Run tests + - name: Run example project with valid token run: bun run index.js ${{ secrets.SOURCE_TOKEN }} working-directory: ./example-project + + - name: Run example project with invalid token + run: if bun run index.js INVALID_TOKEN; then echo "This should have failed but didn't"; exit 1; else "Failed successfully"; fi + working-directory: ./example-project From 5e5118f93379ca11573ac175c57f3599ef544093 Mon Sep 17 00:00:00 2001 From: Petr Heinz Date: Tue, 19 Sep 2023 16:11:20 +0200 Subject: [PATCH 08/13] Run the E2E action on this branch --- .github/workflows/end-to-end.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/end-to-end.yml b/.github/workflows/end-to-end.yml index 69bdd58..deaaa53 100644 --- a/.github/workflows/end-to-end.yml +++ b/.github/workflows/end-to-end.yml @@ -4,6 +4,7 @@ on: push: branches: - master + - ph/test-bun-runtime schedule: - cron: '20 5 * * 1' workflow_dispatch: From 7d6fc0c993127a725594a0d14748dd3ba006baf8 Mon Sep 17 00:00:00 2001 From: Petr Heinz Date: Tue, 19 Sep 2023 16:17:26 +0200 Subject: [PATCH 09/13] Fix syntax of invalid token run --- .github/workflows/end-to-end.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/end-to-end.yml b/.github/workflows/end-to-end.yml index deaaa53..d7dfb51 100644 --- a/.github/workflows/end-to-end.yml +++ b/.github/workflows/end-to-end.yml @@ -37,7 +37,13 @@ jobs: working-directory: ./example-project - name: Run example project with invalid token - run: if node index.js INVALID_TOKEN; then echo "This should have failed but didn't"; exit 1; else "Failed successfully"; fi + run: | + if node index.js INVALID_TOKEN; then + echo "This should have failed but didn't" + exit 1 + else + echo "Failed successfully" + fi working-directory: ./example-project tests-bun: @@ -65,5 +71,11 @@ jobs: working-directory: ./example-project - name: Run example project with invalid token - run: if bun run index.js INVALID_TOKEN; then echo "This should have failed but didn't"; exit 1; else "Failed successfully"; fi + run: | + if bun run index.js INVALID_TOKEN; then + echo "This should have failed but didn't" + exit 1 + else + echo "Failed successfully" + fi working-directory: ./example-project From 687290a71b227dfb2ca79540efda4aa79de328db Mon Sep 17 00:00:00 2001 From: Petr Heinz Date: Tue, 19 Sep 2023 16:29:39 +0200 Subject: [PATCH 10/13] Stop running the E2E action on this branch --- .github/workflows/end-to-end.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/end-to-end.yml b/.github/workflows/end-to-end.yml index d7dfb51..07e5c36 100644 --- a/.github/workflows/end-to-end.yml +++ b/.github/workflows/end-to-end.yml @@ -4,7 +4,6 @@ on: push: branches: - master - - ph/test-bun-runtime schedule: - cron: '20 5 * * 1' workflow_dispatch: From 0aecb07f0b54e1813ea452be0280fa69bafbc4c1 Mon Sep 17 00:00:00 2001 From: Petr Heinz Date: Tue, 19 Sep 2023 16:58:22 +0200 Subject: [PATCH 11/13] add runtime name and version to I am using Better Stack! debug log --- example-project/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example-project/index.js b/example-project/index.js index 5902e1a..dbd7585 100644 --- a/example-project/index.js +++ b/example-project/index.js @@ -19,7 +19,7 @@ const logger = new Logtail(process.argv[2], { sendLogsToConsoleOutput: true }); // Usage // Send debug level log using the debug() method -const debugLog = logger.debug("I am using Better Stack!"); +const debugLog = logger.debug(`I am using Better Stack! (${process.title} v${process.versions?.[process.title]})`); // Send info level log using the info() method const infoLog = logger.info("An interesting event occurred!"); From fa16acbe3132bd2caf282f102a766b71107e502c Mon Sep 17 00:00:00 2001 From: Petr Heinz Date: Tue, 19 Sep 2023 17:00:34 +0200 Subject: [PATCH 12/13] Test running E2E tests on this branch --- .github/workflows/end-to-end.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/end-to-end.yml b/.github/workflows/end-to-end.yml index 07e5c36..d7dfb51 100644 --- a/.github/workflows/end-to-end.yml +++ b/.github/workflows/end-to-end.yml @@ -4,6 +4,7 @@ on: push: branches: - master + - ph/test-bun-runtime schedule: - cron: '20 5 * * 1' workflow_dispatch: From ca3cd326050a3f8c8151af3443ee7ad4cd074871 Mon Sep 17 00:00:00 2001 From: Petr Heinz Date: Tue, 19 Sep 2023 17:02:46 +0200 Subject: [PATCH 13/13] Stop running E2E tests on this branch --- .github/workflows/end-to-end.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/end-to-end.yml b/.github/workflows/end-to-end.yml index d7dfb51..07e5c36 100644 --- a/.github/workflows/end-to-end.yml +++ b/.github/workflows/end-to-end.yml @@ -4,7 +4,6 @@ on: push: branches: - master - - ph/test-bun-runtime schedule: - cron: '20 5 * * 1' workflow_dispatch: