Skip to content

Commit

Permalink
Merge branch 'tc-management' into tc-addFirebase
Browse files Browse the repository at this point in the history
  • Loading branch information
TrCaM committed Aug 1, 2019
2 parents 29e23ff + 21a68c1 commit 20bc934
Show file tree
Hide file tree
Showing 27 changed files with 184 additions and 75 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
- TEST_NAME="Emulator End-to-End Tests"
before_script:
- echo "==== ${TEST_NAME} ===="
- ./scripts/decrypt-app-credentials.sh
script:
- ./scripts/test-triggers-end-to-end.sh
after_script: skip
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Introduce experimental support for browser clients to the Firestore emulator.
8 changes: 3 additions & 5 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
* Allow passing `GOOGLE_APPLICATION_CREDENTIALS` environment variable into the functions emulator.
* Set FIREBASE_DATABASE_EMULATOR_HOST in emulators:exec.
* Add new project management commands: `projects:create`, `projects:list`.
* Add new app management commands: `apps:create`, `apps:list`, `apps:sdkconfig`.
* Improve `init` command to be able to create a new project.
* Add new project management commands: `projects:create`, `projects:list`
* Add new app management commands: `apps:create`, `apps:list`, `apps:sdkconfig`, `apps:addfirebase
* Improve `init` command to be able to create a new project
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firebase-tools",
"version": "7.2.1",
"version": "7.2.2",
"description": "Command-Line Interface for Firebase",
"main": "./lib/index.js",
"bin": {
Expand Down
12 changes: 12 additions & 0 deletions scripts/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:8.16.0

# Install dependencies
RUN apt-get update && \
apt-get install -y curl git jq

# Install npm at 6.10.2.
RUN npm install --global npm@6.10.2

# Install hub
RUN curl -fsSL --output hub.tgz https://github.com/github/hub/releases/download/v2.11.2/hub-linux-amd64-2.11.2.tgz
RUN tar --strip-components=2 -C /usr/bin -xf hub.tgz hub-linux-amd64-2.11.2/bin/hub
4 changes: 4 additions & 0 deletions scripts/build/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
steps:
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/$PROJECT_ID/package-builder', '.']
images: ['gcr.io/$PROJECT_ID/package-builder']
44 changes: 25 additions & 19 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ set -e

printusage() {
echo "publish.sh <version>"
echo "REPOSITORY_ORG and REPOSITORY_NAME should be set in the environment."
echo "e.g. REPOSITORY_ORG=user, REPOSITORY_NAME=repo"
echo ""
echo "Arguments:"
echo " version: 'patch', 'minor', or 'major'."
Expand All @@ -17,16 +19,24 @@ elif [[ ! ($VERSION == "patch" || $VERSION == "minor" || $VERSION == "major") ]]
exit 1
fi

if [[ $REPOSITORY_ORG == "" ]]; then
printusage
exit 1
fi
if [[ $REPOSITORY_NAME == "" ]]; then
printusage
exit 1
fi

WDIR=$(pwd)

echo "Checking for commands..."
trap "echo 'Missing hub.'; exit 1" ERR
which hub &> /dev/null
trap - ERR

trap "echo 'Missing nvm.'; exit 1" ERR
file "${HOME}/.nvm/nvm.sh" &> /dev/null
source "${HOME}/.nvm/nvm.sh"
trap "echo 'Missing node.'; exit 1" ERR
which node &> /dev/null
trap - ERR

trap "echo 'Missing jq.'; exit 1" ERR
Expand All @@ -36,19 +46,15 @@ echo "Checked for commands."

echo "Checking for Twitter credentials..."
trap "echo 'Missing Twitter credentials.'; exit 1" ERR
test -f ${WDIR}/scripts/twitter.json
test -f "${WDIR}/scripts/twitter.json"
trap - ERR
echo "Checked for Twitter credentials..."

echo "Using node 8..."
nvm use 8
echo "Using node 8."

echo "Checking for logged-in user..."
echo "Checking for logged-in npm user..."
trap "echo 'Please login to npm using \`npm login --registry https://wombat-dressing-room.appspot.com\`'; exit 1" ERR
npm whoami --registry https://wombat-dressing-room.appspot.com
trap - ERR
echo "Checked for logged-in user."
echo "Checked for logged-in npm user."

echo "Moving to temporary directory.."
TEMPDIR=$(mktemp -d)
Expand All @@ -57,13 +63,13 @@ cd "${TEMPDIR}"
echo "Moved to temporary directory."

echo "Cloning repository..."
git clone git@github.com:firebase/firebase-tools.git
cd firebase-tools
git clone "git@github.com:${REPOSITORY_ORG}/${REPOSITORY_NAME}.git"
cd "${REPOSITORY_NAME}"
echo "Cloned repository."

echo "Making sure there is a changelog..."
if [ ! -s changelog.txt ]; then
echo "changelog.txt is empty. aborting."
if [ ! -s CHANGELOG.md ]; then
echo "CHANGELOG.md is empty. aborting."
exit 1
fi
echo "Made sure there is a changelog."
Expand All @@ -86,17 +92,17 @@ RELEASE_NOTES_FILE=$(mktemp)
echo "[DEBUG] ${RELEASE_NOTES_FILE}"
echo "v${NEW_VERSION}" >> "${RELEASE_NOTES_FILE}"
echo "" >> "${RELEASE_NOTES_FILE}"
cat changelog.txt >> "${RELEASE_NOTES_FILE}"
cat CHANGELOG.md >> "${RELEASE_NOTES_FILE}"
echo "Made the release notes."

echo "Publishing to npm..."
npm publish
echo "Published to npm."

echo "Cleaning up release notes..."
rm changelog.txt
touch changelog.txt
git commit -m "[firebase-release] Removed change log and reset repo after ${NEW_VERSION} release" changelog.txt
rm CHANGELOG.md
touch CHANGELOG.md
git commit -m "[firebase-release] Removed change log and reset repo after ${NEW_VERSION} release" CHANGELOG.md
echo "Cleaned up release notes."

echo "Pushing to GitHub..."
Expand All @@ -109,6 +115,6 @@ echo "Published release notes."

echo "Making the tweet..."
npm install --no-save twitter@1.7.1
cp ${WDIR}/scripts/twitter.json ${TEMPDIR}/firebase-tools/scripts/
cp -v "${WDIR}/scripts/twitter.json" "${TEMPDIR}/${REPOSITORY_NAME}/scripts/"
node ./scripts/tweet.js ${NEW_VERSION}
echo "Made the tweet."
1 change: 1 addition & 0 deletions scripts/publish/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
originals
76 changes: 76 additions & 0 deletions scripts/publish/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
steps:
# Decrypt the SSH key.
- name: 'gcr.io/cloud-builders/gcloud'
args: ['kms', 'decrypt', '--ciphertext-file=deploy_key.enc', '--plaintext-file=/root/.ssh/id_rsa', '--location=global', '--keyring=${_KEY_RING}', '--key=${_KEY_NAME}']

# Decrypt the Twitter credentials.
- name: 'gcr.io/cloud-builders/gcloud'
args: ['kms', 'decrypt', '--ciphertext-file=twitter.json.enc', '--plaintext-file=twitter.json', '--location=global', '--keyring=${_KEY_RING}', '--key=${_KEY_NAME}']

# Decrypt the npm credentials.
- name: 'gcr.io/cloud-builders/gcloud'
args: ['kms', 'decrypt', '--ciphertext-file=npmrc.enc', '--plaintext-file=npmrc', '--location=global', '--keyring=${_KEY_RING}', '--key=${_KEY_NAME}']

# Decrypt the hub (GitHub) credentials.
- name: 'gcr.io/cloud-builders/gcloud'
args: ['kms', 'decrypt', '--ciphertext-file=hub.enc', '--plaintext-file=hub', '--location=global', '--keyring=${_KEY_RING}', '--key=${_KEY_NAME}']

# Set up git with key and domain.
- name: 'gcr.io/cloud-builders/git'
entrypoint: 'bash'
args:
- '-c'
- |
chmod 600 /root/.ssh/id_rsa
cat <<EOF >/root/.ssh/config
Hostname github.com
IdentityFile /root/.ssh/id_rsa
EOF
ssh-keyscan github.com >> /root/.ssh/known_hosts
# Clone the repository.
- name: 'gcr.io/cloud-builders/git'
args: ['clone', 'git@github.com:${_REPOSITORY_ORG}/${_REPOSITORY_NAME}']

# Set up the Git configuration.
- name: 'gcr.io/cloud-builders/git'
dir: '${_REPOSITORY_NAME}'
args: ['config', '--global', 'user.email', 'firebase-oss-bot@google.com']
- name: 'gcr.io/cloud-builders/git'
dir: '${_REPOSITORY_NAME}'
args: ['config', '--global', 'user.name', 'Google Open Source Bot']

# Set up the Twitter credentials.
- name: 'gcr.io/$PROJECT_ID/package-builder'
entrypoint: 'cp'
args: ['-v', 'twitter.json', '${_REPOSITORY_NAME}/scripts/twitter.json']

# Set up the npm credentials.
- name: 'gcr.io/$PROJECT_ID/package-builder'
entrypoint: 'bash'
args: ['-c', 'cp -v npmrc ~/.npmrc']

# Set up the hub credentials.
- name: 'gcr.io/$PROJECT_ID/package-builder'
entrypoint: 'bash'
args: ['-c', 'mkdir -vp ~/.config && cp -v hub ~/.config/hub']

# Publish the package.
- name: 'gcr.io/$PROJECT_ID/package-builder'
dir: '${_REPOSITORY_NAME}'
args: ['bash', './scripts/publish.sh', '${_VERSION}']
env:
- 'REPOSITORY_ORG=${_REPOSITORY_ORG}'
- 'REPOSITORY_NAME=${_REPOSITORY_NAME}'

options:
volumes:
- name: 'ssh'
path: /root/.ssh

substitutions:
_VERSION: ''
_KEY_RING: 'cloud-build-ring'
_KEY_NAME: 'publish'
_REPOSITORY_ORG: 'firebase'
_REPOSITORY_NAME: 'firebase-tools'
Binary file added scripts/publish/deploy_key.enc
Binary file not shown.
Binary file added scripts/publish/hub.enc
Binary file not shown.
Binary file added scripts/publish/npmrc.enc
Binary file not shown.
Binary file added scripts/publish/twitter.json.enc
Binary file not shown.
18 changes: 18 additions & 0 deletions scripts/set-default-credentials.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -e

CWD="$(pwd)"

if [ "${TRAVIS}" != "true" ]; then
export TRAVIS_COMMIT="localtesting"
export TRAVIS_JOB_ID="$(echo $RANDOM)"
export TRAVIS_REPO_SLUG="firebase/firebase-tools"
fi

GOOGLE_APPLICATION_CREDENTIALS="${CWD}/scripts/creds-private.json"
if [ "${TRAVIS_REPO_SLUG}" == "firebase/firebase-tools" ]; then
GOOGLE_APPLICATION_CREDENTIALS="${CWD}/scripts/creds-public.json"
fi
export GOOGLE_APPLICATION_CREDENTIALS

echo "Application Default Credentials: ${GOOGLE_APPLICATION_CREDENTIALS}"
15 changes: 3 additions & 12 deletions scripts/test-hosting.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
#!/usr/bin/env bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
CWD="$(pwd)"

if [ "${TRAVIS}" != "true" ]; then
TRAVIS_COMMIT="localtesting"
TRAVIS_JOB_ID="$(echo $RANDOM)"
TRAVIS_REPO_SLUG="firebase/firebase-tools"
fi
source $DIR/set-default-credentials.sh

CWD="$(pwd)"
TARGET_FILE="${TRAVIS_COMMIT}-${TRAVIS_JOB_ID}.txt"

GOOGLE_APPLICATION_CREDENTIALS="${CWD}/scripts/creds-private.json"
if [ "${TRAVIS_REPO_SLUG}" == "firebase/firebase-tools" ]; then
GOOGLE_APPLICATION_CREDENTIALS="${CWD}/scripts/creds-public.json"
fi
export GOOGLE_APPLICATION_CREDENTIALS

echo "Running in ${CWD}"
echo "Running with node: $(which node)"
echo "Running with npm: $(which npm)"
Expand Down
4 changes: 3 additions & 1 deletion scripts/test-triggers-end-to-end.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash

set -xe
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

source $DIR/set-default-credentials.sh

FIREBASE_CLI="./lib/bin/firebase.js"

Expand Down
2 changes: 0 additions & 2 deletions src/commands/apps-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ module.exports = new Command("apps:create [platform] [displayName]")
const appPlatform = getAppPlatform(platform);
if (appPlatform === AppPlatform.ANY /* platform is not provided */) {
throw new FirebaseError("App platform must be provided");
} else if (appPlatform === AppPlatform.PLATFORM_UNSPECIFIED /* Unknown platform */) {
throw new FirebaseError("Unexpected platform. Only support iOS, Android and Web apps");
}

logger.info(`Create your ${appPlatform} app in project ${clc.bold(projectId)}:`);
Expand Down
4 changes: 0 additions & 4 deletions src/commands/apps-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ module.exports = new Command("apps:list [platform]")
const projectId = getProjectId(options);
const appPlatform = getAppPlatform(platform);

if (appPlatform === AppPlatform.PLATFORM_UNSPECIFIED) {
throw new FirebaseError("Unexpected platform. Only support iOS, Android and Web apps");
}

let apps;
const spinner = ora(
"Preparing the list of your Firebase " +
Expand Down
4 changes: 0 additions & 4 deletions src/commands/apps-sdkconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ module.exports = new Command("apps:sdkconfig [platform] [appId]")
async (platform: string = "", appId: string = "", options: any): Promise<any> => {
let appPlatform = getAppPlatform(platform);

if (appPlatform === AppPlatform.PLATFORM_UNSPECIFIED) {
throw new FirebaseError("Unexpected platform. Only support iOS, Android and Web apps.");
}

if (!appId) {
if (options.nonInteractive) {
throw new FirebaseError("App ID must not be empty.");
Expand Down
10 changes: 9 additions & 1 deletion src/commands/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,23 @@ module.exports = new Command("login")
return Promise.resolve(user);
}

utils.logBullet(
"Firebase optionally collects CLI usage and error reporting information to help improve our products. Data is collected in accordance with Google's privacy policy (https://policies.google.com/privacy) and is not used to identify you.\n"
);
return prompt(options, [
{
type: "confirm",
name: "collectUsage",
message: "Allow Firebase to collect anonymous CLI usage and error reporting information?",
message: "Allow Firebase to collect CLI usage and error reporting information?",
},
])
.then(function() {
configstore.set("usage", options.collectUsage);
if (options.collectUsage) {
utils.logBullet(
"To change your data collection preference at any time, run `firebase logout` and log in again."
);
}
return auth.login(options.localhost);
})
.then(function(result) {
Expand Down
6 changes: 3 additions & 3 deletions src/commands/mods-install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ async function installMod(options: InstallModOptions): Promise<void> {
const spec = source.spec;
const spinner = ora.default("Installing your mod instance. This usually takes 3 to 5 minutes...");
try {
await checkProjectBilling(projectId, spec.name, spec.billingRequired);
await checkProjectBilling(projectId, spec.displayName || spec.name, spec.billingRequired);
const roles = spec.roles ? spec.roles.map((role: modsApi.Role) => role.role) : [];
await askUserForConsent.prompt(spec.name, projectId, roles);
await askUserForConsent.prompt(spec.displayName || spec.name, projectId, roles);

const params = await paramHelper.getParams(projectId, _.get(spec, "params", []), paramFilePath);

Expand Down Expand Up @@ -78,7 +78,7 @@ async function installMod(options: InstallModOptions): Promise<void> {

utils.logLabeledSuccess(
logPrefix,
`successfully installed ${clc.bold(spec.name)}, ` +
`successfully installed ${clc.bold(spec.displayName || spec.name)}, ` +
`its Instance ID is ${clc.bold(instanceId)}.`
);
const usageInstruction =
Expand Down

0 comments on commit 20bc934

Please sign in to comment.