Browse Source

refactor: #162 Use package version in CI, update var, and fallbacks

master
vnugent 11 months ago
parent
commit
173d8942ca
No known key found for this signature in database
GPG Key ID: C282EAC569C07C91
  1. 17
      vite.config.ts

17
vite.config.ts

@ -3,14 +3,21 @@ import { defineConfig } from "vite"; @@ -3,14 +3,21 @@ import { defineConfig } from "vite";
import { execSync } from "child_process";
// Function to get the latest git tag
function getLatestGitTag() {
function getAppVersionString() {
// if running in ci context, we can assume the package has been properly versioned
if (process.env.ALEXANDIRA_IS_CI_BUILD) {
console.info("Running in CI context, using package version");
return process.env.npm_package_version;
}
try {
// Get the latest git tag
// Get the latest git tag, assuming git is installed and tagged branch is available
const tag = execSync('git describe --tags --abbrev=0').toString().trim();
return tag;
} catch (error) {
console.error("Failed to get git tag:", error);
return "unknown";
// Fallback to package version
return process.env.npm_package_version;
}
}
@ -20,7 +27,7 @@ export default defineConfig({ @@ -20,7 +27,7 @@ export default defineConfig({
include: ['./tests/unit/**/*.unit-test.js']
},
define: {
// Expose the git tag as a global variable
'import.meta.env.GIT_TAG': JSON.stringify(getLatestGitTag())
// Expose the app version as a global variable
'import.meta.env.APP_VERSION': JSON.stringify(getAppVersionString())
}
});

Loading…
Cancel
Save