From 4feb130f46afcfa7b7bb215031c00f412c2a14c2 Mon Sep 17 00:00:00 2001 From: Valery Melou Date: Sat, 13 Jul 2024 08:04:07 +0100 Subject: [PATCH 1/4] chore: setup continuous deployment on firebase hosting --- .github/workflows/firebase-hosting-merge.yml | 20 ++++++++++++++++++ .../firebase-hosting-pull-request.yml | 21 +++++++++++++++++++ .gitignore | 1 + firebase.json | 16 ++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 .github/workflows/firebase-hosting-merge.yml create mode 100644 .github/workflows/firebase-hosting-pull-request.yml create mode 100644 firebase.json diff --git a/.github/workflows/firebase-hosting-merge.yml b/.github/workflows/firebase-hosting-merge.yml new file mode 100644 index 0000000..6fc7d11 --- /dev/null +++ b/.github/workflows/firebase-hosting-merge.yml @@ -0,0 +1,20 @@ +# This file was auto-generated by the Firebase CLI +# https://github.com/firebase/firebase-tools + +name: Deploy to Firebase Hosting on merge +on: + push: + branches: + - master +jobs: + build_and_deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: yarn nx run website:build + - uses: FirebaseExtended/action-hosting-deploy@v0 + with: + repoToken: ${{ secrets.GITHUB_TOKEN }} + firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }} + channelId: live + projectId: ${{ secrets.FIREBASE_PROJECT_ID }} diff --git a/.github/workflows/firebase-hosting-pull-request.yml b/.github/workflows/firebase-hosting-pull-request.yml new file mode 100644 index 0000000..14a66d4 --- /dev/null +++ b/.github/workflows/firebase-hosting-pull-request.yml @@ -0,0 +1,21 @@ +# This file was auto-generated by the Firebase CLI +# https://github.com/firebase/firebase-tools + +name: Deploy to Firebase Hosting on PR +on: pull_request +permissions: + checks: write + contents: read + pull-requests: write +jobs: + build_and_preview: + if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: yarn nx run website:build + - uses: FirebaseExtended/action-hosting-deploy@v0 + with: + repoToken: ${{ secrets.GITHUB_TOKEN }} + firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }} + projectId: ${{ secrets.FIREBASE_PROJECT_ID }} diff --git a/.gitignore b/.gitignore index 43a37dc..695b983 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,4 @@ Thumbs.db .nx/workspace-data .angular .env +.firebaserc diff --git a/firebase.json b/firebase.json new file mode 100644 index 0000000..1242ff0 --- /dev/null +++ b/firebase.json @@ -0,0 +1,16 @@ +{ + "hosting": { + "public": "dist/apps/website/browser", + "ignore": [ + "firebase.json", + "**/.*", + "**/node_modules/**" + ], + "rewrites": [ + { + "source": "**", + "destination": "/index.html" + } + ] + } +} From 64b546f8a7a0575c1e06d8b13c471af6888a4ec9 Mon Sep 17 00:00:00 2001 From: Valery Melou Date: Sat, 13 Jul 2024 14:01:20 +0100 Subject: [PATCH 2/4] chore: fix deployment pipeline --- .github/workflows/cd.yml | 29 +++++++++++++++++++ .github/workflows/ci.yml | 16 ++++++++++ .github/workflows/firebase-hosting-merge.yml | 20 ------------- .../firebase-hosting-pull-request.yml | 21 -------------- .../src/lib/blog-article.component.spec.ts | 13 +++++++++ .../src/lib/blog-home.component.spec.ts | 7 +++-- 6 files changed, 63 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/cd.yml delete mode 100644 .github/workflows/firebase-hosting-merge.yml delete mode 100644 .github/workflows/firebase-hosting-pull-request.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..77af054 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,29 @@ +on: + workflow_call: + inputs: + environment: + required: true + type: string + description: 'The environment to deploy to' + +jobs: + deploy: + runs-on: ubuntu-latest + environment: ${{ inputs.environment }} + steps: + - uses: actions/checkout@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'yarn' + + - run: yarn install + - run: npx nx run website:build + - uses: FirebaseExtended/action-hosting-deploy@v0 + with: + repoToken: ${{ secrets.GITHUB_TOKEN }} + firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }} + channelId: live + projectId: ${{ secrets.FIREBASE_PROJECT_ID }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 37f0f54..d361de3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,8 @@ concurrency: permissions: actions: read contents: read + checks: write + pull-requests: write jobs: test: @@ -54,3 +56,17 @@ jobs: path: | .nx key: ${{ steps.nx-cache-restore.outputs.cache-primary-key }} + + deploy-preview: + if: github.ref == 'refs/heads/develop' or github.event.pull_request.head.repo.full_name == github.repository + uses: ./.github/workflows/cd.yml + secrets: inherit + with: + environment: staging + + deploy: + if: github.ref == 'refs/heads/master' + uses: ./.github/workflows/cd.yml + secrets: inherit + with: + environment: production diff --git a/.github/workflows/firebase-hosting-merge.yml b/.github/workflows/firebase-hosting-merge.yml deleted file mode 100644 index 6fc7d11..0000000 --- a/.github/workflows/firebase-hosting-merge.yml +++ /dev/null @@ -1,20 +0,0 @@ -# This file was auto-generated by the Firebase CLI -# https://github.com/firebase/firebase-tools - -name: Deploy to Firebase Hosting on merge -on: - push: - branches: - - master -jobs: - build_and_deploy: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - run: yarn nx run website:build - - uses: FirebaseExtended/action-hosting-deploy@v0 - with: - repoToken: ${{ secrets.GITHUB_TOKEN }} - firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }} - channelId: live - projectId: ${{ secrets.FIREBASE_PROJECT_ID }} diff --git a/.github/workflows/firebase-hosting-pull-request.yml b/.github/workflows/firebase-hosting-pull-request.yml deleted file mode 100644 index 14a66d4..0000000 --- a/.github/workflows/firebase-hosting-pull-request.yml +++ /dev/null @@ -1,21 +0,0 @@ -# This file was auto-generated by the Firebase CLI -# https://github.com/firebase/firebase-tools - -name: Deploy to Firebase Hosting on PR -on: pull_request -permissions: - checks: write - contents: read - pull-requests: write -jobs: - build_and_preview: - if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - run: yarn nx run website:build - - uses: FirebaseExtended/action-hosting-deploy@v0 - with: - repoToken: ${{ secrets.GITHUB_TOKEN }} - firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT }} - projectId: ${{ secrets.FIREBASE_PROJECT_ID }} diff --git a/libs/blog/feature-article/src/lib/blog-article.component.spec.ts b/libs/blog/feature-article/src/lib/blog-article.component.spec.ts index a9746cf..f658f6d 100644 --- a/libs/blog/feature-article/src/lib/blog-article.component.spec.ts +++ b/libs/blog/feature-article/src/lib/blog-article.component.spec.ts @@ -1,5 +1,9 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { provideRouter } from '@angular/router'; + import { BlogArticleComponent } from './blog-article.component'; +import { ArticleService, Article } from '@valerymelou/blog/data-access'; +import { of } from 'rxjs'; describe('BlogArticleComponent', () => { let component: BlogArticleComponent; @@ -8,6 +12,15 @@ describe('BlogArticleComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ imports: [BlogArticleComponent], + providers: [ + provideRouter([]), + { + provide: ArticleService, + useValue: { + getOne: () => of(new Article()), + }, + }, + ], }).compileComponents(); fixture = TestBed.createComponent(BlogArticleComponent); diff --git a/libs/blog/feature-home/src/lib/blog-home.component.spec.ts b/libs/blog/feature-home/src/lib/blog-home.component.spec.ts index f83e407..c88cb99 100644 --- a/libs/blog/feature-home/src/lib/blog-home.component.spec.ts +++ b/libs/blog/feature-home/src/lib/blog-home.component.spec.ts @@ -1,8 +1,11 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { BlogHomeComponent } from './blog-home.component'; -import { Article, ArticleService } from '@valerymelou/blob/data-access'; + import { of } from 'rxjs'; +import { Article, ArticleService } from '@valerymelou/blog/data-access'; + +import { BlogHomeComponent } from './blog-home.component'; + describe('BlogHomeComponent', () => { let component: BlogHomeComponent; let fixture: ComponentFixture; From cb08bbc5e65e42a4b73095180a5a1638039a6fe5 Mon Sep 17 00:00:00 2001 From: Valery Melou Date: Sat, 13 Jul 2024 14:03:16 +0100 Subject: [PATCH 3/4] chore: fix logical expression in ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d361de3..28d14e9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,7 +58,7 @@ jobs: key: ${{ steps.nx-cache-restore.outputs.cache-primary-key }} deploy-preview: - if: github.ref == 'refs/heads/develop' or github.event.pull_request.head.repo.full_name == github.repository + if: github.ref == 'refs/heads/develop' || github.event.pull_request.head.repo.full_name == github.repository uses: ./.github/workflows/cd.yml secrets: inherit with: From 094233b5741a27e51da718a1c38ecf03842de281 Mon Sep 17 00:00:00 2001 From: Valery Melou Date: Sat, 13 Jul 2024 14:11:00 +0100 Subject: [PATCH 4/4] chore: add dependency on test for deploy jobs in ci.yml --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 28d14e9..8df74a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,7 +58,8 @@ jobs: key: ${{ steps.nx-cache-restore.outputs.cache-primary-key }} deploy-preview: - if: github.ref == 'refs/heads/develop' || github.event.pull_request.head.repo.full_name == github.repository + if: github.ref == 'refs/heads/develop' + needs: test uses: ./.github/workflows/cd.yml secrets: inherit with: @@ -66,6 +67,7 @@ jobs: deploy: if: github.ref == 'refs/heads/master' + needs: test uses: ./.github/workflows/cd.yml secrets: inherit with: