Skip to content

Commit

Permalink
Fix boilerplate build
Browse files Browse the repository at this point in the history
  • Loading branch information
eliangcs committed Jan 29, 2020
1 parent 9db7768 commit 5d76f82
Show file tree
Hide file tree
Showing 15 changed files with 205 additions and 133 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,5 @@ typings/

example-apps/*/yarn.lock
example-apps/*/package-lock.json

boilerplate/build
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ before_install:
- npm install -g yarn
- pip install --user awscli
install:
# need to ignore engines until we can ditch node 8 after calendar 2019
- yarn install --ignore-engines
- yarn install
script:
- yarn validate
notifications:
Expand Down
5 changes: 5 additions & 0 deletions boilerplate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Zapier Platform Boilerplate

Boilerplate is an empty Zapier integration project. We use it to build a zip
providing all the necessary dependencies for integrations developed on visual
builder.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
"license": "UNLICENSED",
"main": "index.js",
"engines": {
"node": ">=8.10.0",
"node": ">=10",
"npm": ">=5.6.0"
},
"dependencies": {
"zapier-platform-core": "PLACEHOLDER",
"zapier-platform-legacy-scripting-runner": "PLACEHOLDER"
}
},
"private": true
}
136 changes: 136 additions & 0 deletions boilerplate/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/usr/bin/env bash
#
# Build with current local code:
# ./build.sh
#
# Specify core and legacy-scripting-runner versions to build with published
# packages on npm:
# ./build.sh 9.0.0 3.2.4

update_deps() {
package_json=$1
core_version=$2
legacy_version=$3

cmd_for_core="s|\"zapier-platform-core\": \"[^\"]*\""
cmd_for_core+="|\"zapier-platform-core\": \"$core_version\"|g"

cmd_for_legacy="s|\"zapier-platform-legacy-scripting-runner\": \"[^\"]*\""
cmd_for_legacy+="|\"zapier-platform-legacy-scripting-runner\": \"$legacy_version\"|g"

sed -i.bak "$cmd_for_core" "$package_json"
sed -i.bak "$cmd_for_legacy" "$package_json"

rm -f "$package_json.bak"
}

inspect_build() {
temp_dir="`dirname $1`/_temp"
unzip -q $1 -d $temp_dir
find $temp_dir/node_modules/zapier-platform-*/package.json | (xargs cat | jq '{name, version}')
echo 'deasync bindings:'
ls $temp_dir/node_modules/deasync/bin
rm -rf $temp_dir
}

# Get the absolute path of the directory holding this script file
SCRIPT_DIR=$(dirname $0)
pushd $SCRIPT_DIR > /dev/null
SCRIPT_DIR=$(pwd)
popd > /dev/null

REPO_DIR=$(dirname $(dirname $SCRIPT_DIR))
CORE_DIR="$REPO_DIR/packages/core"
LEGACY_DIR="$REPO_DIR/packages/legacy-scripting-runner"
BOILERPLATE_DIR="$REPO_DIR/boilerplate"

BUILD_DIR="$BOILERPLATE_DIR/build"

mkdir -p $BUILD_DIR

# Copy files
cp "$CORE_DIR/include/zapierwrapper.js" "$BOILERPLATE_DIR/"

# Get core version
if [ "$1" == "" ]; then
pushd $CORE_DIR > /dev/null
CORE_VERSION="$(node -p "require('./package.json').version")"
popd > /dev/null
else
CORE_VERSION=$1
fi

# Get legacy-scripting-runner version
if [ "$2" == "" ]; then
pushd $LEGACY_DIR > /dev/null
LEGACY_VERSION="$(node -p "require('./package.json').version")"
popd > /dev/null
else
LEGACY_VERSION=$2
fi

TARGET_FILE="$BUILD_DIR/$CORE_VERSION.zip"
rm -f $TARGET_FILE

# Patch boilerplate's package.json with appropriate dependency versions
if [ "$1" == "" ]; then
# Build core and legacy-scripting-runner locally. Needs to generate a unique filename
# with a timestamp to avoid yarn using cached packages.
# See https://github.com/yarnpkg/yarn/issues/2165.
TIMESTAMP=`date +"%s"`
echo "Building from local"

CORE_PACK_FILENAME="core-$TIMESTAMP.tgz"
LEGACY_PACK_FILENAME="legacy-$TIMESTAMP.tgz"

pushd $CORE_DIR > /dev/null
yarn pack --filename "$BOILERPLATE_DIR/$CORE_PACK_FILENAME"
popd > /dev/null

pushd $LEGACY_DIR > /dev/null
yarn pack --filename "$BOILERPLATE_DIR/$LEGACY_PACK_FILENAME"
popd > /dev/null

# Replace core and legacy-scripting-runner versions in package.json
update_deps "$BOILERPLATE_DIR/package.json" "./$CORE_PACK_FILENAME" "./$LEGACY_PACK_FILENAME"
else
echo "Building from published packages, core $CORE_VERSION"

update_deps "$BOILERPLATE_DIR/package.json" $CORE_VERSION $LEGACY_VERSION
fi

# Install boilerplate deps
pushd $BOILERPLATE_DIR > /dev/null
echo "{\"version\": \"1.0.0\", \"platformVersion\": \"$CORE_VERSION\"}" > definition.json
yarn --force --no-lockfile
popd > /dev/null

# Monkey patch boilerplate package.json so zapier-platform-core and
# zapier-platform-legacy-scripting-runner have version numbers specified instead
# of local file path
update_deps "$BOILERPLATE_DIR/package.json" $CORE_VERSION $LEGACY_VERSION

pushd $BOILERPLATE_DIR > /dev/null

# Build the zip!
# the node-X segment in the next line should match the latest major version
zip -R $TARGET_FILE '*.js' '*.json' '*/linux-x64-node-10/*.node'

# Remove generated files
rm -f zapierwrapper.js definition.json core-*.tgz legacy-*.tgz
# rm -rf node_modules

# Don't let yarn pile up useless caches of local packages.
# See https://github.com/yarnpkg/yarn/issues/6037.
yarn cache clean zapier-platform-core zapier-platform-schema zapier-platform-legacy-scripting-runner

popd > /dev/null

# Undo the monkey patch on boilerplate package.json
update_deps "$BOILERPLATE_DIR/package.json" PLACEHOLDER PLACEHOLDER

echo -e "\nDone! Here's your output zip file:"
ls -hl $TARGET_FILE

echo -e "\nInspecting what's inside the zip:"
inspect_build $TARGET_FILE
26 changes: 26 additions & 0 deletions boilerplate/scripts/upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
#
# Usage:
# ./upload.sh 9.0.0

if [ "$1" == "" ]; then
if [ -z $TRAVIS_TAG ]; then
(>&2 echo 'TRAVIS_TAG is undefined')
exit 1
fi
PKG_VERSION=`echo $TRAVIS_TAG | grep '@' | cut -d '@' -f 2`
else
PKG_VERSION=$1
fi

BUCKET='zapier-dev-platform-cli-boilerplates'

# Get the absolute path of the directory holding this script file
SCRIPT_DIR=$(dirname $0)
pushd $SCRIPT_DIR > /dev/null
SCRIPT_DIR=$(pwd)
popd > /dev/null

REPO_DIR=$(dirname $(dirname $SCRIPT_DIR))

/usr/local/bin/aws s3 cp $REPO_DIR/boilerplate/build/$PKG_VERSION.zip s3://$BUCKET/$PKG_VERSION.zip --acl public-read
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
"lint": "lerna run --stream --ignore zapier-platform-example-app-* lint",
"lint-examples": "eslint examples",
"validate": "lerna run --ignore zapier-platform-example-app-* validate",
"bump": "./scripts/bump.js",
"build-boilerplate": "yarn workspace zapier-platform-core build-boilerplate",
"upload-boilerplate": "yarn workspace zapier-platform-core upload-boilerplate"
"bump": "./scripts/bump.js"
},
"husky": {
"hooks": {
Expand Down
1 change: 1 addition & 0 deletions packages/boilerplate/definition.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "version": "1.0.0", "platformVersion": "9.0.0" }
6 changes: 6 additions & 0 deletions packages/boilerplate/zapierwrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// not intended to be loaded via require() - copied during build step
const path = require('path');
const zapier = require('zapier-platform-core');
const appPath = path.resolve(__dirname, 'index.js');
// don't `require(appPath)` out here
module.exports = { handler: zapier.createAppHandler(appPath) };
71 changes: 0 additions & 71 deletions packages/core/bin/build-boilerplate.sh

This file was deleted.

40 changes: 0 additions & 40 deletions packages/core/bin/update-boilerplate-dependencies.js

This file was deleted.

11 changes: 0 additions & 11 deletions packages/core/bin/upload-boilerplate.sh

This file was deleted.

3 changes: 0 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
"upload-integration-test": "bin/upload-lambda.js local.bundle.zip",
"deploy-integration-test":
"yarn build-integration-test && yarn upload-integration-test",
"build-boilerplate": "bin/build-boilerplate.sh",
"upload-boilerplate": "bin/upload-boilerplate.sh",
"postpublish": "bin/build-boilerplate.sh && bin/upload-boilerplate.sh",
"validate": "yarn test && yarn smoke-test && yarn lint"
},
"engines": {
Expand Down
25 changes: 24 additions & 1 deletion scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,28 @@ echo "$NPM_REGISTRY_NO_PROTO/:_authToken=\"$NPM_TOKEN\"" > $NPMRC_PATH

# cd to the package and publish it!
PKG_PATH=`yarn workspaces info -s | jq -r ".[\"$PKG_NAME\"].location"`
cd $PKG_PATH
pushd $PKG_PATH > /dev/null
npm publish --registry $NPM_REGISTRY
popd > /dev/null

# === BEGIN Boilerplate Rebuild ===

if [[ "$PKG_NAME" == "zapier-platform-core" ]]; then
LEGACY_VERSION=$(curl https://registry.npmjs.org/zapier-platform-legacy-scripting-runner/latest | jq -r .version)
CORE_VERSION=$(cat $PKG_PATH/package.json | jq -r .version)
fi

if [[ "$PKG_NAME" == "zapier-platform-legacy-scripting-runner" ]]; then
CORE_VERSION=$(curl https://registry.npmjs.org/zapier-platform-core/latest | jq -r .version)
LEGACY_VERSION=$(cat $PKG_PATH/package.json | jq -r .version)
fi

if [[ "$CORE_VERSION" != "" && "$LEGACY_VERSION" != "" ]]; then
# Build boilerplate and let Zapier know about this
./boilerplate/scripts/build.sh $CORE_VERSION $LEGACY_VERSION &&
./boilerplate/scripts/upload.sh $CORE_VERSION &&
ZIP_HASH=$(sha1sum "./boilerplate/build/$CORE_VERSION.zip" | awk '{print $1}') &&
curl -H 'content-type:application/json' -d "{\"version\":\"$CORE_VERSION\",\"id\":\"$ZIP_HASH\"}" $BOILERPLATE_UPDATE_URL | jq .status
fi

# === END Boilerplate Rebuild ===

0 comments on commit 5d76f82

Please sign in to comment.