Skip to content

Instantly share code, notes, and snippets.

@stekhn
Created November 27, 2022 21:39
Show Gist options
  • Save stekhn/685279a5240738a1db820ce80f2ca9e8 to your computer and use it in GitHub Desktop.
Save stekhn/685279a5240738a1db820ce80f2ca9e8 to your computer and use it in GitHub Desktop.
Github Action for building a web application and deploying it to a Google Cloud Storage bucket
# Set up Node.js action: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
# Set up Google Cloud auth action: https://github.com/google-github-actions/auth#usage
# Set up Google Cloud workload identity federation: https://github.com/marketplace/actions/authenticate-to-google-cloud#setting-up-workload-identity-federation
# Upload to Google Cloud Storage: https://github.com/google-github-actions/upload-cloud-storage
name: CI/CD
on:
push:
branches: ['main']
pull_request:
branches: ['main']
jobs:
build-and-deploy:
name: Build & Deploy
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16
cache: yarn
- name: Install dependencies
run: yarn install --prefer-offline
- name: Build project
run: yarn build
- name: Authenticate Github Action
uses: google-github-actions/auth@v0
with:
workload_identity_provider: ${{ secrets.GCP_WIP }}
service_account: ${{ secrets.GCP_SA }}
- name: Upload build to Google Cloud Storage
uses: google-github-actions/upload-cloud-storage@v0
with:
path: public
destination: my-bucket
parent: false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment