Skip to content

feat: deployment

feat: deployment #5

Workflow file for this run

name: Build & Deploy
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
permissions:
contents: 'read'
id-token: 'write'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Authenticate with Google Cloud
uses: google-github-actions/auth@v2
#if: github.event_name == 'push' && github.ref == 'refs/heads/main'
with:
project_id: sail-intact
workload_identity_provider: projects/695814629538/locations/global/workloadIdentityPools/github/providers/github
service_account: [email protected]
- name: Set up GCloud SDK
#if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: google-github-actions/setup-gcloud@v2
- name: Use Node.js 22.x
uses: actions/setup-node@v4
with:
node-version: 22.x
- name: Get npm cache directory
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
- name: Backup existing bucket contents
run: |
gsutil mv gs://intact-frontend/** gs://intact-frontend/backup/
echo "backup_done=true" >> $GITHUB_ENV
- name: Deploy to Google Cloud Bucket
uses: google-github-actions/upload-cloud-storage@v2
#if: success() && github.ref == 'refs/heads/main' && env.backup_done == 'true'
with:
path: /dist/
destination: intact-frontend
parent: false
- name: Remove backup
#if: success() && github.ref == 'refs/heads/main' && env.backup_done == 'true'
run: |
gsutil rm -r gs://intact-frontend/backup/
- name: Restore from backup (on failure)
#if: failure() && github.ref == 'refs/heads/main' && env.backup_done == 'true'
run: |
gsutil mv gs://intact-frontend-backup/** gs://intact-frontend/
gsutil -m rm -r gs://intact-frontend-backup/