diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml new file mode 100644 index 0000000000..033db2b737 --- /dev/null +++ b/.github/workflows/pr-preview.yml @@ -0,0 +1,110 @@ +name: PR Preview (GitHub Pages) + +on: + pull_request: + types: [opened, reopened, synchronize, closed] + branches: + - dev + +concurrency: + group: preview-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: write + pull-requests: write + +jobs: + deploy-preview: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - uses: actions/setup-node@v6 + with: + node-version: "24" + cache: "npm" + cache-dependency-path: | + package-lock.json + docs/package-lock.json + + - name: Install npm 11 + run: npm install -g npm@11 + + - name: Install dependencies + if: github.event.action != 'closed' + run: | + npm ci + cd docs && npm ci --legacy-peer-deps + + - name: Build docs + if: github.event.action != 'closed' + env: + PREVIEW_SITE: https://govalta.github.io + PREVIEW_BASE: /ui-components/pr-preview/pr-${{ github.event.number }}/ + run: npx nx run docs:build + + - name: Build React playground + if: github.event.action != 'closed' + env: + PREVIEW_BASE_REACT: /ui-components/pr-preview-react/pr-${{ github.event.number }}/ + run: npx nx run react-prs:build:production + + - name: Build Angular playground + if: github.event.action != 'closed' + env: + PREVIEW_BASE_ANGULAR: /ui-components/pr-preview-angular/pr-${{ github.event.number }}/ + run: npx nx run angular-prs:build:production --base-href=$PREVIEW_BASE_ANGULAR + + - name: Deploy docs preview + uses: rossjrw/pr-preview-action@v1 + with: + source-dir: ./dist/docs + preview-branch: gh-pages + umbrella-dir: pr-preview + action: auto + + - name: Deploy React playground preview + uses: rossjrw/pr-preview-action@v1 + with: + source-dir: ./dist/apps/prs/react + preview-branch: gh-pages + umbrella-dir: pr-preview-react + action: auto + + - name: Deploy Angular playground preview + uses: rossjrw/pr-preview-action@v1 + with: + source-dir: ./dist/apps/prs/angular/browser + preview-branch: gh-pages + umbrella-dir: pr-preview-angular + action: auto + + - name: Post consolidated preview comment + if: github.event.action != 'closed' + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: pr-preview-all + message: | + ## Preview links + + | Target | URL | + |---|---| + | Docs | https://govalta.github.io/ui-components/pr-preview/pr-${{ github.event.number }}/ | + | React playground | https://govalta.github.io/ui-components/pr-preview-react/pr-${{ github.event.number }}/ | + | Angular playground | https://govalta.github.io/ui-components/pr-preview-angular/pr-${{ github.event.number }}/ | + + Built from commit ${{ github.event.pull_request.head.sha }}. Previews are removed automatically when this PR closes. + + - name: Post cleanup notice + if: github.event.action == 'closed' + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: pr-preview-all + message: | + ## Preview removed + + All preview folders cleaned from gh-pages branch. diff --git a/apps/prs/angular/src/app/app.component.html b/apps/prs/angular/src/app/app.component.html index 3ddf65fc39..780a3016ff 100644 --- a/apps/prs/angular/src/app/app.component.html +++ b/apps/prs/angular/src/app/app.component.html @@ -2,7 +2,7 @@
- +
@for (route of bugRouteDefinitions; track route.path) { } @@ -36,7 +36,7 @@ @for (route of docsRouteDefinitions; track route.path) { } @@ -44,7 +44,7 @@ @for (route of featureRouteDefinitions; track route.path) { } diff --git a/apps/prs/angular/src/app/app.component.ts b/apps/prs/angular/src/app/app.component.ts index 410381a6da..487604db6e 100644 --- a/apps/prs/angular/src/app/app.component.ts +++ b/apps/prs/angular/src/app/app.component.ts @@ -1,4 +1,5 @@ import { Component, CUSTOM_ELEMENTS_SCHEMA, inject } from "@angular/core"; +import { LocationStrategy } from "@angular/common"; import { Router, NavigationEnd, RouterOutlet } from "@angular/router"; import { filter } from "rxjs/operators"; import { @@ -37,6 +38,7 @@ export class AppComponent { readonly bugRouteDefinitions = bugRouteDefinitions; readonly featureRouteDefinitions = featureRouteDefinitions; readonly docsRouteDefinitions = docsRouteDefinitions; + readonly baseHref = inject(LocationStrategy).getBaseHref(); private fullPageRoutes = ["/features/2885"]; private router = inject(Router); @@ -52,6 +54,9 @@ export class AppComponent { } handleNavigate(path: string): void { - this.router.navigateByUrl(path); + const internal = path.startsWith(this.baseHref) + ? "/" + path.slice(this.baseHref.length) + : path; + this.router.navigateByUrl(internal); } } diff --git a/apps/prs/angular/src/index.html b/apps/prs/angular/src/index.html index 333da64741..ac2171d421 100644 --- a/apps/prs/angular/src/index.html +++ b/apps/prs/angular/src/index.html @@ -6,6 +6,19 @@ Angular Playground + + diff --git a/apps/prs/angular/src/routes/bugs/3273/bug3273-2.component.html b/apps/prs/angular/src/routes/bugs/3273/bug3273-2.component.html index 97ee8a9528..050d133865 100644 --- a/apps/prs/angular/src/routes/bugs/3273/bug3273-2.component.html +++ b/apps/prs/angular/src/routes/bugs/3273/bug3273-2.component.html @@ -14,10 +14,10 @@

Scenario two

- Parent Item + Parent Item - Child Item + Child Item diff --git a/apps/prs/angular/src/routes/bugs/3273/bug3273-2.component.ts b/apps/prs/angular/src/routes/bugs/3273/bug3273-2.component.ts index c224d01903..faac6c5cf8 100644 --- a/apps/prs/angular/src/routes/bugs/3273/bug3273-2.component.ts +++ b/apps/prs/angular/src/routes/bugs/3273/bug3273-2.component.ts @@ -1,11 +1,12 @@ import { Component } from "@angular/core"; import { CommonModule } from "@angular/common"; +import { RouterLink } from "@angular/router"; import { GoabSideMenu, GoabSideMenuGroup } from "@abgov/angular-components"; @Component({ standalone: true, selector: "abgov-bug3273-2", templateUrl: "./bug3273-2.component.html", - imports: [CommonModule, GoabSideMenu, GoabSideMenuGroup], + imports: [CommonModule, RouterLink, GoabSideMenu, GoabSideMenuGroup], }) export class Bug32732Component {} diff --git a/apps/prs/angular/src/routes/bugs/3273/bug3273.component.html b/apps/prs/angular/src/routes/bugs/3273/bug3273.component.html index ec8d15d996..0ec0a13a38 100644 --- a/apps/prs/angular/src/routes/bugs/3273/bug3273.component.html +++ b/apps/prs/angular/src/routes/bugs/3273/bug3273.component.html @@ -16,10 +16,10 @@

Scenario one

- Parent Item + Parent Item - Child Item + Child Item diff --git a/apps/prs/angular/src/routes/bugs/3273/bug3273.component.ts b/apps/prs/angular/src/routes/bugs/3273/bug3273.component.ts index 0b587f9dd3..42399eab24 100644 --- a/apps/prs/angular/src/routes/bugs/3273/bug3273.component.ts +++ b/apps/prs/angular/src/routes/bugs/3273/bug3273.component.ts @@ -1,11 +1,12 @@ import { Component } from "@angular/core"; import { CommonModule } from "@angular/common"; +import { RouterLink } from "@angular/router"; import { GoabSideMenu, GoabSideMenuGroup } from "@abgov/angular-components"; @Component({ standalone: true, selector: "abgov-bug3273", templateUrl: "./bug3273.component.html", - imports: [CommonModule, GoabSideMenu, GoabSideMenuGroup], + imports: [CommonModule, RouterLink, GoabSideMenu, GoabSideMenuGroup], }) export class Bug3273Component {} diff --git a/apps/prs/react/index.html b/apps/prs/react/index.html index d2a4aba1f8..71ff4f0bed 100644 --- a/apps/prs/react/index.html +++ b/apps/prs/react/index.html @@ -4,10 +4,23 @@ React Playground - + - + + +