Build Site and Deploy to Firebase Hosting #1150
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Site and Deploy to Firebase Hosting | |
on: | |
push: | |
branches: | |
- main | |
pull_request: {} | |
workflow_dispatch: {} | |
schedule: | |
- cron: '42 2 * * *' # run 2:42 am every day | |
env: | |
FIREBASE_PROJECT_ID: favre-base-project | |
NODE_VERSION: 18.17.0 | |
HUGO_VERSION: 0.111.3 | |
WORKING_DIR: './content-downloader' | |
DOCKER_REPO: 'website-favr' | |
jobs: | |
build: | |
name: Build CLI & Site | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code und Submodules | |
uses: actions/checkout@v4 | |
with: | |
submodules: true # Fetch Hugo themes (true OR recursive) | |
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod | |
- name: Prepare Node.js ${{ env.NODE_VERSION }} | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ env.NODE_VERSION }} | |
- name: NPM Install & Test Content-Downloader | |
run: npm run package:ci | |
working-directory: ${{ env.WORKING_DIR }} | |
- name: Run ESLint | |
run: npm run lint | |
working-directory: ${{ env.WORKING_DIR }} | |
- name: Run NPM Audit | |
run: npm audit --audit-level=none | |
working-directory: ${{ env.WORKING_DIR }} | |
- name: Update Content | |
uses: nick-fields/retry@v2 | |
if: (github.event_name == 'schedule') || (github.event_name == 'workflow_dispatch') | |
with: | |
timeout_minutes: 5 | |
retry_wait_seconds: 60 | |
max_attempts: 3 | |
command: ${{ env.WORKING_DIR }}/dist/index.js ./content/ | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | |
FIREBASE_SERVICE_ACCOUNT_JSON: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_FIRESTORE }} | |
- uses: actions/cache@v3 | |
with: | |
path: /tmp/hugo_cache | |
key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.sum') }} | |
restore-keys: | | |
${{ runner.os }}-hugomod- | |
- name: Setup Hugo | |
uses: peaceiris/actions-hugo@v2 | |
with: | |
hugo-version: ${{ env.HUGO_VERSION }} | |
extended: true | |
- name: Build Site with Hugo | |
env: | |
HUGOxPARAMSxGITxLAST_COMMITxHASH: ${{ github.sha }} | |
HUGOxPARAMSxGITxLAST_BUILDxID: ${{ github.run_id }} | |
HUGOxPARAMSxGITxLAST_BUILDxNUMBER: ${{ github.run_number }} | |
run: | | |
hugo version && \ | |
hugo config && \ | |
hugo --verbose --printPathWarnings --minify | |
- name: Upload Hugo Site | |
uses: actions/upload-artifact@v4 | |
with: | |
name: hugo-public | |
path: public | |
retention-days: 2 | |
if-no-files-found: error | |
- name: Upload Updated Content | |
uses: actions/upload-artifact@v4 | |
if: (github.event_name == 'schedule') || (github.event_name == 'workflow_dispatch') | |
with: | |
name: hugo-content | |
path: content | |
retention-days: 2 | |
if-no-files-found: error | |
- name: SonarCloud Scan | |
uses: SonarSource/[email protected] | |
if: github.actor != 'dependabot[bot]' | |
with: | |
projectBaseDir: content-downloader | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
deploy_production: | |
name: Deploy to Firebase Production | |
needs: build | |
runs-on: ubuntu-latest | |
environment: production | |
if: (github.event_name == 'schedule') || (github.event_name == 'workflow_dispatch') | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Download Hugo Site Artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: hugo-public | |
path: public | |
- name: Deploy to Firebase Hosting | |
id: firebase-deploy-prod | |
uses: FirebaseExtended/action-hosting-deploy@main | |
with: | |
repoToken: '${{ secrets.GITHUB_TOKEN }}' | |
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_FAVRE_BASE_PROJECT }}' | |
channelId: live | |
projectId: ${{ env.FIREBASE_PROJECT_ID }} | |
deploy_staging: | |
name: Deploy to Firebase Staging | |
needs: build | |
runs-on: ubuntu-latest | |
environment: staging | |
if: github.event_name == 'pull_request' && github.actor != 'dependabot[bot]' | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Download Hugo Site Artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: hugo-public | |
path: public | |
- name: Deploy to Firebase Hosting (dev preview channel) | |
id: firebase-deploy-preview | |
uses: FirebaseExtended/action-hosting-deploy@main | |
with: | |
repoToken: '${{ secrets.GITHUB_TOKEN }}' | |
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_FAVRE_BASE_PROJECT }}' | |
projectId: ${{ env.FIREBASE_PROJECT_ID }} | |
expires: 7d | |
build_docker: | |
name: Build and Push Docker Image | |
needs: build | |
runs-on: ubuntu-latest | |
if: (github.event_name == 'schedule') || (github.event_name == 'workflow_dispatch') | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
with: | |
submodules: true | |
fetch-depth: 0 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Download Updated Content | |
uses: actions/download-artifact@v4 | |
with: | |
name: hugo-content | |
path: content | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
push: true | |
tags: | | |
ghcr.io/${{ github.repository_owner }}/${{ env.DOCKER_REPO }}:latest |