Skip to content

Commit 680071b

Browse files
OLILHRhf-krechan
andauthored
feat: add version endpoint (#48)
* add version endpoint infos for stage release * add dummy version json * add version endpoint infos for prod * Add version endpoint to fetch version information from `version.json` * Add version tag to the footer * fix branch name When running in GitHub Actions, git rev-parse --abbrev-ref HEAD will return "HEAD" because the checkout action performs a "detached HEAD" checkout by default. To get the actual branch name in GitHub Actions, you can use the built-in GitHub context variable. * use commit id from github env * set fetch_depth to 0 * another try to get the right commit id * use github env vars for commit id and branch name * Exclude `/version/` endpoint from authentication * make version endpoint public * Link footer version tag to version endpoint --------- Co-authored-by: kevin <[email protected]>
1 parent fa4d627 commit 680071b

File tree

6 files changed

+119
-15
lines changed

6 files changed

+119
-15
lines changed

.github/workflows/azure-static-web-apps-brave-ocean-076b69903.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ jobs:
1919
with:
2020
submodules: false
2121
lfs: false
22+
fetch-depth: 0
23+
- name: Set build and release information
24+
id: build_release_info
25+
run: |
26+
BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
27+
COMMIT_ID=${{ github.event.pull_request.head.sha || github.sha }}
28+
BUILD_BRANCH=${{ github.head_ref || github.ref_name }}
29+
sed -i "s|\"build_date\": \"0001-01-01T00:00:00Z\"|\"build_date\": \"$BUILD_DATE\"|" static/version.json
30+
sed -i "s|\"commit_id\": \"dummy-commit-id\"|\"commit_id\": \"$COMMIT_ID\"|" static/version.json
31+
sed -i "s|\"build_branch\": \"dummy-branch\"|\"build_branch\": \"$BUILD_BRANCH\"|" static/version.json
2232
- name: Build And Deploy
2333
id: builddeploy
2434
uses: Azure/static-web-apps-deploy@v1

.github/workflows/azure-static-web-apps-icy-stone-001be1b03.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ jobs:
1414
with:
1515
submodules: false
1616
lfs: false
17+
- name: Set build and release information
18+
id: build_release_info
19+
run: |
20+
BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
21+
COMMIT_ID=${{ github.sha }}
22+
BUILD_BRANCH=${{ github.ref_name }}
23+
VERSION_TAG=${GITHUB_REF#refs/tags/}
24+
sed -i "s|\"build_date\": \"0001-01-01T00:00:00Z\"|\"build_date\": \"$BUILD_DATE\"|" static/version.json
25+
sed -i "s|\"commit_id\": \"dummy-commit-id\"|\"commit_id\": \"$COMMIT_ID\"|" static/version.json
26+
sed -i "s|\"build_branch\": \"dummy-branch\"|\"build_branch\": \"$BUILD_BRANCH\"|" static/version.json
27+
sed -i "s|\"version_tag\": \"v0.0.0\"|\"version_tag\": \"$VERSION_TAG\"|" static/version.json
1728
- name: Build And Deploy
1829
id: builddeploy
1930
uses: Azure/static-web-apps-deploy@v1
Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1-
<script>
1+
<script lang="ts">
2+
import { onMount } from "svelte";
3+
4+
import { base } from "$app/paths";
25
import { IconHeart, IconLogo } from "$lib/components";
36
47
export let background = "bg-tint";
58
9+
type VersionInfo = {
10+
version_tag: string;
11+
};
12+
613
let currentYear = new Date().getFullYear();
14+
let versionTag: string | null = null;
15+
16+
onMount(async () => {
17+
const response = await fetch(`${base}/version.json`);
18+
const data: VersionInfo = await response.json();
19+
versionTag = data.version_tag;
20+
});
721
</script>
822

923
<footer class="flex items-center {background} px-3 py-2">
@@ -16,45 +30,54 @@
1630
<div class="flex-1 flex justify-center">
1731
<div class="flex items-center text-sm text-black/70 space-x-1 text-center">
1832
<p class="flex items-center flex-wrap justify-center">
19-
© {currentYear} - made with
33+
© {currentYear}
34+
{#if versionTag}
35+
-
36+
<a
37+
href="{base}/version/"
38+
class="hover:underline font-bold mx-1"
39+
title="Version details"
40+
>{versionTag}
41+
</a>
42+
{/if}
43+
- made with
2044
<IconHeart />
2145
by
2246
<a
23-
class="ml-1 mr-2"
47+
class="ml-1 mr-2 hover:underline font-bold"
2448
target="_blank"
2549
rel="noopener noreferrer"
2650
href="https://hochfrequenz.de">Hochfrequenz</a
2751
>
2852
|
2953
<a
30-
class="font-bold underline ml-2"
54+
class="font-bold ml-2 text-secondary"
3155
target="_blank"
32-
rel="noopener
33-
noreferrer"
56+
rel="noopener noreferrer"
3457
href="https://www.hochfrequenz.de/#fristenkalender"
3558
>
3659
hier klicken</a
3760
>
38-
<span class="mr-2"
39-
>, um unseren aktuellsten Fristenkalender als PDF anzufordern</span
61+
<span class="ml-1 mr-2">
62+
um unseren aktuellsten Fristenkalender als PDF anzufordern</span
4063
>
4164
|
4265
<a
43-
class="mx-2"
66+
class="mx-2 hover:underline"
4467
target="_blank"
4568
rel="noopener noreferrer"
4669
href="https://www.hochfrequenz.de/datenschutz/">Datenschutz</a
4770
>
4871
|
4972
<a
50-
class="mx-2"
73+
class="mx-2 hover:underline"
5174
target="_blank"
5275
rel="noopener noreferrer"
5376
href="https://www.hochfrequenz.de/impressum/">Impressum</a
5477
>
5578
|
5679
<a
57-
class="mx-2"
80+
class="mx-2 hover:underline"
5881
target="_blank"
5982
rel="noopener noreferrer"
6083
href="https://www.hochfrequenz.de/kontakt/">Kontakt</a
@@ -63,5 +86,6 @@
6386
</div>
6487
</div>
6588

66-
<div class="flex-none w-[150px]"></div>
89+
<!-- to compensate the padding caused by the logo on the left -->
90+
<div class="flex-none w-[160px]"></div>
6791
</footer>

src/routes/+layout.svelte

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
1313
let isLoading = true;
1414
15+
const exposedEndpoints = [`${base}/`, `${base}/version/`];
16+
1517
onMount(async () => {
1618
await auth.createClient();
1719
@@ -27,14 +29,18 @@
2729
isLoading = false;
2830
2931
isAuthenticated.subscribe((value: boolean) => {
30-
if (!value && !isLoading && $page.url.pathname !== `${base}/`) {
32+
const isExposedEndpoint = exposedEndpoints.includes($page.url.pathname);
33+
if (!value && !isLoading && !isExposedEndpoint) {
3134
goto(`${base}/`);
3235
}
3336
});
3437
});
3538
36-
$: if (!$isAuthenticated && !isLoading && $page.url.pathname !== `${base}/`) {
37-
goto(`${base}/`);
39+
$: {
40+
const isExposedEndpoint = exposedEndpoints.includes($page.url.pathname);
41+
if (!$isAuthenticated && !isLoading && !isExposedEndpoint) {
42+
goto(`${base}/`);
43+
}
3844
}
3945
</script>
4046

src/routes/version/+page.svelte

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<script lang="ts">
2+
import { onMount } from "svelte";
3+
4+
import { base } from "$app/paths";
5+
6+
type VersionInfo = {
7+
build_date: string;
8+
commit_id: string;
9+
version_tag: string;
10+
build_branch: string;
11+
};
12+
13+
let versionData: VersionInfo | null = null;
14+
15+
onMount(async () => {
16+
const response = await fetch(`${base}/version.json`); // local development: static/version.json & stage/prod: build/version.json
17+
versionData = await response.json();
18+
});
19+
</script>
20+
21+
<div class="p-6">
22+
{#if versionData}
23+
<div class="flex flex-col">
24+
<div class="flex gap-4">
25+
<div class="text-black/70 font-medium">build date:</div>
26+
<div class="text-black/70">
27+
{new Date(versionData.build_date).toLocaleString()}
28+
</div>
29+
</div>
30+
31+
<div class="flex gap-4">
32+
<div class="text-black/70 font-medium">version:</div>
33+
<div class="text-black/70">{versionData.version_tag}</div>
34+
</div>
35+
36+
<div class="flex gap-4">
37+
<div class="text-black/70 font-medium">commit ID:</div>
38+
<div class="text-black/70">{versionData.commit_id}</div>
39+
</div>
40+
41+
<div class="flex gap-4">
42+
<div class="text-black/70 font-medium">build branch:</div>
43+
<div class="text-black/70">{versionData.build_branch}</div>
44+
</div>
45+
</div>
46+
{/if}
47+
</div>

static/version.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"build_date": "0001-01-01T00:00:00Z",
3+
"commit_id": "dummy-commit-id",
4+
"version_tag": "v0.0.0",
5+
"build_branch": "dummy-branch"
6+
}

0 commit comments

Comments
 (0)