Skip to content

Commit

Permalink
Merge pull request #199 from privacy-scaling-explorations/fix/env
Browse files Browse the repository at this point in the history
Fix CI workflow to deploy proper dependecies to each environment
  • Loading branch information
ctrlc03 authored Oct 19, 2023
2 parents 7cfaa5d + 8772edf commit 9275517
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 14 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/deploy-and-test-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ concurrency:
cancel-in-progress: true

jobs:
publish-cli-package:
if: github.ref == 'refs/heads/dev'
uses: ./.github/workflows/publish-dev-packages.yaml

deploy-dev:
uses: ./.github/workflows/firebase-deploy.yaml
uses: ./.github/workflows/firebase-deploy-dev.yaml
secrets: inherit
with:
environment: dev
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/deploy-production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ concurrency:
cancel-in-progress: true

jobs:
publish-cli-package:
if: github.ref == 'refs/heads/main'
uses: ./.github/workflows/publish-production-packages.yaml

deploy-production:
uses: ./.github/workflows/firebase-deploy.yaml
uses: ./.github/workflows/firebase-deploy-production.yaml
secrets: inherit
with:
environment: production
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/deploy-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ concurrency:
cancel-in-progress: true

jobs:
publish-cli-package:
if: github.ref == 'refs/heads/staging'
uses: ./.github/workflows/publish-staging-packages.yaml

deploy-staging:
uses: ./.github/workflows/firebase-deploy.yaml
uses: ./.github/workflows/firebase-deploy-staging.yaml
secrets: inherit
with:
environment: staging
Expand Down
74 changes: 74 additions & 0 deletions .github/workflows/firebase-deploy-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Deploy to Firebase Dev Environment

on:
workflow_call:
inputs:
branch:
description: "Branch to deploy"
required: true
type: string

environment:
description: "Environment to deploy to"
required: true
type: string

firebase_project:
description: "The name of the Firebase project to deploy to"
required: true
type: string

jobs:
deploy-p0tion:
runs-on: ubuntu-22.04
environment: ${{ inputs.environment }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.branch }}

- name: Use Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: "https://registry.npmjs.org"

- name: Update package.json dependencies and names
run: |
# Enable recursive globbing
shopt -s globstar
# Update package.json dependencies
sed -i -e 's/"@p0tion\/actions": "[^"]*"/"@devtion\/actions": "latest"/g' ./packages/backend/package.json
# Update string literals in TypeScript files
sed -i 's|p0tion/actions|devtion/actions|g' packages/**/*.ts
cat ./packages/backend/package.json
cat ./packages/backend/src/functions/ceremony.ts
- name: Install npm packages and write env
run: |
yarn install
echo "${{ secrets.ACTIONS_ENV_FILE }}" > ./packages/actions/.env
echo "${{ secrets.BACKEND_ENV_FILE }}" > ./packages/backend/.env
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: "false"

- name: build packages
run: yarn build
env:
NODE_OPTIONS: "--max_old_space_size=4096"

# Workaround for SSL error. (resource: https://github.com/firebase/firebase-admin-node/issues/1712)
- name: SSL Workaround
run: sudo sed -i '54 s/^/#/' /usr/lib/ssl/openssl.cnf

- name: Deploy to Firebase
uses: w9jds/firebase-action@master
with:
args: deploy --only functions --project ${{ inputs.firebase_project }}
env:
GCP_SA_KEY: ${{ secrets.SERVICE_ACCOUNT_KEY }}
PROJECT_PATH: ./packages/backend
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy to Firebase
name: Deploy to Firebase Production Environment

on:
workflow_call:
Expand Down Expand Up @@ -35,7 +35,7 @@ jobs:

- name: Install npm packages and write env
run: |
yarn install --immutable
yarn install
echo "${{ secrets.ACTIONS_ENV_FILE }}" > ./packages/actions/.env
echo "${{ secrets.BACKEND_ENV_FILE }}" > ./packages/backend/.env
Expand Down
71 changes: 71 additions & 0 deletions .github/workflows/firebase-deploy-staging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Deploy to Firebase Staging Environment

on:
workflow_call:
inputs:
branch:
description: "Branch to deploy"
required: true
type: string

environment:
description: "Environment to deploy to"
required: true
type: string

firebase_project:
description: "The name of the Firebase project to deploy to"
required: true
type: string

jobs:
deploy-p0tion:
runs-on: ubuntu-22.04
environment: ${{ inputs.environment }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.branch }}

- name: Use Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: "https://registry.npmjs.org"

- name: Update package.json dependencies and names
run: |
# Enable recursive globbing
shopt -s globstar
# Update package.json dependencies
sed -i -e 's/"@p0tion\/actions": "[^"]*"/"@stagtion\/actions": "latest"/g' ./packages/backend/package.json
# Update string literals in TypeScript files
sed -i 's|p0tion/actions|stagtion/actions|g' packages/**/*.ts
- name: Install npm packages and write env
run: |
yarn install
echo "${{ secrets.ACTIONS_ENV_FILE }}" > ./packages/actions/.env
echo "${{ secrets.BACKEND_ENV_FILE }}" > ./packages/backend/.env
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: "false"

- name: build packages
run: yarn build
env:
NODE_OPTIONS: "--max_old_space_size=4096"

# Workaround for SSL error. (resource: https://github.com/firebase/firebase-admin-node/issues/1712)
- name: SSL Workaround
run: sudo sed -i '54 s/^/#/' /usr/lib/ssl/openssl.cnf

- name: Deploy to Firebase
uses: w9jds/firebase-action@master
with:
args: deploy --only functions --project ${{ inputs.firebase_project }}
env:
GCP_SA_KEY: ${{ secrets.SERVICE_ACCOUNT_KEY }}
PROJECT_PATH: ./packages/backend
4 changes: 1 addition & 3 deletions .github/workflows/publish-dev-packages.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: Publish @devtion

on:
push:
branches:
- dev
workflow_call:

jobs:
npm-publish-dev:
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/publish-production-packages.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: Publish @p0tion

on:
push:
branches:
- main
workflow_call:

jobs:
npm-publish:
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/publish-staging-packages.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: Publish @stagtion

on:
push:
branches:
- staging
workflow_call:

jobs:
npm-publish-staging:
Expand Down

0 comments on commit 9275517

Please sign in to comment.