Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/bunTest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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: Bun Test
steps:
- uses: actions/checkout@v4.2.2
- name: use Default
uses: KAnggara/DevOps/test/bun@feature-bunTest
with:
path: action_test/bun

- 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: |
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 }}

- uses: KAnggara/DevOps/test/bun@feature-bunTest
with:
path: action_test/bun
2 changes: 1 addition & 1 deletion .github/workflows/maventest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- feature-mavenTest
paths:
- "test/mvn/**"
- ".github/workflows/maventest.yaml"
- ".github/workflows/mavenTest.yaml"

jobs:
mavenTest:
Expand Down
11 changes: 11 additions & 0 deletions action_test/bun/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
BAGIA=20
BAGIB=4
BAGIC=5

TAMBAHA=4
TAMBAHB=6
TAMBAHC=10

MODA=22
MODB=7
MODC=1
24 changes: 12 additions & 12 deletions action_test/bun/coverage/lcov.info
Original file line number Diff line number Diff line change
@@ -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
22 changes: 14 additions & 8 deletions action_test/bun/src/calc.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
23 changes: 20 additions & 3 deletions action_test/bun/test/calc.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
28 changes: 28 additions & 0 deletions test/bun/action.yaml
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions test/bun/buntest.sh
Original file line number Diff line number Diff line change
@@ -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 "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 "Copy .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!"