Compare commits

...

9 Commits

Author SHA1 Message Date
f6e8983879 Enhance Amogus 2025-08-31 21:05:53 +02:00
d914f47640 Merge branch 'better-deploy'
Some checks failed
CI / build (push) Successful in 15s
CI / lint (push) Successful in 13s
CI / create-and-publish-docker-image (push) Has been cancelled
2025-08-31 21:04:52 +02:00
2c805ab513 dont publish if lint fails
All checks were successful
CI / build (push) Successful in 13s
CI / lint (push) Successful in 9s
CI / create-and-publish-docker-image (push) Successful in 11s
CI / build (pull_request) Successful in 12s
CI / lint (pull_request) Successful in 9s
CI / create-and-publish-docker-image (pull_request) Successful in 12s
2025-08-31 18:22:15 +02:00
2b21310dfb add githooks and setup.sh 2025-08-31 18:22:15 +02:00
756e709181 correct permission on shell script 2025-08-31 18:22:15 +02:00
9872b64fbd create git hash html 2025-08-31 18:22:15 +02:00
b6c9c51ec3 docker image now uses dist folder from build step for deploy 2025-08-31 18:22:15 +02:00
83f872577b ensure git-hash.js is in dist folder 2025-08-31 18:22:15 +02:00
2b489e83ba write git sha env variable into docker container 2025-08-31 18:22:15 +02:00
8 changed files with 103 additions and 76 deletions

View File

@@ -18,8 +18,8 @@ jobs:
run: bun install
- name: Build
run: bun run build
- name: Write git hash into dist
run: echo "export const GIT_HASH = '$(git rev-parse HEAD)';" > dist/git-hash.js
- name: Write Git-Hash into html
run: ./pipeline/create-git-hash-html.sh
- name: Create Build Artifact
uses: christopherhx/gitea-upload-artifact@v4
with:
@@ -42,7 +42,7 @@ jobs:
run: biome ci .
create-and-publish-docker-image:
needs: [build]
needs: [lint]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
@@ -60,7 +60,6 @@ jobs:
run: docker build -t git.rivercry.com/wg/monitor-im-flur .
- name: Push Docker image
run: docker push git.rivercry.com/wg/monitor-im-flur
- name: Deploy via SSH
uses: appleboy/ssh-action@v0.1.10
with:

View File

@@ -1,11 +1,5 @@
FROM oven/bun as builder
WORKDIR /app
COPY . .
RUN bun install
RUN bun run build
FROM nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
COPY ./dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

12
githooks/pre-commit Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/sh
echo "Running pre-commit hooks..."
biome check --write
biome lint --write
if git diff --quiet; then
exit 0
else
git add -u
fi

View File

@@ -16,7 +16,7 @@ http {
index index.html;
location / {
try_files $uri $uri/ /index.html;
try_files $uri $uri/ /index.html /git-hash.js;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {

View File

@@ -1 +0,0 @@
#!/bin/bash

View File

@@ -0,0 +1,11 @@
#!/bin/sh
echo "<!DOCTYPE html>
<html>
<head>
<title>Git Hash</title>
</head>
<body>
<pre>GITHUB_SHA = '$GITHUB_SHA';</pre>
</body>
</html>" > dist/git-hash.html

3
setup.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/sh
git config --local core.hooksPath githooks

View File

@@ -12,81 +12,90 @@ type Amogus = {
speedY: number;
};
const { innerWidth: width, innerHeight: height } = window;
const getImage = (sus: Amogus) => (sus.isImposter ? imposter : amogus);
const initialCrewmates: Amogus[] = [
{ key: "a", isImposter: true, posX: 10, posY: 20, speedX: 10, speedY: 30 },
{
key: "b",
isImposter: false,
posX: 400,
posY: 200,
speedX: 10,
speedY: -20,
},
{
key: "c",
isImposter: false,
posX: 900,
posY: 200,
speedX: -20,
speedY: 10,
},
];
const makeCrewmate = (crewmate: Amogus) => {
const image = getImage(crewmate);
return (
<div
key={crewmate.key}
className={style.container}
style={{ top: crewmate.posY, left: crewmate.posX }}
>
<img src={image} alt="Amogus" />
</div>
);
const makeInitialCrewmates: Amogus[] = () => {
return [
makeCrewmate(true),
makeCrewmate(false),
makeCrewmate(false),
makeCrewmate(false),
makeCrewmate(false),
makeCrewmate(false),
];
};
const stepCrewmates = (list: Amogus[]) => {
const { innerWidth: width, innerHeight: height } = window;
const newCrewmates = list.slice();
for (const c of newCrewmates) {
let newX = c.posX + c.speedX;
let newY = c.posY + c.speedY;
if (newX > width - 90) {
newX = width - 90;
c.speedX *= -1;
}
if (newX < 0) {
newX = 0;
c.speedX *= -1;
}
if (newY > height - 120) {
newY = height - 120;
c.speedY *= -1;
}
if (newY < 0) {
newY = 0;
c.speedY *= -1;
}
c.posX = newX;
c.posY = newY;
}
return newCrewmates;
const randNum: number = (min: number, max: number) =>
Math.random() * (max - min) + min;
const makeCrewmate: Amogus = (imposter: boolean) => ({
isImposter: imposter,
posX: randNum(0, width - 90),
posY: randNum(0, height - 120),
speedX: Math.random() > 0.5 ? randNum(5, 15) : randNum(-5, -15),
speedY: Math.random() > 0.5 ? randNum(5, 15) : randNum(-5, -15),
});
const intersect: Bool = (c1: Crewmate, c2: Crewmate) =>
Math.abs(c1.posX - c2.posX) < 80 && Math.abs(c1.posY - c2.posY) < 90;
const doMove = (crewmates: Amogus[]) =>
crewmates.map((c) => ({
...c,
posX: c.posX + c.speedX,
posY: c.posY + c.speedY,
}));
const doCollision = (crewmates: Amogus[]) =>
crewmates.map((c) => {
if (c.posX > width - 90) {
return { ...c, posX: width - 90, speedX: c.speedX * -1 };
} else if (c.posX < 0) {
return { ...c, posX: 0, speedX: c.speedX * -1 };
} else if (c.posY > height - 120) {
return { ...c, posY: height - 120, speedY: c.speedY * -1 };
} else if (c.posY < 0) {
return { ...c, posY: 0, speedY: c.speedY * -1 };
} else return c;
});
const doKills = (crewmates: Amogus[]) => {
const imposters = crewmates.filter((c) => c.isImposter);
const alive = crewmates
.filter((c) => !c.isImposter)
.filter((c) => imposters.every((i) => !intersect(i, c)));
return imposters.concat(alive);
};
const checkReset = (crewmates: Amogus[]) =>
crewmates.every((c) => c.isImposter) ? makeInitialCrewmates() : crewmates;
const renderCrewmate = (crewmate: Amogus, key: number) => (
<div
key={key}
className={style.container}
style={{ top: crewmate.posY, left: crewmate.posX }}
>
<img src={getImage(crewmate)} alt="Amogus" />
</div>
);
export default function Amogus() {
const [crewmates, setCrewmates] = useState(initialCrewmates);
const [crewmates, setCrewmates] = useState(() => makeInitialCrewmates());
useEffect(() => {
const timer = setInterval(() => {
const c = crewmates;
setCrewmates(stepCrewmates(c));
}, 100);
setCrewmates((c) => doMove(c));
setCrewmates((c) => doCollision(c));
setCrewmates((c) => doKills(c));
setCrewmates((c) => checkReset(c));
}, 50);
return () => {
clearInterval(timer);
};
}, [crewmates]);
}, []);
return <>{crewmates.map((c) => makeCrewmate(c))}</>;
return <>{crewmates.map((c, index) => renderCrewmate(c, index))}</>;
}