Skip to content

Commit 3ccae54

Browse files
committed
Adds comprehensive unit tests and CI workflow
Improves code reliability and maintainability by introducing extensive unit test coverage for core modules and services. Integrates a GitHub Actions workflow to automate test execution and coverage reporting, supporting continuous integration for key branches. Encourages robust development practices and simplifies future feature changes and bug fixes.
1 parent 8ae3ac9 commit 3ccae54

22 files changed

Lines changed: 2999 additions & 165 deletions

.github/workflows/delete_all_images.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
delete-all-images:
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/delete-package-versions@v4
10+
- uses: actions/delete-package-versions@v5
1111
with:
1212
# Name of the package.
1313
# Required

.github/workflows/deploy.yml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- hotfix
8+
- develop
9+
- early-access
10+
11+
concurrency:
12+
group: deploy-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
docker:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: "${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/hotfix' && 0 || 1 }}"
23+
24+
- name: Fetch Current Package Version
25+
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/hotfix' || github.ref == 'refs/heads/develop'
26+
id: package-version
27+
uses: martinbeentjes/npm-get-version-action@v1.3.1
28+
29+
- name: Set up QEMU
30+
uses: docker/setup-qemu-action@v3
31+
32+
- name: Set up Docker Buildx
33+
uses: docker/setup-buildx-action@v3
34+
35+
- name: Login to Docker Hub
36+
uses: docker/login-action@v3
37+
with:
38+
username: phalcode
39+
password: ${{ secrets.DOCKERHUB_TOKEN }}
40+
41+
- name: Login to GitHub Container Registry
42+
uses: docker/login-action@v3
43+
with:
44+
registry: ghcr.io
45+
username: phalcode
46+
password: ${{ secrets.GITHUB_TOKEN }}
47+
48+
- name: Determine Docker tags
49+
id: tags
50+
run: |
51+
BRANCH="${GITHUB_REF#refs/heads/}"
52+
case "$BRANCH" in
53+
master|hotfix)
54+
echo "tags<<EOF" >> $GITHUB_OUTPUT
55+
echo "phalcode/gamevault-backend:latest" >> $GITHUB_OUTPUT
56+
echo "phalcode/gamevault-backend:${{ steps.package-version.outputs.current-version }}" >> $GITHUB_OUTPUT
57+
echo "ghcr.io/phalcode/gamevault-backend:latest" >> $GITHUB_OUTPUT
58+
echo "ghcr.io/phalcode/gamevault-backend:${{ steps.package-version.outputs.current-version }}" >> $GITHUB_OUTPUT
59+
echo "EOF" >> $GITHUB_OUTPUT
60+
;;
61+
develop)
62+
echo "tags<<EOF" >> $GITHUB_OUTPUT
63+
echo "phalcode/gamevault-backend:unstable" >> $GITHUB_OUTPUT
64+
echo "ghcr.io/phalcode/gamevault-backend:unstable" >> $GITHUB_OUTPUT
65+
echo "EOF" >> $GITHUB_OUTPUT
66+
;;
67+
early-access)
68+
echo "tags<<EOF" >> $GITHUB_OUTPUT
69+
echo "phalcode/gamevault-backend:early-access" >> $GITHUB_OUTPUT
70+
echo "ghcr.io/phalcode/gamevault-backend:early-access" >> $GITHUB_OUTPUT
71+
echo "EOF" >> $GITHUB_OUTPUT
72+
;;
73+
esac
74+
75+
- name: Build and Push
76+
uses: docker/build-push-action@v6
77+
with:
78+
platforms: linux/amd64,linux/arm64
79+
push: true
80+
tags: ${{ steps.tags.outputs.tags }}
81+
cache-from: type=gha
82+
cache-to: type=gha,mode=max
83+
84+
- name: Create Github Tag & Release
85+
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/hotfix'
86+
id: release
87+
uses: CupOfTea696/gh-action-auto-release@v1.0.2
88+
env:
89+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
90+
91+
- name: Discord notification
92+
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/hotfix'
93+
uses: Ilshidur/action-discord@master
94+
env:
95+
DISCORD_WEBHOOK: ${{ secrets.DISCORD_RELEASE_BOT_WEBHOOK }}
96+
with:
97+
args: "<@&1128857090090340382> New Release: {{ EVENT_PAYLOAD.repository.full_name }} v${{ steps.package-version.outputs.current-version }} has been deployed. Here are the changes: https://github.com/{{ EVENT_PAYLOAD.repository.full_name }}/releases/tag/${{ steps.package-version.outputs.current-version }}"
98+
99+
sonarcloud:
100+
if: github.ref == 'refs/heads/develop'
101+
runs-on: ubuntu-latest
102+
steps:
103+
- uses: actions/checkout@v4
104+
with:
105+
fetch-depth: 0
106+
- name: SonarCloud Scan
107+
uses: SonarSource/sonarcloud-github-action@master
108+
env:
109+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
110+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.github/workflows/deployment-develop.yml

Lines changed: 0 additions & 57 deletions
This file was deleted.

.github/workflows/deployment-early-access.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

.github/workflows/deployment-master.yml

Lines changed: 0 additions & 64 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [develop, master]
6+
pull_request:
7+
branches: [develop, master]
8+
9+
concurrency:
10+
group: test-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Install pnpm
22+
uses: pnpm/action-setup@v4
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: 22
28+
cache: "pnpm"
29+
30+
- name: Install dependencies
31+
run: pnpm install --frozen-lockfile
32+
33+
- name: Run tests with coverage
34+
run: pnpm test:cov
35+
36+
- name: Upload coverage report
37+
if: always()
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: coverage-report
41+
path: coverage/
42+
retention-days: 14

eslint.config.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,11 @@ export default [
4444
},
4545
},
4646
},
47+
{
48+
files: ["**/*.spec.ts"],
49+
rules: {
50+
"@typescript-eslint/no-explicit-any": "off",
51+
"@typescript-eslint/no-unused-vars": "off",
52+
},
53+
},
4754
];

0 commit comments

Comments
 (0)