Skip to content

Commit

Permalink
readds files that shouldnt have been removed
Browse files Browse the repository at this point in the history
  • Loading branch information
joehan committed Aug 15, 2019
1 parent f67b2ef commit 4037e1b
Show file tree
Hide file tree
Showing 34 changed files with 1,606 additions and 0 deletions.
44 changes: 44 additions & 0 deletions scripts/assets/functions_to_test.js
@@ -0,0 +1,44 @@
var functions = require("firebase-functions");
var admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);

exports.dbAction = functions.database.ref("/input/{uuid}").onWrite(function(event) {
console.log("Received event:", event);
return event.data.ref.root.child("output/" + event.params.uuid).set(event.data.val());
});

exports.nested = {
dbAction: functions.database.ref("/inputNested/{uuid}").onWrite(function(event) {
console.log("Received event:", event);
return event.data.ref.root.child("output/" + event.params.uuid).set(event.data.val());
}),
};

exports.httpsAction = functions.https.onRequest(function(req, res) {
res.send(req.body);
});

exports.pubsubAction = functions.pubsub.topic("topic1").onPublish(function(event) {
console.log("Received event:", event);
var uuid = event.data.json;
return admin
.database()
.ref("output/" + uuid)
.set(uuid);
});

exports.gcsAction = functions.storage.object().onChange(function(event) {
console.log("Received event:", event);
var uuid = event.data.name;
return admin
.database()
.ref("output/" + uuid)
.set(uuid);
});

exports.pubsubScheduleAction = functions.pubsub
.schedule("every 10 minutes")
.onPublish(function(event) {
console.log("Received scheduled event:", event);
return true;
});
12 changes: 12 additions & 0 deletions scripts/build/Dockerfile
@@ -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
@@ -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']
4 changes: 4 additions & 0 deletions scripts/clean.ts
@@ -0,0 +1,4 @@
import { removeSync } from "fs-extra";
import { resolve } from "path";

removeSync(`${resolve(__dirname, "..", "lib")}`);
Binary file added scripts/creds-private.json.enc
Binary file not shown.
Binary file added scripts/creds-public.json.enc
Binary file not shown.
18 changes: 18 additions & 0 deletions scripts/decrypt-app-credentials.sh
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -e

openssl aes-256-cbc \
-K $encrypted_830857fa25dd_key \
-iv $encrypted_830857fa25dd_iv \
-in scripts/creds-public.json.enc \
-out scripts/creds-public.json \
-d || true

openssl aes-256-cbc \
-K $encrypted_830857fa25dd_key \
-iv $encrypted_830857fa25dd_iv \
-in scripts/creds-private.json.enc \
-out scripts/creds-private.json \
-d || true

test -f scripts/creds-public.json || test -f scripts/creds-private.json || (echo "No Credentials Decrypted" && false)
120 changes: 120 additions & 0 deletions scripts/publish.sh
@@ -0,0 +1,120 @@
#!/bin/bash
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'."
}

VERSION=$1
if [[ $VERSION == "" ]]; then
printusage
exit 1
elif [[ ! ($VERSION == "patch" || $VERSION == "minor" || $VERSION == "major") ]]; then
printusage
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 node.'; exit 1" ERR
which node &> /dev/null
trap - ERR

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

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

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 npm user."

echo "Moving to temporary directory.."
TEMPDIR=$(mktemp -d)
echo "[DEBUG] ${TEMPDIR}"
cd "${TEMPDIR}"
echo "Moved to temporary directory."

echo "Cloning repository..."
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.md ]; then
echo "CHANGELOG.md is empty. aborting."
exit 1
fi
echo "Made sure there is a changelog."

echo "Running npm install..."
npm install
echo "Ran npm install."

echo "Running tests..."
npm test
echo "Ran tests."

echo "Making a $VERSION version..."
npm version $VERSION
NEW_VERSION=$(jq -r ".version" package.json)
echo "Made a $VERSION version."

echo "Making the release notes..."
RELEASE_NOTES_FILE=$(mktemp)
echo "[DEBUG] ${RELEASE_NOTES_FILE}"
echo "v${NEW_VERSION}" >> "${RELEASE_NOTES_FILE}"
echo "" >> "${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.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..."
git push origin master --tags
echo "Pushed to GitHub."

echo "Publishing release notes..."
hub release create --file "${RELEASE_NOTES_FILE}" "v${NEW_VERSION}"
echo "Published release notes."

echo "Making the tweet..."
npm install --no-save twitter@1.7.1
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
@@ -0,0 +1 @@
originals
76 changes: 76 additions & 0 deletions scripts/publish/cloudbuild.yaml
@@ -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
@@ -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}"

0 comments on commit 4037e1b

Please sign in to comment.