Skip to content

Commit

Permalink
feat(ci): add circle ci configuration
Browse files Browse the repository at this point in the history
- Setup Firebase
- Add Circle CI configuration
- Add CI job to deploy to Firebase Hosting
  • Loading branch information
ricardochl committed May 24, 2024
1 parent e9a4714 commit 837a341
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 24 deletions.
123 changes: 103 additions & 20 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,113 @@
# See: https://circleci.com/docs/configuration-reference
version: 2.1

# Define a job to be invoked later in a workflow.
# See: https://circleci.com/docs/jobs-steps/#jobs-overview & https://circleci.com/docs/configuration-reference/#jobs
jobs:
say-hello:
# Specify the execution environment. You can specify an image from Docker Hub or use one of our convenience images from CircleCI's Developer Hub.
# See: https://circleci.com/docs/executor-intro/ & https://circleci.com/docs/configuration-reference/#executor-job
docker:
# Specify the version you desire here
# See: https://circleci.com/developer/images/image/cimg/base
- image: cimg/base:current
# Settings common to each job
job_defaults: &job_defaults
working_directory: ~/angular-docs-es
docker:
- image: cimg/node:lts-browsers

orbs:
node: circleci/[email protected]
build-tools: circleci/[email protected]
browser-tools: circleci/[email protected]

# Add steps to the job
# See: https://circleci.com/docs/jobs-steps/#steps-overview & https://circleci.com/docs/configuration-reference/#steps
commands:
# Command for checking out the source code from GitHub. This also ensures that the source code
# can be merged to the main branch without conflicts.
checkout_and_rebase:
description: Checkout and verify clean merge with main
steps:
# Checkout the code as the first step.
- checkout
- run:
name: "Say hello"
command: "echo Hello, World!"
name: Set git user.name and user.email for rebase.
# User is required for rebase.
command: |
git config user.name "ricardochl"
git config user.email "[email protected]"
- build-tools/merge-with-parent:
parent: main
setup:
description: 'Set up executor'
steps:
- attach_workspace:
at: ~/
setup_firebase_auth:
description: 'Set up Firebase authentication'
steps:
- run:
name: Create a $GOOGLE_APPLICATION_CREDENTIALS environment variable
command: |
# Set the variable at runtime because CircleCI doesn't support interpolation when setting environment variables.
echo 'export GOOGLE_APPLICATION_CREDENTIALS="$HOME"/google_service_account.json' >> "$BASH_ENV"
- run:
name: Create GSA key JSON file
command: echo $GSA_KEY > $GOOGLE_APPLICATION_CREDENTIALS

# ----------------------------------
# Job definitions.
# ----------------------------------

jobs:
# ----------------------------------
# initialize job
# ----------------------------------
initialize:
<<: *job_defaults
steps:
- checkout_and_rebase
- node/install-packages
- persist_to_workspace:
root: ~/
paths:
- angular-docs-es
# -----------------------------------
# Build job.
# -----------------------------------
build:
<<: *job_defaults
steps:
- setup
- run:
name: Build project in CI mode (pre build)
command: npm run build:ci
- run:
name: Installing packages
working_directory: ./build
command: yarn install
- run:
name: Build adev-es docs
working_directory: ./build
command: yarn bazel build //adev:build --fast_adev --local_ram_resources="HOST_RAM*.90" --jobs=2
- persist_to_workspace:
root: ~/
paths:
- angular-docs-es/build/dist/bin/adev/build/browser

# -----------------------------------
# Firebase deploy to staging job.
# -----------------------------------
firebase-deploy-staging:
<<: *job_defaults
steps:
- setup
- setup_firebase_auth
- run:
name: 'Deploy Main Branch to Firebase'
command: |
npm run deploy:staging
# Orchestrate jobs using workflows
# See: https://circleci.com/docs/workflows/ & https://circleci.com/docs/configuration-reference/#workflows
workflows:
say-hello-workflow: # This is the name of the workflow, feel free to change it to better match your workflow.
# Inside the workflow, you define the jobs you want to run.
build-workflow:
jobs:
- say-hello
- initialize
- build:
requires:
- initialize
- firebase-deploy-staging:
filters:
branches:
only:
- main
requires:
- build
16 changes: 16 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"projects": {
"default": "angular-hispano-staging",
"staging": "angular-hispano-staging"
},
"targets": {
"angular-hispano-staging": {
"hosting": {
"staging": [
"angular-hispano-docs-staging"
]
}
}
},
"etags": {}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ yarn-error.log
# System files
.DS_Store
Thumbs.db

# Firebase Caching
.firebase
17 changes: 17 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"hosting": {
"target": "staging",
"public": "build/dist/bin/adev/build/browser",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "zx tools/build.mjs",
"build:ci": "zx tools/build.mjs -- --ci",
"start": "zx tools/watch.mjs",
"update-origin": "zx tools/update-origin.mjs"
},
"update-origin": "zx tools/update-origin.mjs",
"deploy:staging": "firebase use staging && firebase deploy --only hosting:staging"
},
"keywords": [],
"author": "",
"license": "ISC",
Expand Down
9 changes: 7 additions & 2 deletions tools/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import { chalk } from 'zx';
import { applyPatches, buildADEV, copyLocalizedFiles, resetBuildDir } from './lib/common.mjs';

try {
const { ci = false } = argv;

console.log(chalk.green('==== setup ===='));
await setup();
console.log(chalk.green('==== preBuild ===='));
await preBuild();
console.log(chalk.green('==== build ===='));
await build();

if(!ci){
console.log(chalk.green('==== build ===='));
await build();
}
} catch (e) {
console.error(chalk.red(e));
process.exit(1);
Expand Down

0 comments on commit 837a341

Please sign in to comment.