Skip to content

Commit

Permalink
Implementing:
Browse files Browse the repository at this point in the history
1.- Making sure backward-compatibility of database restore
(#4050)

2.- Suggestions by Edwin Betancourt concerning which files are eligible
for launching a Github restore action
(#3972 (comment))
  • Loading branch information
marcalwestf committed Jan 24, 2023
1 parent 0da7739 commit 436dc9c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 37 deletions.
13 changes: 9 additions & 4 deletions .github/actions/adempiere-build/action.yml
@@ -1,15 +1,16 @@
name: 'ADempiere Build'
description: 'ADempiere is built and installed. Database seed is generated only if a nigration xml file was modified'
description: 'ADempiere is built and installed. Database seed is generated only if a migration xml file was modified'
author: 'Mario Calderon, marcalwestf'
inputs:
nodbrestore: # id of input
description: 'true-> no restore of DB; false-> DB will be restored'
nodbrestore: # input parameter ID
description: 'Value of nodbrestore==true -> no restore of DB. Value of nodbrestore==false-> DB will be restored'
required: true
default: "true"
runs:
using: "composite"
steps:
- run: |
echo "Start from action adempiere-build/action.yml"
echo $ACTION_BUILD_DIR
echo $GITHUB_REF
echo $GITHUB_HEAD_REF
Expand All @@ -27,7 +28,11 @@ runs:
echo $(ant -version)name: Build, install and restore
echo $ADEMPIERE_HOME
# ANT performs build & install. If parameter nodbrestore=false, it performs also a database restore.
echo "End from action adempiere-build/action.yml"
echo "Control gets over to $ADEMPIERE_HOME/build.xml"
echo "The call is: ant build -Dnodbrestore=${{ inputs.nodbrestore }}"
# ANT performs build & install.
# If parameter nodbrestore=false, it performs also a database restore; otherwise, the database restore is skipped.
ant build -Dnodbrestore=${{ inputs.nodbrestore }}
env:
ACTION_BUILD_DIR: ${{ github.action_path }}
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/main.yml
Expand Up @@ -19,14 +19,14 @@ jobs:
build-all:
# The type of runner that the job will run on
# For Linux, only Ubuntu is supported.
# Taking a specific version number to avoid side effects.
# Taking the last version.
runs-on: ubuntu-latest
# Service containers to run with `container-job`
services:
# Label used to access the service container
postgres:
# Docker Hub image
# Ubuntu lates with last version of postgresql
# Take the specific latest Postgres version that runs with latest Ubuntu version.
image: postgres:14.6
# Provide the password for postgres
env:
Expand Down Expand Up @@ -67,13 +67,17 @@ jobs:
echo "Installing Tomcat version 9 FINISHED"
# Filter files to discern whether to run with or without database restore
# Restore due when following files are modified: migration xml files, Github action files and utils scripts.
- name: Discern which files changed ...
uses: dorny/paths-filter@v2
id: changed-files
with:
filters: |
xml-files:
- 'migration/**/*.xml'
- '.github/workflows/*.yml'
- 'build.xml'
- 'utils/RUN*.*'
# Build ADempiere with ant, if there are changes in XML files
- name: Build Adempiere with database restore...
Expand Down
37 changes: 11 additions & 26 deletions build.xml
Expand Up @@ -53,7 +53,7 @@
</target>

<target name="silent-setup" description="Step 3: Run SilentSetup">
<echo message="Install ADempiere"/>
<echo message="Install ADempiere with SilentSetup start"/>
<java dir="${env.ADEMPIERE_HOME}" classname="org.compiere.install.SilentSetup" fork="true">
<arg value="ALL"/>
<jvmarg value="--add-opens"/>
Expand All @@ -72,7 +72,7 @@
<pathelement path="${java.class.path}"/>
</classpath>
</java>
<echo message="Install ADempiere finished"/>
<echo message="Install ADempiere with SilentSetup finished"/>
<tstamp>
<format property="current.time" pattern="dd/MM/yyyy hh:mm:ss"/>
</tstamp>
Expand All @@ -83,49 +83,34 @@
<antcall target="import-database-seed"/>
</target>

<!-- For the last ANT targets the following is valid: -->
<!-- Target will be executed if called as follows: -Dnodbrestore=false or without parameter -->
<!-- Target will not be executed if called as follows: -Dnodbrestore=true -->
<target name="import-database-seed" description="Step 4: Run Import ADempiere: import seed" unless="${nodbrestore}">
<echo message="Run Import ADempiere"/>
<echo message="Restore last ADempiere seed with RUN_ImportAdempiere.sh start"/>
<exec dir="${env_directory}" executable="/bin/bash" failonerror="true">
<arg value="${RUN_ImportAdempiere}"/>
</exec>
<echo message="Import seed finished"/>
<!-- <antcall target="restore-database-seed"/> Skip Restore because database was already restored -->
<echo message="Restore last ADempiere seed with RUN_ImportAdempiere.sh finished"/>
<!-- If this target is not executed, the next ANT call is also not executed -->
<antcall target="import-xml-files"/>
</target>

<!-- Target will be executed if called as follows: -Dnodbrestore=false or without parameter -->
<!-- Target will NOT be executed if called as follows: -Dnodbrestore=true -->
<!-- Skip Restore because database was already restored
<target name="restore-database-seed" description="Step 5: Run DB Restore ADempiere: restore seed" unless="${nodbrestore}">
<echo message="Run DB Restore ADempiere"/>
<exec dir="${env_directory}" executable="/bin/bash" failonerror="true">
<arg value="${RUN_DBRestore}"/>
</exec>
<echo message="Restore seed finished"/>
<antcall target="import-xml-files"/>
</target>
-->

<!-- Target will be executed if called as follows: -Dnodbrestore=false or without parameter -->
<!-- Target will not be executed if called as follows: -Dnodbrestore=true -->
<target name="import-xml-files" description="Step 5: Run Migrate XML: load and apply all migration xml files" unless="${nodbrestore}">
<echo message="Run Migrate XML"/>
<echo message="Execute XML migration files with RUN_MigrateXML start"/>
<exec dir="${AD_directory}" executable="/bin/bash" failonerror="true">
<arg value="${RUN_MigrateXML}"/>
</exec>
<echo message="Run Migrate XML finished"/>
<echo message="Execute XML migration files with RUN_MigrateXML finished"/>
<!-- If this target is not executed, the next ANT call is also not executed -->
<antcall target="export-database"/>
</target>

<!-- Target will be executed if called as follows: -Dnodbrestore=false or without parameter -->
<!-- Target will not be executed if called as follows: -Dnodbrestore=true -->
<target name="export-database" description="Step 6: Export restored and migrated database" unless="${nodbrestore}">
<echo message="Run Export Database"/>
<echo message="Export new Database seed with RUN_ExportReference start"/>
<exec dir="${env_directory}" executable="/bin/bash" failonerror="true">
<arg value="${RUN_ExportReference}"/>
</exec>
<echo message="Run Export Database finished"/>
<echo message="Export new Database seed with RUN_ExportReference finished"/>
</target>
</project>
6 changes: 3 additions & 3 deletions utils/PostgreSQL/DBRestore.sh
Expand Up @@ -2,7 +2,7 @@

echo ADempiere Database Import

echo Importing ADempiere DB from $ADEMPIERE_HOME/data/Adempiere_pg.dmp
echo Importing ADempiere DB from $ADEMPIERE_HOME/data/ExpDat.dmp

if [ $# -le 2 ]
then
Expand Down Expand Up @@ -42,9 +42,9 @@ echo -------------------------------------
echo Import Adempiere_pg.dmp
echo -------------------------------------
psql -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -d $ADEMPIERE_DB_NAME -U $2 -c "drop schema sqlj cascade"
ADEMPIERE_ALTER_ROLE_SQL="ALTER ROLE $2 SET search_path TO adempiere, pg_catalog"
ADEMPIERE_ALTER_ROLE_SQL="ALTER ROLE $2 SET search_path TO $ADEMPIERE_DB_NAME, pg_catalog"
psql -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -d $ADEMPIERE_DB_NAME -U $2 -c "$ADEMPIERE_ALTER_ROLE_SQL"
psql -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -d $ADEMPIERE_DB_NAME -U $2 -f $ADEMPIERE_HOME/data/Adempiere_pg.dmp
psql -h $ADEMPIERE_DB_SERVER -p $ADEMPIERE_DB_PORT -d $ADEMPIERE_DB_NAME -U $2 -f $ADEMPIERE_HOME/data/ExpDat.dmp

PGPASSWORD=
export PGPASSWORD
4 changes: 2 additions & 2 deletions utils/RUN_DBRestore.sh
Expand Up @@ -8,9 +8,9 @@ fi
echo Restore Adempiere Database from Export- $ADEMPIERE_HOME \($ADEMPIERE_DB_NAME\)


echo Re-Create Adempiere User and import $ADEMPIERE_HOME/data/Adempiere_pg.dmp
echo Re-Create Adempiere User and import $ADEMPIERE_HOME/data/ExpDat.dmp
echo == The import will show warnings. This is OK ==
ls -lsa $ADEMPIERE_HOME/data/Adempiere_pg.dmp
ls -lsa $ADEMPIERE_HOME/data/ExpDat.dmp
echo Press enter to continue ...
read in

Expand Down

0 comments on commit 436dc9c

Please sign in to comment.