Skip to content
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

Verify committed build files #12

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
78 changes: 78 additions & 0 deletions bin/pmc-test-asset-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash

set -e

echo -e "${GREEN}Starting $(basename ${BASH_SOURCE[0]})${RESET}"

pmc_run_npm_build() {
cwd=$(pwd)

# Find all the package.json files not in node_modules and store as an array
packagejsons=()
while IFS= read -r -d $'\0'; do
packagejsons+=("$REPLY")
done < <(find . -maxdepth 3 -type d -name "*node_modules*" -prune -o -name "package.json" -print0)

set -e
for i in "${packagejsons[@]}"
do
pushd $( dirname $i )
if [[ -f "package.json" ]]; then
pwd

if [[ ! -f ".nvmrc" ]]; then
echo "WARNING: No .nvmrc found for $PWD"
exit 1
fi

if [[ 0 != $(jq '.scripts.build|length' < package.json) || 0 != $(jq '.scripts.prod|length' < package.json) ]]; then
nvm install
npm config set unsafe-perm true
npm config set user 0
npm ci

if [[ 0 != $(jq '.scripts.build|length' < package.json) ]]; then
npm run build || { echo 'Build Failed'; exit 1; }
elif [ 0 != $(jq '.scripts.prod|length' < package.json) ]; then
npm run prod || { echo 'Build Failed'; exit 1; }
fi
fi
fi
popd
done

# Return to the original directory
cd $cwd;
}

. pmc-setup-colors
. pmc-setup-ssh
. pmc-setup-clone-dir
. pmc-setup-git-environment
. pmc-setup-pmc-plugins
. pmc-setup-bashrc
. pmc-setup-assets-dir
. pmc-functions
. pmc-test-functions
maybe_build_pmc_plugins_js_checklist

if [[ -n "${PMC_IS_PMC_PLUGINS}" ]]
then
if [[ -n "${PMC_PLUGINS_JS_CHECKLIST}" ]]
then
# Loop through and run the tests from within the directory of only changed
# Plugins. This way we can prevent having to setup a LOT of phpunit vars and
# potential errors
for i in "${PMC_PLUGINS_JS_CHECKLIST[@]}"
do
pushd ${i}
echo ""
echo -e "${LIGHT_BLUE}Verifying ${i}${RESET}"
pmc_run_npm_build
echo ""
popd
done
fi
else
pmc_run_npm_build
fi
5 changes: 2 additions & 3 deletions bin/pmc-test-npm
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ pmc_run_npmtest() {
exit 1
fi

nvm install
nvm use
if [[ $( npm run | grep 'test' ) ]]; then
if [[ 0 != $(jq '.scripts.test|length' < package.json) ]]; then
nvm install
npm config set unsafe-perm true
npm config set user 0
npm ci
Expand Down