Skip to content

Commit

Permalink
v0.15.0 (#69)
Browse files Browse the repository at this point in the history
* feat(deps): add depdendabot settings
* fix(setEnv): replace set-env (deprecated) with appending GITHUB_ENV file
* build(dev-deps): update @babel/cli from 7.8.4 to 7.12.10
* build(dev-deps): update eslint from 6.8.0 to 7.16.0
  • Loading branch information
prescottprue authored Dec 31, 2020
1 parent 5c3e107 commit 26f5569
Show file tree
Hide file tree
Showing 34 changed files with 1,525 additions and 1,851 deletions.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# For for information on config options, visit docs:
# https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
8 changes: 2 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
uses: actions/checkout@v2

- name: Check version changes
uses: EndBug/version-check@v1
uses: EndBug/version-check@v2
id: check

- name: Version update detected
Expand All @@ -23,7 +23,7 @@ jobs:

- name: Setup Node
if: steps.check.outputs.changed == 'true'
uses: actions/setup-node@v1
uses: actions/setup-node@v2.1.2
with:
node-version: 12
registry-url: https://registry.npmjs.org/
Expand All @@ -41,15 +41,12 @@ jobs:

- name: Install Dependencies
if: steps.check.outputs.changed == 'true'
env:
CI: true
run: |
yarn install --frozen-lockfile
- name: Run Unit Tests + Coverage
if: steps.check.outputs.changed == 'true'
env:
CI: true
CODE_CLIMATE: ${{ secrets.CODE_CLIMATE }}
run: yarn test:cov

Expand All @@ -74,7 +71,6 @@ jobs:
- name: Upload Coverage + Climate
if: steps.check.outputs.changed == 'true' && success()
env:
CI: true
CODE_COV: ${{ secrets.CODE_COV }}
CODECLIMATE_REPO_TOKEN: ${{ secrets.CODE_CLIMATE }}
# Upload to Code Coverage. Curl used in place of codecov/codecov-action
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
uses: actions/checkout@v2

- name: Setup Node
uses: actions/setup-node@v1
uses: actions/setup-node@v2.1.2
with:
node-version: 12

Expand All @@ -26,18 +26,14 @@ jobs:
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}

- name: Install Dependencies
env:
CI: true
run: |
yarn install --frozen-lockfile
- name: Run Unit Tests + Coverage
run: yarn test:cov

- name: Upload Coverage + Climate
if: success()
env:
CI: true
CODE_COV: ${{ secrets.CODE_COV }}
CODECLIMATE_REPO_TOKEN: ${{ secrets.CODE_CLIMATE }}
run: |
Expand Down
95 changes: 71 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,60 +11,79 @@

## Features

* Skip For Pull Requests
* Automatic loading of commit message as deploy message
* Deploy to Different Firebase Instances based on Branch
* Deploy to different Firebase projects based on Git Branch
* Automatically use commit message as deploy message
* Expose CI environment variables based on branch name
* Mapping of CI environment variables to Firebase Functions Config
* Create a config file based on CI environment variables
* Optional Deploying of targets Functions, Hosting, Database (rules) and Storage (rules)
* Skip For Pull Requests

## Getting Started

1. Generate a CI token through `firebase-tools` by running `firebase login:ci`
1. Place this token within your CI environment under the variable `FIREBASE_TOKEN`
1. Install `firebase-ci` into your project (so it is available on your CI): `npm install --save-dev firebase-ci firebase-tools`. If you don't want `firebase-tools` as a dev dependency, it can be left out as it is installed automatically if it doesn't exist.
1. Add the following npm scripts:
1. Set different Firebase project names in `projects` parameter of `.firebaserc`. The project aliases should match branch names like so:

```json
"build:config": "firebase-ci createConfig",
"deploy": "firebase-ci deploy"
{
"projects": {
"prod": "prod-firebase",
"master": "dev-firebase",
"default": "dev-firebase"
}
}
```
1. Add the following scripts to your CI config, for instance within a `travis.yml`:

1. Add calls to the scripts within to your CI stages, here are a few example snippets:

**Github Actions** (*.github/workflows/\*.yml*)
```yaml
jobs:
deploy:
name: ${{ matrix.app }} Deploy
runs-on: ubuntu-18.04
steps:
- name: Checkout Code
uses: actions/checkout@v2

## Place other steps for installing deps, building, etc. here
## See the github-actions example for a full workflow

# Deploy to Firebase project matching branch name in projects parameter of .firebaserc
- name: Deploy To Firebase
run: |
$(npm bin)/firebase-ci deploy
```

**Travis** (*travis.yml*)
```yaml
script:
- npm run build:config # Build src/config.js (environment specific client config)
- npm run lint # Check for lint
- npm run deploy # Deploy to Firebase
# Deploy to Firebase project matching branch name in projects parameter of .firebaserc
- $(npm bin)/firebase-ci deploy
```

**NOTES**:
* `firebase-ci` can be used through the nodejs `bin` **OR** installed globally
* `firebase-ci` can be used through the nodejs `bin` **OR** installed globally (npm bin is used here since instructions include adding firebase-ci as a dev dependency)
* `firebase-tools` will be installed (from `@latest`) if it is not already installed locally or globally

1. Set different Firebase instances names to `.firebaserc` like so:
```json
{
"projects": {
"prod": "prod-firebase",
"master": "dev-firebase",
"default": "dev-firebase"
}
}
```

## Setting Project

There are a number of ways to set which Firebase project within `.firebaserc` is being used when running actions. Below is the order of for how the project is determined (default at bottom):

* `FIREBASE_CI_PROJECT` environment variable (overrides all)
* branch name (dependent on CI provider):
* Github Actions - `GITHUB_HEAD_REF` or `GITHUB_REF` (`refs/heads/` prefix is removed)
* Travis-CI - `TRAVIS_BRANCH`
* Gitlab - `CI_COMMIT_REF_SLUG`
* Circle-CI - `CIRCLE_BRANCH`
* wercker - `WERCKER_GIT_BRANCH`
* drone-ci - `DRONE_BRANCH`
* codeship - `CI_BRANCH`
* bitbucket - `BITBUCKET_BRANCH`
* fallback name (dependent on CI provider)
* Gitlab - `CI_ENVIRONMENT_SLUG`
* Other - `master`
* `master`
* `default` (must be set within `.firebaserc`)

Expand All @@ -78,7 +97,10 @@ Default installation uses `@latest` tag, but there are also others:

## [Examples](/examples)

* [Basic](/examples/basic) - Basic html file upload to Firebase hosting of different projects (or "environments")
Examples are the same basic html file upload to Firebase hosting of different projects (or "environments") for different CI providers:

* [Travis](/examples/travis)
* [Github Actions](/examples/github-actions)

## Why?

Expand Down Expand Up @@ -125,8 +147,33 @@ It can be convenient for the version within the `functions/package.json` file to
}
```

### setEnv

Expose environment variables to CI based on current branch.

With a `.firebaserc` that looks like so:

```yaml
"ci": {
"setEnv": {
"master": {
"SOME_VAR": "some value"
"REACT_APP_ENV_VARIABLE": "val passed to react app"
},
"prod": {
"SOME_VAR": "some other value"
"REACT_APP_ENV_VARIABLE": "val passed to react app"
}
}
}
```

`SOME_VAR` and `REACT_APP_ENV_VARIABLE` will be exposed to environment variables of your CI based on branch. Meaning that on the master branch `SOME_VAR` will be set to `"some value"`

### createConfig

**DEPRECATED**

Create a config file based on CI environment variables (defaults to `src/config.js`). Allows for creating files of different types based on the extension passed.

With the following environment variables:
Expand Down
2 changes: 1 addition & 1 deletion bin/firebase-ci
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ program.version(pkg.version)

require('../cmds')(program)

program.on('*', function(name) {
program.on('*', function (name) {
/* eslint-disable no-console */
console.log(
"'" + name + "' is not a known command. See 'firebase-ci --help':"
Expand Down
2 changes: 1 addition & 1 deletion cmds/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const getBranch = require('../lib/utils/ci').getBranch
* echo "Project to deploy to $(firebase-ci project)"
* // => "Project to deploy to my-project"
*/
module.exports = function(program) {
module.exports = function (program) {
program
.command('branch')
.description(
Expand Down
2 changes: 1 addition & 1 deletion cmds/copyVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const copyVersion = require('../lib/actions/copyVersion').default
* - npm i -g firebase-ci
* - firebase-ci copyVersion
*/
module.exports = function(program) {
module.exports = function (program) {
program
.command('copyVersion')
.description('Copy version from outer folder into functions folder')
Expand Down
14 changes: 3 additions & 11 deletions cmds/createConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,11 @@
const createConfig = require('../lib/actions/createConfig').default

/**
* @name deploy
* @description Deploy to Firebase only on build branches (master, stage, prod)
* @name createConfig
* @description Create src/config.js file (planned to be deprecated)
* @param {object} program - Commander program object
* @example <caption>Basic</caption>
* # make sure FIREBASE_TOKEN env variable is set
* npm i -g firebase-ci
* firebase-ci deploy
* @example <caption>Travis</caption>
* after_success:
* - npm i -g firebase-ci
* - firebase-ci deploy
*/
module.exports = function(program) {
module.exports = function (program) {
program
.command('createConfig')
.description(
Expand Down
4 changes: 2 additions & 2 deletions cmds/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const deployToFirebase = require('../lib/actions/deploy').default
* # make sure FIREBASE_TOKEN env variable is set
* firebase-ci deploy
*/
module.exports = function(program) {
module.exports = function (program) {
program
.command('deploy')
.description(
Expand All @@ -34,7 +34,7 @@ module.exports = function(program) {
)
.option('-s --simple', 'Skip CI actions, and only run deployment')
// .option('-a --actions <actions>', 'Only run certain CI actions (e.g "mapEnv", "createConfig")', /^(mapEnv|createConfig|copyVersion)$/i)
.action(opts => {
.action((opts) => {
return deployToFirebase(opts)
.then(() => process.exit(0))
.catch(() => process.exit(1))
Expand Down
2 changes: 1 addition & 1 deletion cmds/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module.exports = function (client) {
process.env.FORCE_COLOR = true
var loadCommand = function (name) {
const loadCommand = function (name) {
return require('./' + name)(client)
}

Expand Down
2 changes: 1 addition & 1 deletion cmds/mapEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const mapEnv = require('../lib/actions/mapEnv').default
* # make sure you set mapEnv settings in .firebaserc
* firebase-ci mapEnv
*/
module.exports = function(program) {
module.exports = function (program) {
program
.command('mapEnv')
.description('Copy version from outer folder into functions folder')
Expand Down
2 changes: 1 addition & 1 deletion cmds/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const getProjectName = require('../lib/utils/ci').getProjectName
* echo "Project to deploy to $(firebase-ci project)"
* // => "Project to deploy to my-project"
*/
module.exports = function(program) {
module.exports = function (program) {
program
.command('project')
.description('Get name of project associated with current CI environment')
Expand Down
2 changes: 1 addition & 1 deletion cmds/projectId.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const getProjectId = require('../lib/utils/ci').getProjectId
* echo "Project to deploy to $(firebase-ci project)"
* // => "Project to deploy to my-project"
*/
module.exports = function(program) {
module.exports = function (program) {
program
.command('projectId')
.description('Get projectId of associated with current CI environment')
Expand Down
2 changes: 1 addition & 1 deletion cmds/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const runActions = require('../lib/actions/deploy').runActions
* # make sure FIREBASE_TOKEN env variable is set
* firebase-ci deploy
*/
module.exports = function(program) {
module.exports = function (program) {
program
.command('run')
.description(
Expand Down
4 changes: 2 additions & 2 deletions cmds/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const serve = require('../lib/actions/serve').default
* # make sure FIREBASE_TOKEN env variable is set
* firebase-ci deploy
*/
module.exports = function(program) {
module.exports = function (program) {
program
.command('serve')
.description(
Expand All @@ -23,7 +23,7 @@ module.exports = function(program) {
'-o --only <targets>',
'Only serve specified targets, comma-seperated (e.g "hosting, storage")'
)
.action(opts => {
.action((opts) => {
return serve(opts)
.then(() => process.exit(0))
.catch(() => process.exit(1))
Expand Down
34 changes: 0 additions & 34 deletions examples/basic/.firebaserc

This file was deleted.

Loading

0 comments on commit 26f5569

Please sign in to comment.