Skip to content

Commit 26f5569

Browse files
authored
v0.15.0 (#69)
* 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
1 parent 5c3e107 commit 26f5569

34 files changed

+1525
-1851
lines changed

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# For for information on config options, visit docs:
2+
# https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates
3+
version: 2
4+
updates:
5+
- package-ecosystem: "npm"
6+
directory: "/"
7+
schedule:
8+
interval: "weekly"
9+
- package-ecosystem: "github-actions"
10+
directory: "/"
11+
schedule:
12+
interval: "weekly"

.github/workflows/publish.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
uses: actions/checkout@v2
1515

1616
- name: Check version changes
17-
uses: EndBug/version-check@v1
17+
uses: EndBug/version-check@v2
1818
id: check
1919

2020
- name: Version update detected
@@ -23,7 +23,7 @@ jobs:
2323

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

4242
- name: Install Dependencies
4343
if: steps.check.outputs.changed == 'true'
44-
env:
45-
CI: true
4644
run: |
4745
yarn install --frozen-lockfile
4846
4947
- name: Run Unit Tests + Coverage
5048
if: steps.check.outputs.changed == 'true'
5149
env:
52-
CI: true
5350
CODE_CLIMATE: ${{ secrets.CODE_CLIMATE }}
5451
run: yarn test:cov
5552

@@ -74,7 +71,6 @@ jobs:
7471
- name: Upload Coverage + Climate
7572
if: steps.check.outputs.changed == 'true' && success()
7673
env:
77-
CI: true
7874
CODE_COV: ${{ secrets.CODE_COV }}
7975
CODECLIMATE_REPO_TOKEN: ${{ secrets.CODE_CLIMATE }}
8076
# Upload to Code Coverage. Curl used in place of codecov/codecov-action

.github/workflows/verify.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
uses: actions/checkout@v2
1212

1313
- name: Setup Node
14-
uses: actions/setup-node@v1
14+
uses: actions/setup-node@v2.1.2
1515
with:
1616
node-version: 12
1717

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

2828
- name: Install Dependencies
29-
env:
30-
CI: true
3129
run: |
3230
yarn install --frozen-lockfile
3331
3432
- name: Run Unit Tests + Coverage
3533
run: yarn test:cov
3634

3735
- name: Upload Coverage + Climate
38-
if: success()
3936
env:
40-
CI: true
4137
CODE_COV: ${{ secrets.CODE_COV }}
4238
CODECLIMATE_REPO_TOKEN: ${{ secrets.CODE_CLIMATE }}
4339
run: |

README.md

Lines changed: 71 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,60 +11,79 @@
1111

1212
## Features
1313

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

2121
## Getting Started
2222

2323
1. Generate a CI token through `firebase-tools` by running `firebase login:ci`
2424
1. Place this token within your CI environment under the variable `FIREBASE_TOKEN`
2525
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.
26-
1. Add the following npm scripts:
26+
1. Set different Firebase project names in `projects` parameter of `.firebaserc`. The project aliases should match branch names like so:
2727

2828
```json
29-
"build:config": "firebase-ci createConfig",
30-
"deploy": "firebase-ci deploy"
29+
{
30+
"projects": {
31+
"prod": "prod-firebase",
32+
"master": "dev-firebase",
33+
"default": "dev-firebase"
34+
}
35+
}
3136
```
32-
1. Add the following scripts to your CI config, for instance within a `travis.yml`:
3337

38+
1. Add calls to the scripts within to your CI stages, here are a few example snippets:
39+
40+
**Github Actions** (*.github/workflows/\*.yml*)
41+
```yaml
42+
jobs:
43+
deploy:
44+
name: ${{ matrix.app }} Deploy
45+
runs-on: ubuntu-18.04
46+
steps:
47+
- name: Checkout Code
48+
uses: actions/checkout@v2
49+
50+
## Place other steps for installing deps, building, etc. here
51+
## See the github-actions example for a full workflow
52+
53+
# Deploy to Firebase project matching branch name in projects parameter of .firebaserc
54+
- name: Deploy To Firebase
55+
run: |
56+
$(npm bin)/firebase-ci deploy
57+
```
58+
59+
**Travis** (*travis.yml*)
3460
```yaml
3561
script:
36-
- npm run build:config # Build src/config.js (environment specific client config)
37-
- npm run lint # Check for lint
38-
- npm run deploy # Deploy to Firebase
62+
# Deploy to Firebase project matching branch name in projects parameter of .firebaserc
63+
- $(npm bin)/firebase-ci deploy
3964
```
4065

4166
**NOTES**:
42-
* `firebase-ci` can be used through the nodejs `bin` **OR** installed globally
67+
* `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)
4368
* `firebase-tools` will be installed (from `@latest`) if it is not already installed locally or globally
4469

45-
1. Set different Firebase instances names to `.firebaserc` like so:
46-
```json
47-
{
48-
"projects": {
49-
"prod": "prod-firebase",
50-
"master": "dev-firebase",
51-
"default": "dev-firebase"
52-
}
53-
}
54-
```
5570

5671
## Setting Project
5772

5873
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):
5974

6075
* `FIREBASE_CI_PROJECT` environment variable (overrides all)
6176
* branch name (dependent on CI provider):
77+
* Github Actions - `GITHUB_HEAD_REF` or `GITHUB_REF` (`refs/heads/` prefix is removed)
6278
* Travis-CI - `TRAVIS_BRANCH`
6379
* Gitlab - `CI_COMMIT_REF_SLUG`
6480
* Circle-CI - `CIRCLE_BRANCH`
81+
* wercker - `WERCKER_GIT_BRANCH`
82+
* drone-ci - `DRONE_BRANCH`
83+
* codeship - `CI_BRANCH`
84+
* bitbucket - `BITBUCKET_BRANCH`
6585
* fallback name (dependent on CI provider)
6686
* Gitlab - `CI_ENVIRONMENT_SLUG`
67-
* Other - `master`
6887
* `master`
6988
* `default` (must be set within `.firebaserc`)
7089

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

7998
## [Examples](/examples)
8099

81-
* [Basic](/examples/basic) - Basic html file upload to Firebase hosting of different projects (or "environments")
100+
Examples are the same basic html file upload to Firebase hosting of different projects (or "environments") for different CI providers:
101+
102+
* [Travis](/examples/travis)
103+
* [Github Actions](/examples/github-actions)
82104

83105
## Why?
84106

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

150+
### setEnv
151+
152+
Expose environment variables to CI based on current branch.
153+
154+
With a `.firebaserc` that looks like so:
155+
156+
```yaml
157+
"ci": {
158+
"setEnv": {
159+
"master": {
160+
"SOME_VAR": "some value"
161+
"REACT_APP_ENV_VARIABLE": "val passed to react app"
162+
},
163+
"prod": {
164+
"SOME_VAR": "some other value"
165+
"REACT_APP_ENV_VARIABLE": "val passed to react app"
166+
}
167+
}
168+
}
169+
```
170+
171+
`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"`
172+
128173
### createConfig
129174

175+
**DEPRECATED**
176+
130177
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.
131178

132179
With the following environment variables:

bin/firebase-ci

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ program.version(pkg.version)
88

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

11-
program.on('*', function(name) {
11+
program.on('*', function (name) {
1212
/* eslint-disable no-console */
1313
console.log(
1414
"'" + name + "' is not a known command. See 'firebase-ci --help':"

cmds/branch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const getBranch = require('../lib/utils/ci').getBranch
99
* echo "Project to deploy to $(firebase-ci project)"
1010
* // => "Project to deploy to my-project"
1111
*/
12-
module.exports = function(program) {
12+
module.exports = function (program) {
1313
program
1414
.command('branch')
1515
.description(

cmds/copyVersion.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const copyVersion = require('../lib/actions/copyVersion').default
1717
* - npm i -g firebase-ci
1818
* - firebase-ci copyVersion
1919
*/
20-
module.exports = function(program) {
20+
module.exports = function (program) {
2121
program
2222
.command('copyVersion')
2323
.description('Copy version from outer folder into functions folder')

cmds/createConfig.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,11 @@
55
const createConfig = require('../lib/actions/createConfig').default
66

77
/**
8-
* @name deploy
9-
* @description Deploy to Firebase only on build branches (master, stage, prod)
8+
* @name createConfig
9+
* @description Create src/config.js file (planned to be deprecated)
1010
* @param {object} program - Commander program object
11-
* @example <caption>Basic</caption>
12-
* # make sure FIREBASE_TOKEN env variable is set
13-
* npm i -g firebase-ci
14-
* firebase-ci deploy
15-
* @example <caption>Travis</caption>
16-
* after_success:
17-
* - npm i -g firebase-ci
18-
* - firebase-ci deploy
1911
*/
20-
module.exports = function(program) {
12+
module.exports = function (program) {
2113
program
2214
.command('createConfig')
2315
.description(

cmds/deploy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const deployToFirebase = require('../lib/actions/deploy').default
1212
* # make sure FIREBASE_TOKEN env variable is set
1313
* firebase-ci deploy
1414
*/
15-
module.exports = function(program) {
15+
module.exports = function (program) {
1616
program
1717
.command('deploy')
1818
.description(
@@ -34,7 +34,7 @@ module.exports = function(program) {
3434
)
3535
.option('-s --simple', 'Skip CI actions, and only run deployment')
3636
// .option('-a --actions <actions>', 'Only run certain CI actions (e.g "mapEnv", "createConfig")', /^(mapEnv|createConfig|copyVersion)$/i)
37-
.action(opts => {
37+
.action((opts) => {
3838
return deployToFirebase(opts)
3939
.then(() => process.exit(0))
4040
.catch(() => process.exit(1))

cmds/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module.exports = function (client) {
44
process.env.FORCE_COLOR = true
5-
var loadCommand = function (name) {
5+
const loadCommand = function (name) {
66
return require('./' + name)(client)
77
}
88

cmds/mapEnv.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const mapEnv = require('../lib/actions/mapEnv').default
1212
* # make sure you set mapEnv settings in .firebaserc
1313
* firebase-ci mapEnv
1414
*/
15-
module.exports = function(program) {
15+
module.exports = function (program) {
1616
program
1717
.command('mapEnv')
1818
.description('Copy version from outer folder into functions folder')

cmds/project.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const getProjectName = require('../lib/utils/ci').getProjectName
99
* echo "Project to deploy to $(firebase-ci project)"
1010
* // => "Project to deploy to my-project"
1111
*/
12-
module.exports = function(program) {
12+
module.exports = function (program) {
1313
program
1414
.command('project')
1515
.description('Get name of project associated with current CI environment')

cmds/projectId.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const getProjectId = require('../lib/utils/ci').getProjectId
99
* echo "Project to deploy to $(firebase-ci project)"
1010
* // => "Project to deploy to my-project"
1111
*/
12-
module.exports = function(program) {
12+
module.exports = function (program) {
1313
program
1414
.command('projectId')
1515
.description('Get projectId of associated with current CI environment')

cmds/run.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const runActions = require('../lib/actions/deploy').runActions
1212
* # make sure FIREBASE_TOKEN env variable is set
1313
* firebase-ci deploy
1414
*/
15-
module.exports = function(program) {
15+
module.exports = function (program) {
1616
program
1717
.command('run')
1818
.description(

cmds/serve.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const serve = require('../lib/actions/serve').default
1212
* # make sure FIREBASE_TOKEN env variable is set
1313
* firebase-ci deploy
1414
*/
15-
module.exports = function(program) {
15+
module.exports = function (program) {
1616
program
1717
.command('serve')
1818
.description(
@@ -23,7 +23,7 @@ module.exports = function(program) {
2323
'-o --only <targets>',
2424
'Only serve specified targets, comma-seperated (e.g "hosting, storage")'
2525
)
26-
.action(opts => {
26+
.action((opts) => {
2727
return serve(opts)
2828
.then(() => process.exit(0))
2929
.catch(() => process.exit(1))

examples/basic/.firebaserc

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)