Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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=\"$(bun -e \"console.log(require('./package.json').version)\")\""

- name: Setup Pages
uses: actions/configure-pages@v4
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ services:
dockerfile: ./Dockerfile
target: prod
network: host
args:
COMMIT_HASH: ${COMMIT_HASH:-unknown}
ports:
- 4200:80
networks:
Expand Down
31 changes: 31 additions & 0 deletions src/app/components/settings/settings.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
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';
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),
Expand Down Expand Up @@ -101,4 +115,21 @@ describe('SettingsComponent', () => {
expect(tmdbSettingsService.clearCredentials).toHaveBeenCalled();
expect(fixture.componentInstance.tmdbSettingsMessage()).toBe('TMDB credentials cleared.');
});

it('renders About section with version info', () => {
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');
});
});
16 changes: 16 additions & 0 deletions src/app/components/settings/settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -120,6 +121,15 @@ import { TmdbSettingsService } from '../../services/tmdb-settings.service';
</div>
</div>

<div class="bg-light-bg-tertiary dark:bg-dark-bg-tertiary p-6 rounded-lg mb-6">
<h2 class="text-xl mt-0 mb-4 text-light-font-secondary dark:text-dark-font-secondary">
About
</h2>
<p class="text-sm text-light-font-secondary dark:text-dark-font-secondary">
Watch List v{{ environment.appVersion }} ({{ shortHash }})
</p>
</div>

@if (errorMessage()) {
<div class="bg-light-bg-tertiary dark:bg-dark-bg-tertiary p-6 rounded-lg mb-6">
<div
Expand All @@ -146,6 +156,12 @@ export class SettingsComponent {
private importExportService = inject(ImportExportService);
private tmdbSettingsService = inject(TmdbSettingsService);

protected readonly environment = environment;

get shortHash(): string {
return environment.commitHash?.substring(0, 7) ?? 'unknown';
}

errorMessage = signal<string | null>(null);
successMessage = signal<string | null>(null);
tmdbToken = signal(this.tmdbSettingsService.token());
Expand Down
8 changes: 8 additions & 0 deletions src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
interface ImportMetaEnv {
APP_COMMIT_HASH: string;
APP_VERSION: string;
}

interface ImportMeta {
readonly env: ImportMetaEnv;
}
2 changes: 2 additions & 0 deletions src/environments/environment.tauri.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const environment = {
enableServiceWorker: false,
commitHash: import.meta.env.APP_COMMIT_HASH,
appVersion: import.meta.env.APP_VERSION,
};
2 changes: 2 additions & 0 deletions src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const environment = {
enableServiceWorker: false,
commitHash: import.meta.env.APP_COMMIT_HASH,
appVersion: import.meta.env.APP_VERSION,
};
2 changes: 2 additions & 0 deletions src/environments/environment.web.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const environment = {
enableServiceWorker: true,
commitHash: import.meta.env.APP_COMMIT_HASH,
appVersion: import.meta.env.APP_VERSION,
};
Loading