Skip to content

Commit

Permalink
Merge 79b69e5 into ea79e31
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminCharmes authored Oct 14, 2024
2 parents ea79e31 + 79b69e5 commit f3dfdbb
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
6 changes: 3 additions & 3 deletions webapp/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "datalab-vue",
"version": "0.4.5",
"version": "0.0.0-git",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"serve": "VUE_APP_GIT_VERSION=$(node scripts/get-version.js) vue-cli-service serve",
"build": "VUE_APP_GIT_VERSION=$(node scripts/get-version.js) vue-cli-service build",
"test:unit": "vue-cli-service test:unit",
"test:e2e": "vue-cli-service test:e2e --mode test_e2e",
"lint": "vue-cli-service lint"
Expand Down
52 changes: 52 additions & 0 deletions webapp/scripts/get-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env node
// This script tries to get the version of the app from three sources:
//
// 1. The VUE_APP_GIT_VERSION environment variable
// 2. The latest git tag
// 3. The version field in package.JSON
//
// It can be used as part of the build system to set the
// `VUE_APP_GIT_VERSION` environment variable itself.

const { execSync } = require("child_process");
const fs = require("fs");

function getPackageJsonVersion() {
try {
const packageJson = JSON.parse(fs.readFileSync("package.json", "utf8"));
return packageJson.version || "unknown";
} catch (error) {
console.error("Error reading package.json:", error);
return "unknown";
}
}

function getGitVersion() {
try {
const tag = execSync("git describe --tags").toString().trim();
return tag;
} catch (error) {
console.error("Error getting git version:", error);
return null;
}
}

function getVersion() {
// Check if VUE_APP_GIT_VERSION is already set (e.g., by build system)
if (process.env.VUE_APP_GIT_VERSION) {
return process.env.VUE_APP_GIT_VERSION;
}

// Try to get git version
const gitVersion = getGitVersion();
if (gitVersion) {
return gitVersion;
}

// Fall back to package.json version
return getPackageJsonVersion();
}

// Get and log the version
const version = getVersion();
console.log(version);
1 change: 1 addition & 0 deletions webapp/src/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const FEDERATION_QR_CODE_RESOLVER_URL = "https://purl.datalab-org.io";

export const LOGO_URL = process.env.VUE_APP_LOGO_URL;
export const HOMEPAGE_URL = process.env.VUE_APP_HOMEPAGE_URL;
export const APP_VERSION = process.env.VUE_APP_GIT_VERSION;

export const GRAVATAR_STYLE = "identicon";

Expand Down
6 changes: 5 additions & 1 deletion webapp/src/views/About.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
</tr>
<tr>
<td>App version</td>
<td><code>0.4.0</code></td>
<td>
<code>{{ appVersion }}</code>
</td>
</tr>
</table>
</div>
Expand Down Expand Up @@ -75,12 +77,14 @@
import Navbar from "@/components/Navbar";
import { getInfo } from "@/server_fetch_utils.js";
import StatisticsTable from "@/components/StatisticsTable";
import { APP_VERSION } from "@/resources.js";
export default {
components: { Navbar, StatisticsTable },
data() {
return {
apiInfo: { server_version: "unknown" },
appVersion: APP_VERSION,
};
},
async mounted() {
Expand Down

0 comments on commit f3dfdbb

Please sign in to comment.