Skip to content

Prepare for merge

Prepare for merge #55

name: Build and Maybe Deploy
on:
push:
branches:
- '**'
# Note this is NOT REGEX - see https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet
tags:
- '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].[0-9]+'
# Only allow one build at a time on given branch or tag
concurrency:
group: "cloud-monitoring-integration-demo-${{ github.ref }}"
jobs:
build-deploy-dev:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: npm
- name: Install Dependencies
run: |
npm ci
# Log versions to help debug builds
- name: Show Versions
run: |
echo "npm $(npm --version)"
echo "node: $(node --version)"
echo "gcloud: $(gcloud --version)"
- name: Build
run: |
npm run build
npm prune --production
- name: Install gcloud
uses: google-github-actions/setup-gcloud@v1
- name: Auth gcloud
uses: google-github-actions/auth@v1
if: github.ref == 'refs/heads/main' || contains(github.ref, 'refs/tags/')
with:
project_id: ${{ contains(github.ref, 'refs/tags/') && 'mabl-prod' || 'mabl-dev' }}
credentials_json: "${{ contains(github.ref, 'refs/tags/') && secrets.GCP_DEPLOY_SERVICE_ACCOUNT_MABL_PROD || secrets.GCP_DEPLOY_SERVICE_ACCOUNT_MABL_DEV }}"
- name: Deploy to Dev
if: github.ref == 'refs/heads/main'
run: |
GIT_SHA=${{ github.sha }}
GIT_SHA_SHORT=${GIT_SHA:0:7}
gcloud functions deploy ${{ secrets.WEBHOOK_NAME }}\
--runtime nodejs18\
--trigger-http\
--update-labels "app_hash=${GIT_SHA_SHORT},app_name=handle_plan_webhook"\
--project=mabl-dev\
--entry-point=handlePlanWebhook\
--region us-central1\
--allow-unauthenticated\
--set-env-vars=GCP_PROJECT=mabl-dev\
--service-account=${{ secrets.GCF_SERVICE_ACCOUNT_MABL_DEV }}\
--set-build-env-vars=GOOGLE_NODE_RUN_SCRIPTS="" \
--security-level=secure-always
- name: Deploy to Prod
if: contains(github.ref, 'refs/tags/')
run: |
GIT_SHA=${{ github.sha }}
GIT_SHA_SHORT=${GIT_SHA:0:7}
gcloud functions deploy ${{ secrets.WEBHOOK_NAME }}\
--runtime nodejs18\
--trigger-http\
--update-labels "app_hash=${GIT_SHA_SHORT},app_name=handle_plan_webhook"\
--project=mabl-prod\
--entry-point=handlePlanWebhook\
--region us-central1\
--allow-unauthenticated\
--set-env-vars=GCP_PROJECT=mabl-prod\
--service-account=${{ secrets.GCF_SERVICE_ACCOUNT_MABL_PROD }}\
--set-build-env-vars=GOOGLE_NODE_RUN_SCRIPTS="" \
--security-level=secure-always