From 308db346c95a257aea9cc10f4037e7a5df7d8e88 Mon Sep 17 00:00:00 2001 From: Ma <101021254+CodeWithMa@users.noreply.github.com> Date: Sat, 18 Jul 2026 16:28:11 +0200 Subject: [PATCH 1/2] feat: show commit hash and app version on Settings page Inject APP_COMMIT_HASH and APP_VERSION at build time via Angular's define option, then display them in a new About section on the Settings page. - Add define defaults in angular.json (dev: "dev"/"0.0.0") - Add ImportMeta type declarations in src/env.d.ts - Add commitHash/appVersion to all environment files - Add About card showing version and short commit hash in Settings - Update CI workflow to pass --define flags with github.sha - Update Dockerfile with COMMIT_HASH build arg - Update docker-compose.prod.yml to pass build arg --- .github/workflows/deploy-pages.yml | 2 +- Dockerfile | 3 ++- angular.json | 6 ++++- docker-compose.prod.yml | 2 ++ .../settings/settings.component.spec.ts | 23 +++++++++++++++++++ .../components/settings/settings.component.ts | 16 +++++++++++++ src/env.d.ts | 8 +++++++ src/environments/environment.tauri.ts | 2 ++ src/environments/environment.ts | 2 ++ src/environments/environment.web.ts | 2 ++ 10 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 src/env.d.ts diff --git a/.github/workflows/deploy-pages.yml b/.github/workflows/deploy-pages.yml index 8587b9b..48f1b19 100644 --- a/.github/workflows/deploy-pages.yml +++ b/.github/workflows/deploy-pages.yml @@ -28,7 +28,7 @@ jobs: run: bun install --frozen-lockfile - name: Build application - run: bun run build -- --base-href /watch-list/ + run: bun run build -- --base-href /watch-list/ --define "import.meta.env.APP_COMMIT_HASH=\"${{ github.sha }}\"" --define "import.meta.env.APP_VERSION=\"$(node -e \"console.log(require('./package.json').version)\")\"" - name: Setup Pages uses: actions/configure-pages@v4 diff --git a/Dockerfile b/Dockerfile index 8877a86..bc58c40 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,8 @@ COPY tsconfig.json . COPY tsconfig.app.json . COPY tsconfig.spec.json . -RUN bun run build +ARG COMMIT_HASH=unknown +RUN bun run build -- --define "import.meta.env.APP_COMMIT_HASH=\"$COMMIT_HASH\"" --define "import.meta.env.APP_VERSION=\"$(grep '"version"' package.json | sed 's/.*"\(.*\)".*/\1/')\"" FROM nginx:alpine-slim AS prod diff --git a/angular.json b/angular.json index 53a4c57..ce936f5 100644 --- a/angular.json +++ b/angular.json @@ -30,7 +30,11 @@ ], "styles": [ "src/styles.css" - ] + ], + "define": { + "import.meta.env.APP_COMMIT_HASH": "\"dev\"", + "import.meta.env.APP_VERSION": "\"0.0.0\"" + } }, "configurations": { "production": { diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 7235e59..ea9de8d 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -12,6 +12,8 @@ services: dockerfile: ./Dockerfile target: prod network: host + args: + COMMIT_HASH: ${COMMIT_HASH:-unknown} ports: - 4200:80 networks: diff --git a/src/app/components/settings/settings.component.spec.ts b/src/app/components/settings/settings.component.spec.ts index c6a4fcf..ecbb0d0 100644 --- a/src/app/components/settings/settings.component.spec.ts +++ b/src/app/components/settings/settings.component.spec.ts @@ -1,4 +1,5 @@ import { TestBed } from '@angular/core/testing'; +import { environment } from '../../../environments/environment'; import { ImportExportService } from '../../services/import-export.service'; import { TmdbCredential, TmdbSettingsService } from '../../services/tmdb-settings.service'; import { SettingsComponent } from './settings.component'; @@ -101,4 +102,26 @@ describe('SettingsComponent', () => { expect(tmdbSettingsService.clearCredentials).toHaveBeenCalled(); expect(fixture.componentInstance.tmdbSettingsMessage()).toBe('TMDB credentials cleared.'); }); + + it('renders About section with version info', () => { + const origHash = environment.commitHash; + const origVersion = environment.appVersion; + environment.commitHash = 'abc123456789'; + environment.appVersion = '1.2.3'; + + configure({ + token: '', + key: '', + credential: null, + }); + const fixture = TestBed.createComponent(SettingsComponent); + + fixture.detectChanges(); + + expect(fixture.nativeElement.textContent).toContain('Watch List v1.2.3'); + expect(fixture.nativeElement.textContent).toContain('abc1234'); + + environment.commitHash = origHash; + environment.appVersion = origVersion; + }); }); diff --git a/src/app/components/settings/settings.component.ts b/src/app/components/settings/settings.component.ts index 37ee714..4d3d861 100644 --- a/src/app/components/settings/settings.component.ts +++ b/src/app/components/settings/settings.component.ts @@ -3,6 +3,7 @@ import { FormsModule } from '@angular/forms'; import { ImportExportService } from '../../services/import-export.service'; import { TmdbSettingsService } from '../../services/tmdb-settings.service'; +import { environment } from '../../../environments/environment'; @Component({ selector: 'app-settings', @@ -120,6 +121,15 @@ import { TmdbSettingsService } from '../../services/tmdb-settings.service'; +
+

+ About +

+

+ Watch List v{{ environment.appVersion }} ({{ shortHash }}) +

+
+ @if (errorMessage()) {
(null); successMessage = signal(null); tmdbToken = signal(this.tmdbSettingsService.token()); diff --git a/src/env.d.ts b/src/env.d.ts new file mode 100644 index 0000000..a14fb6e --- /dev/null +++ b/src/env.d.ts @@ -0,0 +1,8 @@ +interface ImportMetaEnv { + APP_COMMIT_HASH: string; + APP_VERSION: string; +} + +interface ImportMeta { + readonly env: ImportMetaEnv; +} diff --git a/src/environments/environment.tauri.ts b/src/environments/environment.tauri.ts index 5bc3f30..3fdd247 100644 --- a/src/environments/environment.tauri.ts +++ b/src/environments/environment.tauri.ts @@ -1,3 +1,5 @@ export const environment = { enableServiceWorker: false, + commitHash: import.meta.env.APP_COMMIT_HASH, + appVersion: import.meta.env.APP_VERSION, }; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 5bc3f30..3fdd247 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -1,3 +1,5 @@ export const environment = { enableServiceWorker: false, + commitHash: import.meta.env.APP_COMMIT_HASH, + appVersion: import.meta.env.APP_VERSION, }; diff --git a/src/environments/environment.web.ts b/src/environments/environment.web.ts index a901a13..9d5e612 100644 --- a/src/environments/environment.web.ts +++ b/src/environments/environment.web.ts @@ -1,3 +1,5 @@ export const environment = { enableServiceWorker: true, + commitHash: import.meta.env.APP_COMMIT_HASH, + appVersion: import.meta.env.APP_VERSION, }; From f7eb501adca089206d0221a66bab94bb029d9e8a Mon Sep 17 00:00:00 2001 From: Ma <101021254+CodeWithMa@users.noreply.github.com> Date: Sat, 18 Jul 2026 17:03:43 +0200 Subject: [PATCH 2/2] fix: use bun instead of node in workflow and fix test cleanup - Replace node -e with bun -e in deploy-pages.yml for consistency - Add beforeEach/afterEach to safely save/restore environment in test - Remove inline cleanup that would be skipped on test failure --- .github/workflows/deploy-pages.yml | 2 +- .../settings/settings.component.spec.ts | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy-pages.yml b/.github/workflows/deploy-pages.yml index 48f1b19..ea4d943 100644 --- a/.github/workflows/deploy-pages.yml +++ b/.github/workflows/deploy-pages.yml @@ -28,7 +28,7 @@ jobs: run: bun install --frozen-lockfile - name: Build application - run: bun run build -- --base-href /watch-list/ --define "import.meta.env.APP_COMMIT_HASH=\"${{ github.sha }}\"" --define "import.meta.env.APP_VERSION=\"$(node -e \"console.log(require('./package.json').version)\")\"" + run: bun run build -- --base-href /watch-list/ --define "import.meta.env.APP_COMMIT_HASH=\"${{ github.sha }}\"" --define "import.meta.env.APP_VERSION=\"$(bun -e \"console.log(require('./package.json').version)\")\"" - name: Setup Pages uses: actions/configure-pages@v4 diff --git a/src/app/components/settings/settings.component.spec.ts b/src/app/components/settings/settings.component.spec.ts index ecbb0d0..2f80029 100644 --- a/src/app/components/settings/settings.component.spec.ts +++ b/src/app/components/settings/settings.component.spec.ts @@ -6,6 +6,19 @@ import { SettingsComponent } from './settings.component'; import { vi } from 'vitest'; describe('SettingsComponent', () => { + let origHash: string; + let origVersion: string; + + beforeEach(() => { + origHash = environment.commitHash; + origVersion = environment.appVersion; + }); + + afterEach(() => { + environment.commitHash = origHash; + environment.appVersion = origVersion; + }); + function configure(credentials: { token: string; key: string; credential: TmdbCredential }) { const tmdbSettingsService = { token: vi.fn(() => credentials.token), @@ -104,8 +117,6 @@ describe('SettingsComponent', () => { }); it('renders About section with version info', () => { - const origHash = environment.commitHash; - const origVersion = environment.appVersion; environment.commitHash = 'abc123456789'; environment.appVersion = '1.2.3'; @@ -120,8 +131,5 @@ describe('SettingsComponent', () => { expect(fixture.nativeElement.textContent).toContain('Watch List v1.2.3'); expect(fixture.nativeElement.textContent).toContain('abc1234'); - - environment.commitHash = origHash; - environment.appVersion = origVersion; }); });