|
| 1 | +name: 'Setup Environment' |
| 2 | +description: 'Sets up the environment for Frappe development' |
| 3 | +inputs: |
| 4 | + python-version: |
| 5 | + description: 'Python version to use' |
| 6 | + required: false |
| 7 | + default: '3.12.6' |
| 8 | + node-version: |
| 9 | + description: 'Node.js version to use' |
| 10 | + required: false |
| 11 | + default: '22' |
| 12 | + build-assets: |
| 13 | + required: false |
| 14 | + description: 'Wether to build assets' |
| 15 | + default: true |
| 16 | + enable-coverage: |
| 17 | + required: false |
| 18 | + default: false |
| 19 | + enable-watch: |
| 20 | + required: false |
| 21 | + default: false |
| 22 | + enable-schedule: |
| 23 | + required: false |
| 24 | + default: false |
| 25 | + disable-web: |
| 26 | + required: false |
| 27 | + default: false |
| 28 | + disable-socketio: |
| 29 | + required: false |
| 30 | + default: false |
| 31 | + db: |
| 32 | + required: false |
| 33 | + default: mariadb |
| 34 | + db-root-password: |
| 35 | + required: true |
| 36 | + |
| 37 | +runs: |
| 38 | + using: "composite" |
| 39 | + steps: |
| 40 | + - shell: bash -e {0} |
| 41 | + run: | |
| 42 | + # Add 'test_site' to /etc/hosts & setup git config |
| 43 | + echo "127.0.0.1 test_site" | sudo tee -a /etc/hosts |
| 44 | + git config --global init.defaultBranch main |
| 45 | + git config --global advice.detachedHead false |
| 46 | +
|
| 47 | + - name: Clone |
| 48 | + uses: actions/checkout@v4 |
| 49 | + with: |
| 50 | + path: apps/${{ github.event.repository.name }} |
| 51 | + |
| 52 | + - name: Setup Python |
| 53 | + uses: actions/setup-python@v5 |
| 54 | + with: |
| 55 | + python-version: ${{ inputs.python-version }} |
| 56 | + |
| 57 | + - shell: bash -e {0} |
| 58 | + run: | |
| 59 | + # Check for valid Python & Merge Conflicts |
| 60 | + python -m compileall -q -f "${GITHUB_WORKSPACE}/apps/${{ github.event.repository.name }}" |
| 61 | + if grep -lr --exclude-dir=node_modules "^<<<<<<< " "${GITHUB_WORKSPACE}/apps/${{ github.event.repository.name }}" |
| 62 | + then echo "Found merge conflicts" |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | +
|
| 66 | + - name: Checkout Frappe |
| 67 | + uses: actions/checkout@v4 |
| 68 | + with: |
| 69 | + repository: ${{ env.FRAPPE_GH_ORG || github.repository_owner }}/frappe |
| 70 | + ref: ${{ github.event.client_payload.frappe_sha || github.base_ref || github.ref_name }} |
| 71 | + path: apps/frappe |
| 72 | + if: github.event.repository.name != 'frappe' |
| 73 | + |
| 74 | + - uses: actions/setup-node@v4 |
| 75 | + with: |
| 76 | + node-version: ${{ inputs.node-version }} |
| 77 | + check-latest: true |
| 78 | + |
| 79 | + - name: Cache pip |
| 80 | + uses: actions/cache@v4 |
| 81 | + with: |
| 82 | + path: ~/.cache/pip |
| 83 | + key: ${{ runner.os }}-pip-${{ hashFiles('**/*requirements.txt', '**/pyproject.toml', '**/setup.py') }} |
| 84 | + restore-keys: | |
| 85 | + ${{ runner.os }}-pip- |
| 86 | + ${{ runner.os }}- |
| 87 | +
|
| 88 | + - id: yarn-cache-dir-path |
| 89 | + shell: bash -e {0} |
| 90 | + run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT |
| 91 | + - uses: actions/cache@v4 |
| 92 | + id: yarn-cache |
| 93 | + with: |
| 94 | + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} |
| 95 | + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} |
| 96 | + restore-keys: | |
| 97 | + ${{ runner.os }}-yarn- |
| 98 | +
|
| 99 | + - shell: bash -e {0} |
| 100 | + run: | |
| 101 | + # Install System Dependencies |
| 102 | + start_time=$(date +%s) |
| 103 | + curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version="mariadb-11.8.5" |
| 104 | +
|
| 105 | + sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' |
| 106 | + wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - |
| 107 | +
|
| 108 | + sudo apt -qq update |
| 109 | + sudo apt -qq remove mysql-server mysql-client |
| 110 | + sudo apt -qq remove -y postgresql-client postgresql-client-16 postgresql-client-common |
| 111 | + sudo apt -qq install libcups2-dev redis-server mariadb-client libmariadb-dev postgresql-client-18 libpq-dev |
| 112 | + echo "/usr/lib/postgresql/18/bin" >> $GITHUB_PATH |
| 113 | +
|
| 114 | + wget -q -O /tmp/wkhtmltox.deb https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb |
| 115 | + sudo apt install /tmp/wkhtmltox.deb |
| 116 | +
|
| 117 | + end_time=$(date +%s) |
| 118 | + echo -e "\033[33mInstall System Dependencies: $((end_time - start_time)) seconds\033[0m" |
| 119 | +
|
| 120 | + - shell: bash -e {0} |
| 121 | + env: |
| 122 | + DB: ${{ inputs.db }} |
| 123 | + run: | |
| 124 | + # Init Bench & test_site |
| 125 | + start_time=$(date +%s) |
| 126 | + mkdir ${GITHUB_WORKSPACE}/{sites,config,logs,config/pids,sites/test_site} |
| 127 | + python -m venv ${GITHUB_WORKSPACE}/env |
| 128 | + source ${GITHUB_WORKSPACE}/env/bin/activate |
| 129 | + pip install --quiet --upgrade pip |
| 130 | + pip cache remove mysqlclient |
| 131 | +
|
| 132 | + pip install --quiet frappe-bench |
| 133 | +
|
| 134 | + python <<EOF |
| 135 | + from bench.config.common_site_config import setup_config |
| 136 | + from bench.config.redis import generate_config |
| 137 | + from bench.config.procfile import setup_procfile |
| 138 | +
|
| 139 | + bench_path = "${{ github.workspace }}" |
| 140 | + is_true = lambda str: True if str == "true" else False |
| 141 | + is_not_true = lambda str: True if str != "true" else False |
| 142 | +
|
| 143 | + setup_config(bench_path) |
| 144 | + generate_config(bench_path) |
| 145 | + setup_procfile( |
| 146 | + bench_path, |
| 147 | + skip_redis=False, |
| 148 | + skip_web=is_true("${{ inputs.disable-web }}"), |
| 149 | + skip_watch=is_not_true("${{ inputs.enable-watch }}"), |
| 150 | + skip_socketio=is_true("${{ inputs.disable-socketio }}"), |
| 151 | + skip_schedule=is_not_true("${{ inputs.enable-schedule }}"), |
| 152 | + with_coverage=is_true("${{ inputs.enable-coverage }}"), |
| 153 | + ) |
| 154 | + EOF |
| 155 | + end_time=$(date +%s) |
| 156 | + echo -e "\033[33mInit Bench: $((end_time - start_time)) seconds\033[0m" |
| 157 | + cat ${GITHUB_WORKSPACE}/Procfile | awk '{print "\033[0;34m" $0 "\033[0m"}' |
| 158 | + # Attempt to copy the configuration file |
| 159 | + if cp "${GITHUB_WORKSPACE}/apps/${{ github.event.repository.name }}/.github/helper/db/$DB.json" ${GITHUB_WORKSPACE}/sites/test_site/site_config.json; then |
| 160 | + echo "Successfully copied ${DB}.json to site_config.json." |
| 161 | + else |
| 162 | + echo "Error: The configuration file ${GITHUB_WORKSPACE}/apps/${{ github.event.repository.name }}/.github/helper/db/$DB.json does not exist." |
| 163 | + echo "Please ensure that the database JSON file is correctly named and located in the helper/db directory." |
| 164 | + exit 1 # Exit with a non-zero status to indicate failure |
| 165 | + fi |
| 166 | +
|
| 167 | + if [ "$DB" == "mariadb" ]; then |
| 168 | + mariadb --host 127.0.0.1 --port 3306 -u root -p${{ inputs.db-root-password }} -e "SET GLOBAL character_set_server = 'utf8mb4'"; |
| 169 | + mariadb --host 127.0.0.1 --port 3306 -u root -p${{ inputs.db-root-password }} -e "SET GLOBAL collation_server = 'utf8mb4_unicode_ci'"; |
| 170 | +
|
| 171 | + mariadb --host 127.0.0.1 --port 3306 -u root -p${{ inputs.db-root-password }} -e "CREATE DATABASE test_frappe"; |
| 172 | + mariadb --host 127.0.0.1 --port 3306 -u root -p${{ inputs.db-root-password }} -e "CREATE USER 'test_frappe'@'localhost' IDENTIFIED BY 'test_frappe'"; |
| 173 | + mariadb --host 127.0.0.1 --port 3306 -u root -p${{ inputs.db-root-password }} -e "GRANT ALL PRIVILEGES ON \`test_frappe\`.* TO 'test_frappe'@'localhost'"; |
| 174 | +
|
| 175 | + mariadb --host 127.0.0.1 --port 3306 -u root -p${{ inputs.db-root-password }} -e "FLUSH PRIVILEGES"; |
| 176 | + fi |
| 177 | +
|
| 178 | + if [ "$DB" == "postgres" ]; then |
| 179 | + export PGPASSWORD='travis' |
| 180 | + psql -h 127.0.0.1 -p 5432 -c "CREATE DATABASE test_frappe" -U postgres |
| 181 | + psql -h 127.0.0.1 -p 5432 -c "CREATE USER test_frappe WITH PASSWORD 'test_frappe'" -U postgres |
| 182 | + psql -h 127.0.0.1 -p 5432 -U postgres -c "GRANT ALL PRIVILEGES ON DATABASE test_frappe TO test_frappe;" |
| 183 | + unset PGPASSWORD |
| 184 | + fi |
| 185 | +
|
| 186 | + - shell: bash -e {0} |
| 187 | + run: | |
| 188 | + # Install App(s) |
| 189 | + step_start_time=$(date +%s) |
| 190 | + source ${GITHUB_WORKSPACE}/env/bin/activate |
| 191 | +
|
| 192 | + for app in ${GITHUB_WORKSPACE}/apps/*/; do |
| 193 | + app_name="$(basename $app)" |
| 194 | + if [ -f "${app}setup.py" ] || [ -f "${app}pyproject.toml" ]; then |
| 195 | + start_time=$(date +%s) |
| 196 | + echo -e "\033[36mInstalling python app from ${app}\033[0m" |
| 197 | + pip install --upgrade -e "${app}[dev,test]" |
| 198 | + end_time=$(date +%s) |
| 199 | + echo -e "\033[36mTime taken to Install python ${app}: $((end_time - start_time)) seconds\033[0m" |
| 200 | + fi |
| 201 | + if [ "${{ inputs.build-assets }}" == "true" ] && [ -f "${app}package.json" ]; then |
| 202 | + start_time=$(date +%s) |
| 203 | + echo -e "\033[36mInstalling js app dependencies from ${app}\033[0m" |
| 204 | + pushd "$app" |
| 205 | + yarn --check-files |
| 206 | + popd |
| 207 | + end_time=$(date +%s) |
| 208 | + echo -e "\033[36mTime taken to Install js ${app}: $((end_time - start_time)) seconds\033[0m" |
| 209 | + fi |
| 210 | + echo "$app_name" >> sites/apps.txt |
| 211 | + echo -e "\033[32mAdded $app_name to $PWD/sites/apps.txt\033[0m" |
| 212 | + done |
| 213 | + step_end_time=$(date +%s) |
| 214 | + echo -e "\033[33mInstall App(s): $((step_end_time - step_start_time)) seconds\033[0m" |
| 215 | + env: |
| 216 | + TYPE: server |
| 217 | + |
| 218 | + - shell: bash -e {0} |
| 219 | + run: | |
| 220 | + # Start Bench |
| 221 | + source ${GITHUB_WORKSPACE}/env/bin/activate |
| 222 | + bench start &> ${GITHUB_WORKSPACE}/bench_start.log & |
| 223 | +
|
| 224 | + - shell: bash -e {0} |
| 225 | + if: ${{ inputs.build-assets == 'true' }} |
| 226 | + run: | |
| 227 | + # Build Assets |
| 228 | + start_time=$(date +%s) |
| 229 | +
|
| 230 | + source ${GITHUB_WORKSPACE}/env/bin/activate |
| 231 | + CI=Yes bench build --force --production & |
| 232 | + build_pid=$! |
| 233 | + bench --site test_site reinstall --yes |
| 234 | + wait $build_pid |
| 235 | +
|
| 236 | + end_time=$(date +%s) |
| 237 | + echo -e "\033[33mBuild Assets and reinstall site: $((end_time - start_time)) seconds\033[0m" |
0 commit comments