Skip to content

Commit 57505e7

Browse files
authored
chore: update built frontend (#31)
1 parent 9aedd47 commit 57505e7

6 files changed

Lines changed: 64 additions & 2 deletions

File tree

.github/workflows/frontend-image.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ jobs:
1717
- uses: actions/checkout@v4
1818
- name: Set up Docker Buildx
1919
uses: docker/setup-buildx-action@v3
20+
- name: Bump frontend version
21+
run: |
22+
cd frontend
23+
npm ci
24+
npm version patch --no-git-tag-version
25+
echo "VERSION=$(node -p 'require(\"./package.json\").version')" >> $GITHUB_ENV
26+
cd ..
27+
- name: Commit version bump
28+
run: |
29+
git config user.name "GitHub Actions"
30+
git config user.email "actions@github.com"
31+
git add frontend/package.json
32+
git commit -m "chore: bump frontend version to $VERSION" && git push || echo "No changes to commit"
2033
- name: Log in to GHCR
2134
uses: docker/login-action@v3
2235
with:
@@ -30,5 +43,5 @@ jobs:
3043
push: true
3144
tags: |
3245
ghcr.io/${{ github.repository_owner }}/global-tsunami-risk-map-frontend:latest
33-
ghcr.io/${{ github.repository_owner }}/global-tsunami-risk-map-frontend:${{ github.sha }}
46+
ghcr.io/${{ github.repository_owner }}/global-tsunami-risk-map-frontend:${{ env.VERSION }}
3447

frontend/build.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
const pkg = require("./package.json");
4+
5+
// prepare dist directories
6+
fs.mkdirSync(path.join(__dirname, "dist", "js"), { recursive: true });
7+
8+
// Read and process HTML
9+
const srcHtmlPath = path.join(__dirname, "src", "index.html");
10+
let html = fs.readFileSync(srcHtmlPath, "utf8");
11+
html = html.replace("{{VERSION}}", pkg.version);
12+
const distHtmlPath = path.join(__dirname, "dist", "index.html");
13+
fs.writeFileSync(distHtmlPath, html);
14+
15+
// Copy JS files
16+
const srcJsDir = path.join(__dirname, "src", "js");
17+
const distJsDir = path.join(__dirname, "dist", "js");
18+
fs.readdirSync(srcJsDir).forEach((file) => {
19+
fs.copyFileSync(path.join(srcJsDir, file), path.join(distJsDir, file));
20+
});

frontend/bump_version.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
set -e
3+
npm version patch --no-git-tag-version

frontend/dist/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,18 @@
139139
// addNorwayHazardTiles(map);
140140
});
141141
</script>
142+
<div
143+
id="version"
144+
style="
145+
position: absolute;
146+
bottom: 0;
147+
right: 0;
148+
background: rgba(255, 255, 255, 0.7);
149+
padding: 4px;
150+
font-size: 12px;
151+
"
152+
>
153+
Version: 1.0.0
154+
</div>
142155
</body>
143156
</html>

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"format": "prettier --write \"src/**/*.{js,html,css}\"",
8-
"build": "mkdir -p dist && cp src/index.html dist/index.html && mkdir -p dist/js && cp src/js/*.js dist/js/"
8+
"build": "node build.js"
99
},
1010
"keywords": [],
1111
"author": "",

frontend/src/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,18 @@
139139
// addNorwayHazardTiles(map);
140140
});
141141
</script>
142+
<div
143+
id="version"
144+
style="
145+
position: absolute;
146+
bottom: 0;
147+
right: 0;
148+
background: rgba(255, 255, 255, 0.7);
149+
padding: 4px;
150+
font-size: 12px;
151+
"
152+
>
153+
Version: {{VERSION}}
154+
</div>
142155
</body>
143156
</html>

0 commit comments

Comments
 (0)