From 69b62940ccd70f4657bfc952bc5569cc52e31de4 Mon Sep 17 00:00:00 2001 From: Call Vin Date: Sun, 9 Mar 2025 10:07:31 +0700 Subject: [PATCH 1/8] new bun test --- .github/workflows/bunTest.yaml | 25 ++++++++++++++++++ .github/workflows/maventest.yaml | 2 +- action_test/bun/env.example | 1 + test/bun/action.yaml | 28 ++++++++++++++++++++ test/bun/buntest.sh | 44 ++++++++++++++++++++++++++++++++ 5 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/bunTest.yaml create mode 100644 action_test/bun/env.example create mode 100644 test/bun/action.yaml create mode 100755 test/bun/buntest.sh diff --git a/.github/workflows/bunTest.yaml b/.github/workflows/bunTest.yaml new file mode 100644 index 0000000..8c73336 --- /dev/null +++ b/.github/workflows/bunTest.yaml @@ -0,0 +1,25 @@ +name: Bun Test 🧪 + +on: + push: + branches: + - main + - feature-bunTest + paths: + - "test/bun/**" + - ".github/workflows/bunTest.yaml" + +jobs: + bunTest: + runs-on: ubuntu-24.04 + permissions: + contents: read + packages: write + attestations: write + id-token: write + name: Maven Test + steps: + - uses: actions/checkout@v4.2.2 + - uses: KAnggara/DevOps/test/bun@feature-bunTest + with: + path: action_test/bun diff --git a/.github/workflows/maventest.yaml b/.github/workflows/maventest.yaml index 4a5d0d5..4afb17c 100644 --- a/.github/workflows/maventest.yaml +++ b/.github/workflows/maventest.yaml @@ -7,7 +7,7 @@ on: - feature-mavenTest paths: - "test/mvn/**" - - ".github/workflows/maventest.yaml" + - ".github/workflows/mavenTest.yaml" jobs: mavenTest: diff --git a/action_test/bun/env.example b/action_test/bun/env.example new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/action_test/bun/env.example @@ -0,0 +1 @@ + diff --git a/test/bun/action.yaml b/test/bun/action.yaml new file mode 100644 index 0000000..50a547e --- /dev/null +++ b/test/bun/action.yaml @@ -0,0 +1,28 @@ +name: "Bun Test" +description: "Test Bun Project" + +inputs: + path: + description: "Path of Bun Project, default ./" + required: false + bun_version: + description: "Bun Version, default latest" + required: false + dot_env: + description: "Bun env Variable, default existing in project" + required: false + +runs: + using: "composite" + steps: + - name: Bun Setup + uses: oven-sh/setup-bun@v2 + with: + bun-version: ${{ inputs.bun_version || latest }} + + - name: Generate application properties and test + shell: bash + env: + DOTENV: ${{ inputs.dot_env }} + WORK_DIR: ${{ inputs.path }} + run: $GITHUB_ACTION_PATH/buntest.sh diff --git a/test/bun/buntest.sh b/test/bun/buntest.sh new file mode 100755 index 0000000..95fc6b2 --- /dev/null +++ b/test/bun/buntest.sh @@ -0,0 +1,44 @@ +#!/bin/bash +set -eu + +abort() { + printf "%s\n" "$@" + exit 1 +} + +override_config() { + if [[ -n "$WORK_DIR" ]]; then + cd $WORK_DIR + fi + + if [[ -n "$DOTENV" ]]; then + if [[ -f .env ]]; then + echo "Rewrite .env" + printf "%s" "$DOTENV" >.env + elif [[ -f env.example ]]; then + echo "Rewrite env.example to .env" + cp env.example .env + fi + elif [[ -f .env ]]; then + echo "DOTENV var not exist, keep it as is" + elif [[ -f env.example ]]; then + echo "Rewrite env.example to .env" + cp env.example .env + else + echo "DOTENV var not exist, keep it as is" + fi +} + +bun_test() { + echo "Bun Test" + bun -v + bun install + bun test +} + +main() { + override_config + bun_test +} + +main || abort "Override config Execute Error!" From e7734c39e627ac44855594879eb344d07e7366b5 Mon Sep 17 00:00:00 2001 From: Call Vin Date: Sun, 9 Mar 2025 10:09:00 +0700 Subject: [PATCH 2/8] new bun test --- .github/workflows/bunTest.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bunTest.yaml b/.github/workflows/bunTest.yaml index 8c73336..5642a71 100644 --- a/.github/workflows/bunTest.yaml +++ b/.github/workflows/bunTest.yaml @@ -17,7 +17,7 @@ jobs: packages: write attestations: write id-token: write - name: Maven Test + name: Bun Test steps: - uses: actions/checkout@v4.2.2 - uses: KAnggara/DevOps/test/bun@feature-bunTest From 666d2fc90080bce714fc01da349a31d6c15b336f Mon Sep 17 00:00:00 2001 From: Call Vin Date: Sun, 9 Mar 2025 10:10:23 +0700 Subject: [PATCH 3/8] new bun test --- test/bun/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bun/action.yaml b/test/bun/action.yaml index 50a547e..7cd2f1b 100644 --- a/test/bun/action.yaml +++ b/test/bun/action.yaml @@ -18,7 +18,7 @@ runs: - name: Bun Setup uses: oven-sh/setup-bun@v2 with: - bun-version: ${{ inputs.bun_version || latest }} + bun-version: ${{ inputs.bun_version || 'latest' }} - name: Generate application properties and test shell: bash From 156d1bef08be9b54b30f577c996c377e8c8ba8e6 Mon Sep 17 00:00:00 2001 From: Call Vin Date: Sun, 9 Mar 2025 10:55:26 +0700 Subject: [PATCH 4/8] new bun test --- .github/workflows/bunTest.yaml | 17 +++++++++++++++++ action_test/bun/.env.example | 11 +++++++++++ action_test/bun/coverage/lcov.info | 24 ++++++++++++------------ action_test/bun/env.example | 1 - action_test/bun/src/calc.ts | 22 ++++++++++++++-------- action_test/bun/test/calc.test.ts | 23 ++++++++++++++++++++--- test/bun/buntest.sh | 12 ++++++------ 7 files changed, 80 insertions(+), 30 deletions(-) create mode 100644 action_test/bun/.env.example delete mode 100644 action_test/bun/env.example diff --git a/.github/workflows/bunTest.yaml b/.github/workflows/bunTest.yaml index 5642a71..a2a157c 100644 --- a/.github/workflows/bunTest.yaml +++ b/.github/workflows/bunTest.yaml @@ -23,3 +23,20 @@ jobs: - uses: KAnggara/DevOps/test/bun@feature-bunTest with: path: action_test/bun + + - uses: KAnggara/DevOps/test/bun@feature-bunTest + with: + path: action_test/bun + bun_version: 1.2.0 + + - run: rm .env + - run: rm .env.example + - uses: KAnggara/DevOps/test/bun@feature-bunTest + with: + path: action_test/bun + dot_env: ${{ secrets.BUN_ENV_ACTION_TEST }} + + - run: rm .env + - uses: KAnggara/DevOps/test/bun@feature-bunTest + with: + path: action_test/bun diff --git a/action_test/bun/.env.example b/action_test/bun/.env.example new file mode 100644 index 0000000..07e5ecd --- /dev/null +++ b/action_test/bun/.env.example @@ -0,0 +1,11 @@ +BAGIA=20 +BAGIB=4 +BAGIC=5 + +TAMBAHA=4 +TAMBAHB=6 +TAMBAHC=10 + +MODA=22 +MODB=7 +MODC=1 diff --git a/action_test/bun/coverage/lcov.info b/action_test/bun/coverage/lcov.info index af42d7c..c2742ad 100644 --- a/action_test/bun/coverage/lcov.info +++ b/action_test/bun/coverage/lcov.info @@ -1,18 +1,18 @@ TN: SF:src/calc.ts -FNF:4 -FNH:2 +FNF:6 +FNH:3 DA:1,11 DA:2,9 DA:3,23 -DA:5,0 -DA:6,8 -DA:8,15 -DA:9,16 -DA:10,35 -DA:11,24 -DA:12,1 -DA:13,14 -LF:16 -LH:10 +DA:6,0 +DA:7,8 +DA:10,0 +DA:11,8 +DA:14,9 +DA:15,23 +DA:18,9 +DA:19,16 +LF:22 +LH:9 end_of_record diff --git a/action_test/bun/env.example b/action_test/bun/env.example deleted file mode 100644 index 8b13789..0000000 --- a/action_test/bun/env.example +++ /dev/null @@ -1 +0,0 @@ - diff --git a/action_test/bun/src/calc.ts b/action_test/bun/src/calc.ts index c9e8005..6269c41 100644 --- a/action_test/bun/src/calc.ts +++ b/action_test/bun/src/calc.ts @@ -1,15 +1,21 @@ export class Calc { - static add(a: number, b: number) { + static tambah(a: number, b: number) { return a + b; } - static div(a: number, b: number) { + + static kurang(a: number, b: number) { return a - b; } - static sum(...numbers: number[]) { - let sum = 0; - for (const element of numbers) { - sum += element; - } - return sum; + + static kali(a: number, b: number) { + return a * b; + } + + static bagi(a: number, b: number) { + return a / b; + } + + static mod(a: number, b: number) { + return a % b; } } diff --git a/action_test/bun/test/calc.test.ts b/action_test/bun/test/calc.test.ts index f695bf1..b82f92a 100644 --- a/action_test/bun/test/calc.test.ts +++ b/action_test/bun/test/calc.test.ts @@ -1,11 +1,28 @@ import { Calc } from "../src/calc"; import { describe, expect, it } from "bun:test"; +const bagia = parseInt(process.env.BAGIA, 0); +const bagib = parseInt(process.env.BAGIB, 0); +const bagic = parseInt(process.env.BAGIC, 0); + +const tambaha = parseInt(process.env.TAMBAHA, 0); +const tambahb = parseInt(process.env.TAMBAHB, 0); +const tambahc = parseInt(process.env.TAMBAHC, 0); + +const moda = parseInt(process.env.MODA, 0); +const modb = parseInt(process.env.MODB, 0); +const modc = parseInt(process.env.MODC, 0); + describe("Test add", () => { - it("Test Sum", () => { - expect(Calc.sum(1, 2, 3, 4)).toBe(10); + it("Test Add", () => { + expect(Calc.tambah(tambaha, tambahb)).toBe(tambahc); }); + + it("Test Bagi", () => { + expect(Calc.bagi(bagia, bagib)).toBe(bagic); + }); + it("Test Add", () => { - expect(Calc.add(4, 6)).toBe(10); + expect(Calc.mod(moda, modb)).toBe(modc); }); }); diff --git a/test/bun/buntest.sh b/test/bun/buntest.sh index 95fc6b2..c28d3fd 100755 --- a/test/bun/buntest.sh +++ b/test/bun/buntest.sh @@ -15,15 +15,15 @@ override_config() { if [[ -f .env ]]; then echo "Rewrite .env" printf "%s" "$DOTENV" >.env - elif [[ -f env.example ]]; then - echo "Rewrite env.example to .env" - cp env.example .env + elif [[ -f .env.example ]]; then + echo "Copy .env.example to .env" + cp .env.example .env fi elif [[ -f .env ]]; then echo "DOTENV var not exist, keep it as is" - elif [[ -f env.example ]]; then - echo "Rewrite env.example to .env" - cp env.example .env + elif [[ -f .env.example ]]; then + echo "Copy .env.example to .env" + cp .env.example .env else echo "DOTENV var not exist, keep it as is" fi From 9c98e2a5454bccb13c6adb3d613e88afa05090c6 Mon Sep 17 00:00:00 2001 From: Call Vin Date: Sun, 9 Mar 2025 10:57:38 +0700 Subject: [PATCH 5/8] new bun test --- .github/workflows/bunTest.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/bunTest.yaml b/.github/workflows/bunTest.yaml index a2a157c..d88744a 100644 --- a/.github/workflows/bunTest.yaml +++ b/.github/workflows/bunTest.yaml @@ -36,7 +36,6 @@ jobs: path: action_test/bun dot_env: ${{ secrets.BUN_ENV_ACTION_TEST }} - - run: rm .env - uses: KAnggara/DevOps/test/bun@feature-bunTest with: path: action_test/bun From 0ecc4a6897541ca1e12c2e1920c11688df9de236 Mon Sep 17 00:00:00 2001 From: Call Vin Date: Sun, 9 Mar 2025 10:58:44 +0700 Subject: [PATCH 6/8] new bun test --- .github/workflows/bunTest.yaml | 1 + test/bun/buntest.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/bunTest.yaml b/.github/workflows/bunTest.yaml index d88744a..7421598 100644 --- a/.github/workflows/bunTest.yaml +++ b/.github/workflows/bunTest.yaml @@ -29,6 +29,7 @@ jobs: path: action_test/bun bun_version: 1.2.0 + - run: pwd - run: rm .env - run: rm .env.example - uses: KAnggara/DevOps/test/bun@feature-bunTest diff --git a/test/bun/buntest.sh b/test/bun/buntest.sh index c28d3fd..538603b 100755 --- a/test/bun/buntest.sh +++ b/test/bun/buntest.sh @@ -7,6 +7,7 @@ abort() { } override_config() { + pwd if [[ -n "$WORK_DIR" ]]; then cd $WORK_DIR fi From 9e28e69ee730bebd246091bc5e3bd30ab02a65d7 Mon Sep 17 00:00:00 2001 From: Call Vin Date: Sun, 9 Mar 2025 11:01:23 +0700 Subject: [PATCH 7/8] new bun test --- .github/workflows/bunTest.yaml | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/bunTest.yaml b/.github/workflows/bunTest.yaml index 7421598..7d34272 100644 --- a/.github/workflows/bunTest.yaml +++ b/.github/workflows/bunTest.yaml @@ -20,19 +20,26 @@ jobs: name: Bun Test steps: - uses: actions/checkout@v4.2.2 - - uses: KAnggara/DevOps/test/bun@feature-bunTest + - name: use Default + uses: KAnggara/DevOps/test/bun@feature-bunTest with: path: action_test/bun - - uses: KAnggara/DevOps/test/bun@feature-bunTest + - run: | + cd action_test/bun + rm .env + - name: Default with Version + uses: KAnggara/DevOps/test/bun@feature-bunTest with: path: action_test/bun bun_version: 1.2.0 - - run: pwd - - run: rm .env - - run: rm .env.example - - uses: KAnggara/DevOps/test/bun@feature-bunTest + - run: | + cd action_test/bun + rm .env + rm .env.example + - name: Default with Dot Env + uses: KAnggara/DevOps/test/bun@feature-bunTest with: path: action_test/bun dot_env: ${{ secrets.BUN_ENV_ACTION_TEST }} From ee32054df7d40f5afdeb8ab7153ec67ed4d33d94 Mon Sep 17 00:00:00 2001 From: Call Vin Date: Sun, 9 Mar 2025 11:04:36 +0700 Subject: [PATCH 8/8] feat: bun test https://github.com/KAnggara/DevOps/issues/12 https://github.com/KAnggara/DevOps/issues/10 --- test/bun/buntest.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/test/bun/buntest.sh b/test/bun/buntest.sh index 538603b..c28d3fd 100755 --- a/test/bun/buntest.sh +++ b/test/bun/buntest.sh @@ -7,7 +7,6 @@ abort() { } override_config() { - pwd if [[ -n "$WORK_DIR" ]]; then cd $WORK_DIR fi