-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
general: Inject also date and link to release in the About page
- Loading branch information
1 parent
3249ea8
commit e03191c
Showing
4 changed files
with
70 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,47 @@ | ||
import { execSync } from 'child_process' | ||
|
||
import type { AppVersionInfo } from './cosmos' | ||
|
||
/** | ||
* Returns the version of the application. | ||
* Uses the git describe command to get the latest tag, or the commit hash if no tags exist. | ||
* Returns a fallback version 'unknown' if git commands fails. | ||
* @returns {string} | ||
* Returns the version information of the application. | ||
* Uses git commands to get the version (tag or commit), date, and link to GitHub. | ||
* Returns fallback values if git commands fail. | ||
* @returns {AppVersionInfo} | ||
*/ | ||
export function getVersion(): string { | ||
export function getVersion(): AppVersionInfo { | ||
const repoUrl = 'https://github.com/bluerobotics/cockpit' | ||
const fallback: AppVersionInfo = { | ||
version: 'unknown', | ||
date: 'unknown', | ||
link: repoUrl, | ||
} | ||
|
||
try { | ||
// Try to get the latest tag | ||
const tag = execSync('git describe --tags --abbrev=0', { encoding: 'utf8' }).trim() | ||
if (tag.startsWith('v')) { | ||
return tag.substring(1) | ||
if (tag) { | ||
// Get the tag date | ||
const date = execSync(`git log -1 --format=%ai ${tag}`, { encoding: 'utf8' }).trim() | ||
return { | ||
version: tag.startsWith('v') ? tag.substring(1) : tag, | ||
date: date.split(' ')[0], // Get just the date part | ||
link: `${repoUrl}/releases/tag/${tag}`, | ||
} | ||
} | ||
return tag | ||
} catch { | ||
try { | ||
// If no tags exist, get the commit hash | ||
const commitHash = execSync('git rev-parse HEAD', { encoding: 'utf8' }).trim() | ||
return commitHash.substring(0, 8) | ||
const date = execSync('git show -s --format=%ai HEAD', { encoding: 'utf8' }).trim() | ||
return { | ||
version: commitHash.substring(0, 8), | ||
date: date.split(' ')[0], // Get just the date part | ||
link: `${repoUrl}/commit/${commitHash}`, | ||
} | ||
} catch { | ||
// If git commands fail, return a fallback version | ||
return 'unknown' | ||
// If git commands fail, return fallback values | ||
return fallback | ||
} | ||
} | ||
return fallback | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters