Skip to content

build: move functions folder into tools/ #4127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"functions": {
"source": "tools/screenshot-test/functions"
},
"hosting": {
"public": "dist",
"rewrites": [
Expand Down
11 changes: 0 additions & 11 deletions functions/package.json

This file was deleted.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@
"dgeni": "^0.4.7",
"dgeni-packages": "^0.16.5",
"firebase": "^3.7.2",
"firebase-admin": "^4.1.2",
"firebase-functions": "^0.5.2",
"firebase-tools": "^2.2.1",
"firebase-admin": "~4.1.2",
"firebase-tools": "^3.6.1",
"fs-extra": "^2.0.0",
"glob": "^7.1.1",
"google-closure-compiler": "^20170218.0.0",
Expand Down
5 changes: 3 additions & 2 deletions tools/gulp/util/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const firebaseAdmin = require('firebase-admin');
const firebase = require('firebase');
const gcloud = require('google-cloud');

const config = require('../../../functions/config.json');
// Firebase configuration for the Screenshot project. Use the config from the screenshot functions.
const screenshotFirebaseConfig = require('../../screenshot-test/functions/config.json');

/** Opens a connection to the firebase realtime database. */
export function openFirebaseDashboardDatabase() {
Expand Down Expand Up @@ -51,6 +52,6 @@ export function decode(str: string): string {
* This connection is client side connection with no credentials
*/
export function connectFirebaseScreenshots() {
return firebase.initializeApp(config.firebase);
return firebase.initializeApp(screenshotFirebaseConfig.firebase);
}

File renamed without changes.
9 changes: 3 additions & 6 deletions tools/screenshot-test/functions/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ export function updateGithubStatus(event: firebaseFunctions.Event<any>) {
return;
}
let result = event.data.val() == true;
let prNumber = event.params.prNumber;
return setGithubStatus(event.params.sha,
{
let {prNumber, sha} = event.params;
return setGithubStatus(sha, {
result: result,
name: toolName,
description: `${toolName} ${result ? 'passed' : 'failed'}`,
url: `http://${authDomain}/${prNumber}`
},
repoSlug,
token);
}, repoSlug, token);
}
17 changes: 17 additions & 0 deletions tools/screenshot-test/functions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Entry point for the Firebase functions of the Screenshot tool. Firebase functions only support
* JavaScript files and therefore the TypeScript files needs to be transpiled. Using ts-node
* seems to be more elegant for now, because Firebase requires the `node_modules` to be copied
* to the output directory and when using TSC the `node_modules` won't be copied to the destination.
*/

'use strict';

const path = require('path');

// Enable TypeScript compilation at runtime using ts-node.
require('ts-node').register({
project: path.join(__dirname, 'tsconfig.json')
});

require('./screenshot-functions');
5 changes: 3 additions & 2 deletions tools/screenshot-test/functions/jwt-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const secret = firebaseFunctions.config().secret.key;
* Replace '/' with '.' to get the token.
*/
function getSecureToken(event: firebaseFunctions.Event<any>) {
return `${event.params.jwtHeader}.${event.params.jwtPayload}.${event.params.jwtSignature}`;
let {jwtHeader, jwtPayload, jwtSignature} = event.params;
return `${jwtHeader}.${jwtPayload}.${jwtSignature}`;
}

/**
Expand All @@ -22,7 +23,7 @@ function getSecureToken(event: firebaseFunctions.Event<any>) {
*/
export function verifySecureToken(event: firebaseFunctions.Event<any>) {
return new Promise((resolve, reject) => {
const prNumber = event.params.prNumber;
const prNumber = event.params['prNumber'];
const secureToken = getSecureToken(event);

return verifyJWT(secureToken, prNumber, secret, repoSlug).then(() => {
Expand Down
13 changes: 13 additions & 0 deletions tools/screenshot-test/functions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "material2-screenshot-functions",
"description": "Angular Material screenshot firebase functions",
"dependencies": {
"@google-cloud/storage": "^0.8.0",
"firebase-admin": "~4.1.3",
"firebase-functions": "^0.5.2",
"jsonwebtoken": "^7.3.0",
"request": "^2.81.0",
"typescript": "^2.2.2",
"ts-node": "^3.0.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {updateGithubStatus} from './github';
* The JWT has 3 parts: header, payload and signature. These three parts are joint by '/' in path.
*/

// Initailize the admin app
// Initialize the admin app
firebaseAdmin.initializeApp(firebaseFunctions.config().firebase);

/** The valid data types database accepts */
Expand Down
7 changes: 2 additions & 5 deletions tools/screenshot-test/functions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
{
"compilerOptions": {
"lib": ["es6", "es2016", "dom"],
"lib": ["es2015", "es2016", "dom"],
"module": "commonjs",
"moduleResolution": "node",
"noEmitOnError": true,
"noImplicitAny": true,
"sourceMap": true,
"target": "es5",
"baseUrl": "",
"outDir": "../../../functions/",
"typeRoots": [
"../../../functions/node_modules/@types/!(node)"
]
"outDir": "../../../dist/screenshot-functions/"
},
"files": [
"./index.ts"
Expand Down
5 changes: 1 addition & 4 deletions tools/screenshot-test/functions/util/jwt.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import * as jwt from 'jsonwebtoken';

export function verifyJWT(token: string,
prNumber: string,
secret: string,
repoSlug: string) {
export function verifyJWT(token: string, prNumber: string, secret: string, repoSlug: string) {
return new Promise((resolve, reject) => {
jwt.verify(token, secret, {issuer: 'Travis CI, GmbH'}, (err: any, payload: any) => {
if (err) {
Expand Down