Skip to content

Commit b90f367

Browse files
committed
🐛 fix(server): fix semver variables in healthcheck
1 parent 1a73403 commit b90f367

File tree

3 files changed

+71
-72
lines changed

3 files changed

+71
-72
lines changed

.github/workflows/ci-cd.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ jobs:
9393
cd ${{ matrix.package }}
9494
npm run build:version
9595
96-
- name: Get client package version
97-
if: matrix.package == 'client'
98-
id: set_client_version
96+
- name: Get package versions
9997
run: |
10098
echo "client_version=$(jq -r .version client/package.json)" >> $GITHUB_OUTPUT
99+
echo "server_version=$(jq -r .version server/package.json)" >> $GITHUB_OUTPUT
100+
id: set_versions
101101

102102
- name: 🏗️ Build Client
103103
if: matrix.package == 'client'
@@ -106,9 +106,9 @@ jobs:
106106
EXPO_PUBLIC_SUPABASE_URL: ${{ secrets.EXPO_PUBLIC_SUPABASE_URL }}
107107
EXPO_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.EXPO_PUBLIC_SUPABASE_ANON_KEY }}
108108
EXPO_PUBLIC_API_URL: http://56.228.14.41
109-
EXPO_PUBLIC_APP_VERSION: ${{ steps.set_client_version.outputs.client_version }}
109+
EXPO_PUBLIC_APP_VERSION: ${{ steps.set_versions.outputs.client_version }}
110110
EXPO_PUBLIC_BUILD_NUMBER: ${{ github.run_number }}
111-
EXPO_PUBLIC_BUILD_DATE: ${{ github.run_started_at }}
111+
EXPO_PUBLIC_BUILD_DATE: ${{ github.event.head_commit.timestamp }}
112112
EXPO_PUBLIC_COMMIT_HASH: ${{ github.sha }}
113113
EXPO_PUBLIC_BUILD_ENV: production
114114
run: |
@@ -128,8 +128,21 @@ jobs:
128128
129129
- name: 🏗️ Build Server
130130
if: matrix.package == 'server'
131+
env:
132+
NODE_ENV: production
133+
SERVER_VERSION: ${{ steps.set_versions.outputs.server_version }}
134+
BUILD_NUMBER: ${{ github.run_number }}
135+
BUILD_DATE: ${{ github.event.head_commit.timestamp }}
136+
COMMIT_HASH: ${{ github.sha }}
131137
run: |
132138
cd server
139+
echo "\n--- ENVIRONMENT VARIABLES ---"
140+
printenv | sort
141+
echo "\n--- src/common/config/version.ts (before) ---"
142+
cat src/common/config/version.ts
143+
npm run build:version
144+
echo "\n--- src/common/config/version.ts (after build-version) ---"
145+
cat src/common/config/version.ts
133146
npm run build
134147
135148
- name: 📤 Upload Build Artifacts

server/scripts/build-version.js

Lines changed: 48 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -42,85 +42,71 @@ function getBuildInfo() {
4242
}
4343
}
4444

45-
function createVersionEndpoint(buildInfo) {
46-
const versionDir = path.join(__dirname, '..', 'src/api/system');
47-
const versionFilePath = path.join(versionDir, 'version.controller.ts');
45+
function updateVersionConfig(buildInfo) {
46+
const versionConfigPath = path.join(__dirname, '..', 'src/common/config/version.ts');
4847

49-
// Ensure directory exists
50-
if (!fs.existsSync(versionDir)) {
51-
fs.mkdirSync(versionDir, { recursive: true });
52-
}
53-
54-
const content = `import { Request, Response } from 'express';
48+
const content = `/**
49+
* Version configuration for the Express.js server
50+
* These values are injected during build time from environment variables
51+
*/
5552
5653
/**
57-
* Version information for the server
58-
* Updated during build process
54+
* Server version following semantic versioning (SemVer)
55+
* Format: MAJOR.MINOR.PATCH
5956
*/
60-
export const VERSION_INFO = {
61-
name: '${buildInfo.name}',
62-
description: '${buildInfo.description}',
63-
version: '${buildInfo.version}',
64-
buildNumber: '${buildInfo.buildNumber}',
65-
buildDate: '${buildInfo.buildDate}',
66-
commitHash: '${buildInfo.commitHash}',
67-
environment: '${buildInfo.buildEnv}',
68-
timestamp: Date.now(),
69-
uptime: process.uptime(),
70-
nodeVersion: process.version,
71-
platform: process.platform,
72-
arch: process.arch
73-
} as const;
57+
export const SERVER_VERSION = '${buildInfo.version}';
7458
7559
/**
76-
* GET /api/version
77-
* Returns version and build information
60+
* Build number for tracking specific builds
61+
* Typically incremented with each CI/CD build
7862
*/
79-
export const getVersion = (req: Request, res: Response) => {
80-
res.json({
81-
...VERSION_INFO,
82-
uptime: process.uptime(),
83-
timestamp: Date.now()
84-
});
85-
};
63+
export const BUILD_NUMBER = '${buildInfo.buildNumber}';
8664
8765
/**
88-
* GET /api/health
89-
* Health check endpoint with version info
66+
* Build date in ISO format
67+
* Set during the build process
9068
*/
91-
export const getHealth = (req: Request, res: Response) => {
92-
res.json({
93-
status: 'healthy',
94-
version: VERSION_INFO.version,
95-
buildNumber: VERSION_INFO.buildNumber,
96-
uptime: process.uptime(),
97-
timestamp: Date.now(),
98-
environment: VERSION_INFO.environment
99-
});
100-
};
101-
`;
69+
export const BUILD_DATE = '${buildInfo.buildDate}';
10270
103-
fs.writeFileSync(versionFilePath, content);
104-
console.log('✅ Created version controller');
71+
/**
72+
* Git commit hash (short)
73+
* Useful for debugging and tracking specific builds
74+
*/
75+
export const COMMIT_HASH = '${buildInfo.commitHash}';
10576
106-
// Create routes file
107-
const routesFilePath = path.join(versionDir, 'version.routes.ts');
108-
const routesContent = `import { Router } from 'express';
109-
import { getVersion, getHealth } from './version.controller';
77+
/**
78+
* Build environment
79+
* development, staging, production
80+
*/
81+
export const BUILD_ENV = '${buildInfo.buildEnv}';
11082
111-
const router = Router();
83+
/**
84+
* Complete version information object
85+
*/
86+
export const VERSION_INFO = {
87+
version: SERVER_VERSION,
88+
buildNumber: BUILD_NUMBER,
89+
buildDate: BUILD_DATE,
90+
commitHash: COMMIT_HASH,
91+
environment: BUILD_ENV,
92+
timestamp: Date.now(),
93+
} as const;
11294
11395
/**
114-
* Version and health routes
96+
* Human-readable version string
97+
* Format: "v1.1.1 (Build 42)"
11598
*/
116-
router.get('/version', getVersion);
117-
router.get('/health', getHealth);
99+
export const VERSION_STRING = \`v\${SERVER_VERSION} (Build \${BUILD_NUMBER})\`;
118100
119-
export default router;
101+
/**
102+
* Detailed version string with date
103+
* Format: "v1.1.1 (Build 42) - Sep 4, 2025"
104+
*/
105+
export const DETAILED_VERSION_STRING = \`\${VERSION_STRING} - \${new Date(BUILD_DATE).toLocaleDateString()}\`;
120106
`;
121107

122-
fs.writeFileSync(routesFilePath, routesContent);
123-
console.log('✅ Created version routes');
108+
fs.writeFileSync(versionConfigPath, content);
109+
console.log('✅ Updated version configuration');
124110
}
125111

126112
function main() {
@@ -129,7 +115,7 @@ function main() {
129115
const buildInfo = getBuildInfo();
130116
console.log('📦 Build Info:', buildInfo);
131117

132-
createVersionEndpoint(buildInfo);
118+
updateVersionConfig(buildInfo);
133119

134120
console.log('✅ Server version build completed');
135121
}
@@ -138,4 +124,4 @@ if (require.main === module) {
138124
main();
139125
}
140126

141-
module.exports = { getBuildInfo, createVersionEndpoint };
127+
module.exports = { getBuildInfo, updateVersionConfig };

server/src/common/config/version.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,31 @@
77
* Server version following semantic versioning (SemVer)
88
* Format: MAJOR.MINOR.PATCH
99
*/
10-
export const SERVER_VERSION = process.env.SERVER_VERSION || process.env.npm_package_version || '1.1.1';
10+
export const SERVER_VERSION = '1.2.7';
1111

1212
/**
1313
* Build number for tracking specific builds
1414
* Typically incremented with each CI/CD build
1515
*/
16-
export const BUILD_NUMBER = process.env.BUILD_NUMBER || '1';
16+
export const BUILD_NUMBER = '999';
1717

1818
/**
1919
* Build date in ISO format
2020
* Set during the build process
2121
*/
22-
export const BUILD_DATE = process.env.BUILD_DATE || new Date().toISOString();
22+
export const BUILD_DATE = '2025-09-17T09:15:43.978Z';
2323

2424
/**
2525
* Git commit hash (short)
2626
* Useful for debugging and tracking specific builds
2727
*/
28-
export const COMMIT_HASH = process.env.COMMIT_HASH || 'unknown';
28+
export const COMMIT_HASH = '1a73403';
2929

3030
/**
3131
* Build environment
3232
* development, staging, production
3333
*/
34-
export const BUILD_ENV = process.env.NODE_ENV || 'development';
34+
export const BUILD_ENV = 'production';
3535

3636
/**
3737
* Complete version information object

0 commit comments

Comments
 (0)