From 12bc2e5dd153aa45c395c307ac0d129dab3ecd8a Mon Sep 17 00:00:00 2001 From: hiranya911 Date: Tue, 17 Mar 2020 16:11:02 -0700 Subject: [PATCH 1/2] chore: Cleaning up package verification scripts --- .../scripts/verify_package.sh | 40 ++-- .github/workflows/release.yml | 3 +- createReleaseTarball.sh | 178 ------------------ test/integration/typescript/package.json | 9 +- 4 files changed, 24 insertions(+), 206 deletions(-) rename verifyReleaseTarball.sh => .github/scripts/verify_package.sh (66%) delete mode 100755 createReleaseTarball.sh diff --git a/verifyReleaseTarball.sh b/.github/scripts/verify_package.sh similarity index 66% rename from verifyReleaseTarball.sh rename to .github/scripts/verify_package.sh index 4f56a5ec3a..f3160e1b5f 100755 --- a/verifyReleaseTarball.sh +++ b/.github/scripts/verify_package.sh @@ -21,55 +21,53 @@ # applications. set -e +set -u if [ -z "$1" ]; then echo "[ERROR] No package name provided." - echo "[INFO] Usage: ./verifyReleaseTarball.sh " + echo "[INFO] Usage: ./verify_package.sh " exit 1 fi -# Variables PKG_NAME="$1" -ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -MOCHA_CLI="$ROOT/node_modules/.bin/mocha -r ts-node/register" -DIR="$ROOT/test/integration/typescript" -WORK_DIR=`mktemp -d` - -if [ ! -f "$ROOT/$PKG_NAME" ]; then - echo "Package $PKG_NAME does not exist." +if [ ! -f "${PKG_NAME}" ]; then + echo "Package ${PKG_NAME} does not exist." exit 1 fi -# check if tmp dir was created -if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then +# create a temporary directory +WORK_DIR=`mktemp -d` +if [[ ! "${WORK_DIR}" || ! -d "${WORK_DIR}" ]]; then echo "Could not create temp dir" exit 1 fi # deletes the temp directory -function cleanup { - rm -rf "$WORK_DIR" - echo "Deleted temp working directory $WORK_DIR" +function cleanup { + rm -rf "${WORK_DIR}" + echo "Deleted temp working directory ${WORK_DIR}" } # register the cleanup function to be called on the EXIT signal trap cleanup EXIT -# Enter work dir -pushd "$WORK_DIR" +# Copy package and test sources into working directory +cp "${PKG_NAME}" "${WORK_DIR}" +cp -r test/integration/typescript/* "${WORK_DIR}" +cp test/resources/mock.key.json "${WORK_DIR}" -# Copy test sources into working directory -cp -r $DIR/* . -cp "$ROOT/test/resources/mock.key.json" . +# Enter work dir +pushd "${WORK_DIR}" # Install the test package npm install # Install firebase-admin package -npm install -S "$ROOT/$PKG_NAME" +npm install -S "${PKG_NAME}" echo "> tsc -p tsconfig.json" -$ROOT/node_modules/.bin/tsc -p tsconfig.json +./node_modules/.bin/tsc -p tsconfig.json +MOCHA_CLI="./node_modules/.bin/mocha -r ts-node/register" echo "> $MOCHA_CLI src/*.test.ts" $MOCHA_CLI src/*.test.ts \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1100ddb45e..24da56e189 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -78,11 +78,10 @@ jobs: name: dist path: dist - # TODO: Move this script to .github/scripts. - name: Verify tarball run: | PACKAGE_TARBALL=`ls firebase-admin-*.tgz` - ./verifyReleaseTarball.sh $PACKAGE_TARBALL + ./.github/scripts/verify_package.sh $PACKAGE_TARBALL publish_release: needs: stage_release diff --git a/createReleaseTarball.sh b/createReleaseTarball.sh deleted file mode 100755 index 9ca9fa5c6a..0000000000 --- a/createReleaseTarball.sh +++ /dev/null @@ -1,178 +0,0 @@ -# Copyright 2017 Google Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -#!/bin/bash - -# Helper function to print the usage instructions. -printUsage () { - echo "[INFO] Usage: $0 " - echo "[INFO] is the version number of the tarball you want to create." -} - - -############## -# PROLOGUE # -############## - -echo "[INFO] This script only affects your local repo and can be used at any time during development or release." -echo - -# Print usage instructions if the first argument is -h or --help. -if [[ $1 == "-h" || $1 == "--help" ]]; then - printUsage - exit 1 -fi - -VERSION=$1 -VERSION_WITHOUT_RC=${VERSION%-*} - - -############################# -# VALIDATE VERSION NUMBER # -############################# -if [[ -z $VERSION ]]; then - echo "[ERROR] Version number not provided." - echo - printUsage - exit 1 -elif ! [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-]+)?$ ]]; then - echo "[ERROR] Version number (${VERSION}) must be a valid SemVer number." - echo - printUsage - exit 1 -fi - - -################### -# VALIDATE REPO # -################### -# Ensure the checked out branch is master. -CHECKED_OUT_BRANCH="$(git branch | grep "*" | awk -F ' ' '{print $2}')" -if [[ $CHECKED_OUT_BRANCH != "master" ]]; then - read -p "[WARNING] You are on the '${CHECKED_OUT_BRANCH}' branch, not 'master'. Continue? (y/N) " CONTINUE - echo - - if ! [[ $CONTINUE == "y" || $CONTINUE == "Y" ]]; then - echo "[INFO] You chose not to continue." - exit 1 - fi -fi - -# Make sure the master branch does not have existing changes. -if ! git --git-dir=".git" diff --quiet; then - read -p "[WARNING] You have uncommitted changes on the current branch. Continue? (y/N) " CONTINUE - echo - - if ! [[ $CONTINUE == "y" || $CONTINUE == "Y" ]]; then - echo "[INFO] You chose not to continue." - exit 1 - fi -fi - - -######################### -# UPDATE package.json # -######################### -echo "[INFO] Updating version number in package.json to ${VERSION_WITHOUT_RC}..." -sed -i '' -e s/"\"version\": \".*\""/"\"version\": \"${VERSION_WITHOUT_RC}\""/ package.json -echo - - -############################ -# REINSTALL DEPENDENCIES # -############################ -echo "[INFO] Removing lib/, and node_modules/..." -rm -rf lib/ node_modules/ -if [[ $? -ne 0 ]]; then - echo "Error: Failed to remove lib/, and node_modules/." - exit 1 -fi -echo - -echo "[INFO] Installing production node modules..." -npm install --production -if [[ $? -ne 0 ]]; then - echo "Error: Failed to install production node modules." - exit 1 -fi -echo - - -############################ -# CREATE RELEASE TARBALL # -############################ -echo "[INFO] Installing and building all node modules..." -npm install -if [[ $? -ne 0 ]]; then - echo "Error: Failed to install all node modules." - exit 1 -fi -echo - -echo "[INFO] Running linter..." -npm run lint -if [[ $? -ne 0 ]]; then - echo "Error: Linter failed." - exit 1 -fi -echo - -echo "[INFO] Running unit tests..." -npm run test:unit -if [[ $? -ne 0 ]]; then - echo "Error: Unit tests failed." - exit 1 -fi -echo - -echo "[INFO] Running integration tests..." -npm run test:integration -- --updateRules --testMultiTenancy -if [[ $? -ne 0 ]]; then - echo "Error: Integration tests failed." - exit 1 -fi -echo - -echo "[INFO] Packaging up release tarball..." -npm pack -if [[ $? -ne 0 ]]; then - echo "Error: Failed to package up release tarball." - exit 1 -fi -echo - -# Since npm pack uses the version number in the package.json when creating the tarball, -# rename the tarball to include the RC version. -mv firebase-admin-${VERSION_WITHOUT_RC}.tgz firebase-admin-${VERSION}.tgz - - -############################ -# VERIFY RELEASE TARBALL # -############################ -echo "[INFO] Running release tarball verification..." -bash verifyReleaseTarball.sh firebase-admin-${VERSION}.tgz -if [[ $? -ne 0 ]]; then - echo "Error: Release tarball failed verification." - exit 1 -fi -echo - - -############## -# EPILOGUE # -############## - -echo "[INFO] firebase-admin-${VERSION}.tgz successfully created!" -echo "[INFO] Create a CL for the updated package.json if this is an actual release." -echo diff --git a/test/integration/typescript/package.json b/test/integration/typescript/package.json index 85395e6792..cc637618d3 100644 --- a/test/integration/typescript/package.json +++ b/test/integration/typescript/package.json @@ -2,13 +2,12 @@ "name": "firebase-admin-typescript-test", "version": "1.0.0", "devDependencies": { - "@types/google-cloud__storage": "^1.1.1", "@types/chai": "^3.4.35", - "@types/mocha": "^2.2.39", - "@types/node": "^7.0.8", + "@types/mocha": "^2.2.48", + "@types/node": "^8.10.59", "chai": "^3.5.0", - "mocha": "^3.5.0", + "mocha": "^5.2.0", "ts-node": "^3.3.0", - "typescript": "^2.4.2" + "typescript": "^3.7.3" } } \ No newline at end of file From b59cd0b324128b1a4ac2b3f6d5d824d270a4e091 Mon Sep 17 00:00:00 2001 From: hiranya911 Date: Tue, 17 Mar 2020 16:28:30 -0700 Subject: [PATCH 2/2] Added package metadata to test package.json file --- .github/scripts/verify_package.sh | 2 +- test/integration/typescript/package.json | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/scripts/verify_package.sh b/.github/scripts/verify_package.sh index f3160e1b5f..f8c37b4db0 100755 --- a/.github/scripts/verify_package.sh +++ b/.github/scripts/verify_package.sh @@ -70,4 +70,4 @@ echo "> tsc -p tsconfig.json" MOCHA_CLI="./node_modules/.bin/mocha -r ts-node/register" echo "> $MOCHA_CLI src/*.test.ts" -$MOCHA_CLI src/*.test.ts \ No newline at end of file +$MOCHA_CLI src/*.test.ts diff --git a/test/integration/typescript/package.json b/test/integration/typescript/package.json index cc637618d3..8f467c2a41 100644 --- a/test/integration/typescript/package.json +++ b/test/integration/typescript/package.json @@ -1,6 +1,12 @@ { "name": "firebase-admin-typescript-test", "version": "1.0.0", + "description": "Firebase Admin SDK post package test cases", + "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "https://github.com/firebase/firebase-admin-node" + }, "devDependencies": { "@types/chai": "^3.4.35", "@types/mocha": "^2.2.48", @@ -10,4 +16,4 @@ "ts-node": "^3.3.0", "typescript": "^3.7.3" } -} \ No newline at end of file +}