Skip to content

Commit

Permalink
Merge pull request #27 from islami00/development
Browse files Browse the repository at this point in the history
(feat) added cd for demo project.
  • Loading branch information
islami00 authored Apr 9, 2022
2 parents 09e4277 + a93061c commit 48b3444
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 69 deletions.
56 changes: 35 additions & 21 deletions .github/workflows/deploy-nightly.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,68 @@
name: CD - Nightly
name: CD (Deploy All)

on:
push:
# nightly releases should only stem from related tags. No auto checks for now though, only branch protection for nightly env.
# releases should only stem from related tags. No auto checks for now though, only branch protection for nightly env.
tags:
- v*.*.*-nightly*
- v*.*.*

jobs:
config-env:
runs-on: ubuntu-20.04
# Map a step output to job output
outputs:
deploy-env: ${{ steps.step1.outputs.deploy_env }}
steps:
- id: step1
name: Set env
if: contains(github.ref, 'nightly')
run: echo "::set-output name=deploy_env::nightly"

web-app:
needs: ['config-env']
if: "! startsWith(github.event.head_commit.message, '[CI Skip]')"
environment: nightly
runs-on: ubuntu-latest
environment: ${{ needs.config-env.outputs.deploy-env }}
runs-on: ubuntu-20.04
env:
DEPLOY_ENV: nightly
DEPLOY_ENV: ${{ needs.config-env.outputs.deploy-env }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
# Repeat Build Setup. Separate terminal outs.
# Configure app for env
- run: yarn install --immutable
- run: yarn lint
# Configure app specially for nightly env
- name: Configure, build, and tar.
- name: Configure, build.
run: |
node ./scripts/frontend_env_set.cjs
yarn build
tar -cvf web-app-nightly-build.tar ./build
- name: tar
run: node ./scripts/do-tar-frontend.cjs
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: web-app-nightly-build
path: web-app-nightly-build.tar
name: '${{ env.ARTIFACT_NAME }}'
path: '${{ env.ARTIFACT_PATH }}'
- name: Deploy to firebase hosting
uses: w9jds/firebase-action@master
with:
args: deploy --only hosting
env:
PROJECT_ID: ${{ secrets.FIREBASE_PROJECT_ALIAS }}
PROJECT_ID: ${{ secrets.FIREBASE_PROJECT_ID }}
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
servers:
runs-on: ubuntu-latest
environment: nightly
needs: ['config-env']
runs-on: ubuntu-20.04
environment: ${{ needs.config-env.outputs.deploy-env }}
# Oidc perms.
permissions:
contents: 'read'
id-token: 'write'
strategy:
matrix:
server: ['polkadot-apac-hackathon/auth-server']
server: ['polkadot-apac-hackathon/auth-server','functions']
# All scripts run in server wd.
defaults:
run:
Expand All @@ -68,23 +82,23 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: '${{ env.ARTIFACT_NAME }}'
path: ${{ matrix.server }}/server-*.tar
path: ${{ matrix.server }}/servers-*.tar
# Placed last due to credential export.
- name: Authenticate to Google Cloud
id: auth
uses: google-github-actions/auth@v0
with:
workload_identity_provider: ${{ secrets.SERVER_WORKLOAD_IDENTITY_PROVIDER }}
service_account: '${{ secrets.AUTH_SA_NAME }}@${{ secrets.PROJECT_ID }}.iam.gserviceaccount.com'
service_account: '${{ secrets.AUTH_SA_NAME }}@${{ secrets.GCLOUD_PROJECT_ID }}.iam.gserviceaccount.com'
- name: Publish to gcp
run: npm run publish-code -- --version=${{ env.APP_VERSION_GCLOUD }} -q
working-directory: ${{ matrix.server }}/lib

# Finally create release with artifacts
# Finally, create release with artifacts
create-release:
runs-on: ubuntu-latest
environment: nightly
needs: ['web-app','servers']
needs: ['config-env','web-app','servers']
runs-on: ubuntu-20.04
environment: ${{ needs.config-env.outputs.deploy-env }}
steps:
- uses: actions/checkout@v2
- name: Download artifacts
Expand Down
19 changes: 8 additions & 11 deletions .github/workflows/deploy-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,27 @@ name: Deploy to Preview Channel

on:
pull_request:
branches: [master]
branches: [master,development]
# Optionally configure to run only for specific files. For example:
# paths:
# - "website/**"

jobs:
build_and_preview:
if: '${{ github.event.pull_request.head.repo.full_name == github.repository }}'
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
if: "! github.event.pull_request.head.repo.fork "
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
- run: npm i -g yarn
- run: yarn set version stable
- run: yarn install --immutable
- run: yarn run lint:fix
- run: yarn run build
# - run: npm ci && yarn run build
- run: |
yarn install --immutable
yarn run lint
yarn run build
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_CHOCOLATE_DEMO }}'
expires: 30d
expires: 10d
projectId: chocolate-demo

27 changes: 0 additions & 27 deletions .github/workflows/firebase-hosting-merge.yml

This file was deleted.

9 changes: 4 additions & 5 deletions functions/scripts/do-tar.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ const prCWD = path.resolve(__dirname, '../');
const here = path.basename(prCWD);
process.chdir(prCWD);
// Get env, and tag
const env = process.env.DEPLOY_ENV ? `-${process.env.DEPLOY_ENV}` : '';
const ref = process.env.GITHUB_REF;
console.log('Producing tar artifact for ', ref);
let ver = '';
let verEnv = '';
let gVerEnv = '';
if (ref) {
const refArr = ref.split('/');
verEnv = `${refArr[refArr.length - 1]}`;
const verEnv = `${refArr[refArr.length - 1]}`;
// Ret format: viii-nightly-mm-dd-yy[1234]
gVerEnv = verEnv.replace(/\./g, '').replace(/\+/g, '--');
ver = `-${verEnv}`;
Expand All @@ -25,7 +23,9 @@ if (ref) {
// Then do tar.
(async function main() {
// tar
const { stderr, stdout } = await execPromise(`tar -cvf server-${here}${ver}${env}.tar ./lib`);
const { stderr, stdout } = await execPromise(
`tar -cvf servers-${here}${ver}.tar ./lib`
);
console.log(stdout);
if (stderr) {
throw new Error(stderr);
Expand All @@ -36,7 +36,6 @@ if (ref) {
const { stderr: var2Err, stdout: var2Out } = await execPromise(
`
echo "ARTIFACT_NAME=${here}" >> $GITHUB_ENV &&
echo "APP_VERSION=${verEnv}" >> $GITHUB_ENV &&
echo "APP_VERSION_GCLOUD=${gVerEnv}" >> $GITHUB_ENV
`
);
Expand Down
7 changes: 2 additions & 5 deletions polkadot-apac-hackathon/auth-server/scripts/do-tar.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ const prCWD = path.resolve(__dirname, '../');
const here = path.basename(prCWD);
process.chdir(prCWD);
// Get env, and tag
const env = process.env.DEPLOY_ENV ? `-${process.env.DEPLOY_ENV}` : '';
const ref = process.env.GITHUB_REF;
console.log('Producing tar artifact for ', ref);
let ver = '';
let verEnv = '';
let gVerEnv = '';
if (ref) {
const refArr = ref.split('/');
verEnv = `${refArr[refArr.length - 1]}`;
const verEnv = `${refArr[refArr.length - 1]}`;
// Ret format: viii-nightly-mm-dd-yy[1234]
gVerEnv = verEnv.replace(/\./g, '').replace(/\+/g, '--');
ver = `-${verEnv}`;
Expand All @@ -25,7 +23,7 @@ if (ref) {
// Then do tar.
(async function main() {
// tar
const { stderr, stdout } = await execPromise(`tar -cvf server-${here}${ver}${env}.tar ./lib`);
const { stderr, stdout } = await execPromise(`tar -cvf servers-${here}${ver}.tar ./lib`);
console.log(stdout);
if (stderr) {
throw new Error(stderr);
Expand All @@ -36,7 +34,6 @@ if (ref) {
const { stderr: var2Err, stdout: var2Out } = await execPromise(
`
echo "ARTIFACT_NAME=${here}" >> $GITHUB_ENV &&
echo "APP_VERSION=${verEnv}" >> $GITHUB_ENV &&
echo "APP_VERSION_GCLOUD=${gVerEnv}" >> $GITHUB_ENV
`
);
Expand Down
43 changes: 43 additions & 0 deletions scripts/do-tar-frontend.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const path = require('path');
const { exec } = require('child_process');
const { promisify } = require('util');

// Cd
const prCWD = path.resolve(__dirname, '../');
process.chdir(prCWD);
const execPromise = promisify(exec);
// Get env, and tag
const env = process.env.DEPLOY_ENV ? `-${process.env.DEPLOY_ENV}` : '';
const ref = process.env.GITHUB_REF;
console.log('Producing tar artifact for ', ref);
let ver = '';
let verEnv = '';
if (ref) {
const refArr = ref.split('/');
verEnv = `${refArr[refArr.length - 1]}`;
// Ret format: viii-?(nightly)-mm-dd-yy[1234]
ver = `-${verEnv}`;
}

// Then do tar.
(async function main() {
// tar
const { stderr, stdout } = await execPromise(`tar -cvf web-app-build${ver}.tar ./build`);
console.log(stdout);
if (stderr) {
throw new Error(stderr);
}
const { stderr: var2Err, stdout: var2Out } = await execPromise(
`
echo "ARTIFACT_NAME=web-app-build${env}" >> $GITHUB_ENV &&
echo "ARTIFACT_PATH=web-app-build${ver}.tar" >> $GITHUB_ENV
`
);
console.log(var2Out);
if (var2Err) {
throw new Error(var2Err);
}
})().catch((err) => {
process.emitWarning(err);
process.exitCode = 1;
});

0 comments on commit 48b3444

Please sign in to comment.