Skip to content

Commit

Permalink
Merge pull request vZome#904 from vorth/quick-workflow
Browse files Browse the repository at this point in the history
Redesigned the online workflow automation
  • Loading branch information
vorth authored Jul 22, 2024
2 parents 9719532 + 6755939 commit d30852c
Show file tree
Hide file tree
Showing 12 changed files with 253 additions and 140 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/jsweet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ jobs:
- name: Build with Gradle and JSweet
run: |
pwd
chmod +x gradlew cicd/jsweet-legacy-code.bash
cicd/jsweet-legacy-code.bash
chmod +x gradlew cicd/online.bash
cicd/online.bash jsweet
- name: Archive Generated JS
uses: actions/upload-artifact@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/online.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Build with Gradle and Yarn
run: |
chmod +x gradlew cicd/build-online.bash
cicd/build-online.bash
chmod +x gradlew cicd/online.bash
cicd/online.bash prod
- name: Configure SSH
run: |
Expand Down
61 changes: 0 additions & 61 deletions cicd/build-online.bash

This file was deleted.

26 changes: 8 additions & 18 deletions cicd/jsweet-legacy-code.bash
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
#!/bin/bash

banner() {
echo ''
echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
echo '%%%% '$1
echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
echo ''
}
if [ -z ${REVISION+x} ]; then
echo "This script is not meant to run as a top-level entry point. Use online.bash."
exit 1
fi

# This is designed to run from the main repo as a working directory.
# From the command line there, run "cicd/jsweet-legacy-code.bash".
verifyJava


rm -rf online/node_modules online/.jsweet
# removing online/node_modules/@types because the JSweet TSC doesn't like Three.d.ts
rm -rf online/.jsweet online/jsweetOut online/node_modules/@types

banner 'Transpiling core Java sources with JSweet' ######################################

./gradlew --continue -p online coreClean core &> core-errors.txt # ignore the exit code, it always fails
./gradlew --continue --info -p online coreClean core &> core-errors.txt # ignore the exit code, it always fails
cat core-errors.txt

grep -q 'transpilation failed with 33 error(s) and 0 warning(s)' core-errors.txt \
&& banner 'JSweet core transpile found the expected errors' \
|| { banner 'UNEXPECTED CHANGE IN JSWEET CORE ERRORS'; exit 1; }


LEGACY=online/src/worker/legacy
CANDIES_IN=online/jsweetOut/core/candies
CANDIES_OUT="$LEGACY/candies"

banner 'Patching up the j4ts bundle as an ES6 module' ######################################

# also, working around https://github.com/cincheo/jsweet/issues/740,
Expand Down
192 changes: 192 additions & 0 deletions cicd/online.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
#!/bin/bash

REVISION=${BUILD_NUMBER:-'DEV'}

LEGACY=online/src/worker/legacy
CANDIES_IN=online/jsweetOut/core/candies
CANDIES_OUT="$LEGACY/candies"

banner() {
echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
echo '%%%% '$1
echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
}

verifyJava(){
JAVA_VER=$(java -version 2>&1 | head -1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1)
echo "detected Java $JAVA_VER"
if [ "$JAVA_VER" -ne 11 ]; then
echo "This script requires JAVA_HOME to point at a Java 11 JDK."
exit 1
fi
}

clean() {
rm -rf jsweet-branches || exit $?
cd online

rm -rf src/worker/legacy/candies || exit $?
rm -rf src/worker/legacy/core-java.js || exit $?

rm -rf .jsweet || exit $?
rm -rf jsweetOut || exit $?
rm -rf dist || exit $?
rm -rf node_modules || exit $?
rm -rf serve/modules || exit $?
rm -rf serve/app/classic/resources || exit $?
}

marshallResources() {
banner 'Marshalling core and desktop resources'
# Remove the detritus of earlier builds (& dev server)
rm -rf serve/modules || exit $?
rm -rf serve/app/classic/resources || exit $?
# Marshall the resources from core and desktop
mkdir -p serve/app/classic/resources/com/vzome/core/exporters || exit $?
cp -R ../desktop/src/main/resources/* serve/app/classic/resources || exit $?
cp -R ../core/src/main/resources/com/vzome/core/exporters/* serve/app/classic/resources/com/vzome/core/exporters || exit $?
}

generateRevisionJs() {
banner 'Generating src/revision.js'
if [ -z ${1+x} ]; then
echo "export const REVISION=\"${REVISION}\";" > src/revision.js
echo "export const importLegacy = async () => import( './worker/legacy/dynamic.js' );" >> src/revision.js
echo "export const importZomic = async () => import( './worker/legacy/zomic/index.js' );" >> src/revision.js
else
echo "export const REVISION=\"${1}\";" > src/revision.js
echo "export const importLegacy = async () => import( 'https://www.vzome.com/modules/vzome-legacy.js' );" >> src/revision.js
echo "export const importZomic = async () => import( 'https://www.vzome.com/modules/vzome-zomic.js' );" >> src/revision.js
fi

# index exporter resources
( cd serve/app/classic/resources
echo 'export const resourceIndex = ['
find com/vzome/core/exporters -type f -exec echo " \"{}\"", \;
echo ' ];' ) >> src/revision.js
}

installJsDependencies(){
banner 'Preparing the distribution folder with Yarn'
yarn install || exit $?
}

buildForProduction() {
installJsDependencies || exit $?

rm -rf dist || exit $?
yarn run build || exit $?

cd dist

banner 'Creating the online.tgz archive'
cp -R ../serve/app/* app && \
rm -rf app/test* && \
echo 'Header always set Access-Control-Allow-Origin "*"' > modules/.htaccess && \
echo ${REVISION} > modules/revision.txt && \
tar czvf online.tgz app modules
}

prepareJSweet(){
source cicd/prepare-jsweet.bash || exit $?
}

jsweet(){
source cicd/jsweet-legacy-code.bash || exit $?
}

devJava(){
jsweet || exit $?

cd online

marshallResources || exit $?

generateRevisionJs || exit $?

installJsDependencies || exit $?

yarn run dev
}

devJs(){
cd online

marshallResources || exit $?

generateRevisionJs || exit $?

installJsDependencies || exit $?

yarn run dev
}

devQuick(){
cd online

marshallResources || exit $?

generateRevisionJs 'QUICKSTART' || exit $?

installJsDependencies || exit $?

yarn run nolegacy
}

productionBuild(){
jsweet || exit $?

cd online

marshallResources || exit $?

generateRevisionJs || exit $?

buildForProduction || exit $?

banner 'finished building the vZome Online apps and web component'
}


case $1 in

quickstart)
devQuick
;;

dev)
devJs
;;

prepareJSweet)
prepareJSweet
;;

jsweet)
jsweet
;;

java)
devJava
;;

prod)
productionBuild
;;

clean)
clean
;;

*)
banner 'no command (quickstart|dev|java|prod) provided'
;;
esac


21 changes: 8 additions & 13 deletions online/prepare-jsweet.sh → cicd/prepare-jsweet.bash
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
#!/bin/bash

cd ..
if [ -z ${REVISION+x} ]; then
echo "This script is not meant to run as a top-level entry point."
exit 1
fi

verifyJava

rm -rf jsweet-branches
mkdir jsweet-branches
cd jsweet-branches

banner() {
echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
echo '%%%% '$1
echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
}

clone() {
banner "git clone vorth/$1"
git clone -b $2 https://github.com/vorth/$1 || exit $?
}

clone jsweet develop
clone jsweet-maven-plugin master
clone j4ts update-jsweet
clone j4ts master
clone jsweet-gradle-plugin update-jsweet

banner 'setting java 11 home'
export JAVA_HOME=`/usr/libexec/java_home -v 11` || exit $?

banner 'building JSweet'
cd jsweet/transpiler/ || exit $?
mvn clean install -Dmaven.test.skip=true -DskipJavadoc=true -DskipSigning=true || exit $?
Expand Down
Loading

0 comments on commit d30852c

Please sign in to comment.