From 66789d1d6efb6dda75e6e3d7c0695cfb13968d0c Mon Sep 17 00:00:00 2001 From: stefango Date: Tue, 31 Dec 2024 14:36:34 +0800 Subject: [PATCH] feat: host on firebase --- .firebaserc | 5 +++ .github/workflows/firebase-hosting-merge.yml | 36 +++++++++++++++++++ .../firebase-hosting-pull-request.yml | 35 ++++++++++++++++++ .gitignore | 1 + README.md | 1 + firebase.json | 10 ++++++ 6 files changed, 88 insertions(+) create mode 100644 .firebaserc 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/.firebaserc b/.firebaserc new file mode 100644 index 0000000..c8734c2 --- /dev/null +++ b/.firebaserc @@ -0,0 +1,5 @@ +{ + "projects": { + "default": "xzl-blog" + } +} diff --git a/.github/workflows/firebase-hosting-merge.yml b/.github/workflows/firebase-hosting-merge.yml new file mode 100644 index 0000000..f53c709 --- /dev/null +++ b/.github/workflows/firebase-hosting-merge.yml @@ -0,0 +1,36 @@ +# 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: + - main +jobs: + build_and_deploy: + runs-on: ubuntu-latest + env: + HUGO_VERSION: 0.140.0 + steps: + - name: Install Hugo CLI + run: | + wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ + && sudo dpkg -i ${{ runner.temp }}/hugo.deb + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive + - name: Build with Hugo + env: + HUGO_CACHEDIR: ${{ runner.temp }}/hugo_cache + HUGO_ENVIRONMENT: production + run: | + hugo \ + --minify \ + --baseURL "https://xzl-blog.web.app/" + - uses: FirebaseExtended/action-hosting-deploy@v0 + with: + repoToken: ${{ secrets.GITHUB_TOKEN }} + firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_XZL_BLOG }} + channelId: live + projectId: xzl-blog diff --git a/.github/workflows/firebase-hosting-pull-request.yml b/.github/workflows/firebase-hosting-pull-request.yml new file mode 100644 index 0000000..400a004 --- /dev/null +++ b/.github/workflows/firebase-hosting-pull-request.yml @@ -0,0 +1,35 @@ +# 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: + - name: Install Hugo CLI + run: | + wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ + && sudo dpkg -i ${{ runner.temp }}/hugo.deb + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive + - name: Build with Hugo + env: + HUGO_CACHEDIR: ${{ runner.temp }}/hugo_cache + HUGO_ENVIRONMENT: production + run: | + hugo \ + --minify \ + --baseURL "https://xzl-blog.web.app/" + - uses: FirebaseExtended/action-hosting-deploy@v0 + with: + repoToken: ${{ secrets.GITHUB_TOKEN }} + firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_XZL_BLOG }} + projectId: xzl-blog diff --git a/.gitignore b/.gitignore index b583d6e..6075f49 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ public/ .idea/ /img .hugo_build.lock +.firebase diff --git a/README.md b/README.md index 7fca613..e691dfe 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ See https://xzl.netlify.app/ or https://xzl.vercel.app/ # Development ```bash +git clone --recurse-submodules git@github.com:stefango/blog.git # hugo v0.140.0 hugo server -D ``` diff --git a/firebase.json b/firebase.json new file mode 100644 index 0000000..e782939 --- /dev/null +++ b/firebase.json @@ -0,0 +1,10 @@ +{ + "hosting": { + "public": "public", + "ignore": [ + "firebase.json", + "**/.*", + "**/node_modules/**" + ] + } +}