Files
erpnext/.github/workflows/patch.yml

199 lines
6.8 KiB
YAML

name: Patch
on:
pull_request:
workflow_dispatch:
permissions:
contents: read
packages: read
concurrency:
group: patch-develop-${{ github.event_name }}-${{ github.event.number || github.event_name == 'workflow_dispatch' && github.run_id || '' }}
cancel-in-progress: true
jobs:
test:
if: >-
(github.event_name != 'pull_request'
|| (github.event.pull_request.user.login == 'mergify[bot]' && startsWith(github.head_ref, 'mergify/merge-queue/'))
|| (startsWith(github.base_ref, 'version-') && !endsWith(github.base_ref, '-hotfix')))
runs-on: erpnext-arc-patch
timeout-minutes: 60
name: Patch Test
container:
image: ghcr.io/frappe/erpnext-ci-mariadb:py3.14-node24-mariadb11.8
credentials:
username: ${{ secrets.GHCR_USERNAME || github.actor }}
password: ${{ secrets.GHCR_TOKEN || github.token }}
defaults:
run:
shell: bash
env:
ERPNEXT_CI_USER: ci
CI_DB_DATADIR: /home/ci/db-ram/data
PIP_CACHE_DIR: /home/ci/.cache/pip
npm_config_cache: /home/ci/.cache/npm
YARN_CACHE_FOLDER: /home/ci/.cache/yarn
UV_CACHE_DIR: /home/ci/.cache/uv
UV_LINK_MODE: copy
steps:
- name: Clone
uses: actions/checkout@v6
- name: Check for valid Python & Merge Conflicts
run: |
python -m compileall -fq "${GITHUB_WORKSPACE}"
if grep -lr --exclude-dir=node_modules "^<<<<<<< " "${GITHUB_WORKSPACE}"
then echo "Found merge conflicts"
exit 1
fi
- name: Add to Hosts
run: echo "127.0.0.1 test_site" | sudo tee -a /etc/hosts
- name: Start DB
run: bash ${GITHUB_WORKSPACE}/.github/helper/start-db.sh
env:
SKIP_SYSTEM_SETUP: "1"
# The v14 baseline backup is a fixed published file — cache it instead of re-downloading
# it from the GitHub release every run.
- name: Cache erpnext v14 backup
id: cache-v14
uses: actions/cache@v4
with:
path: /tmp/erpnext-v14.sql.gz
key: erpnext-v14-sql-gz
- name: Download erpnext v14 backup
if: steps.cache-v14.outputs.cache-hit != 'true'
run: |
curl -fSL --retry 5 --retry-all-errors --retry-delay 5 \
-o /tmp/erpnext-v14.sql.gz \
https://github.com/frappe/erpnext/releases/download/v14-baseline/erpnext-v14.sql.gz
- name: Install
run: bash ${GITHUB_WORKSPACE}/.github/helper/install.sh
env:
DB: mariadb
TYPE: patch
DB_HOST: 127.0.0.1
DB_USER_HOST: '%'
SKIP_SYSTEM_SETUP: "1"
SKIP_WKHTMLTOX_SETUP: 1
CI_SKIP_ERPNEXT_ASSETS: 1
# Anonymous git to github.com gets throttled to a 401; authenticate the clones.
CI_GITHUB_TOKEN: ${{ github.token }}
- name: Run Patch Tests
run: |
su -m "$ERPNEXT_CI_USER" -s /bin/bash <<'EOF'
set -eo pipefail
cd ~/frappe-bench/
jq 'del(.install_apps)' ~/frappe-bench/sites/test_site/site_config.json > tmp.json
mv tmp.json ~/frappe-bench/sites/test_site/site_config.json
bench --site test_site --force restore /tmp/erpnext-v14.sql.gz
git -C "apps/frappe" remote set-url upstream https://github.com/frappe/frappe.git
git -C "apps/erpnext" remote set-url upstream https://github.com/frappe/erpnext.git
# Start every bench process except the background workers. If workers run during a
# migrate, they pick up the orphan-link cleanup jobs it enqueues and race its schema
# changes, which fails with MySQL 1412 "Table definition has changed". Redis and the
# other services stay up; the queued jobs simply wait and are harmless here.
function start_bench_without_workers() {
local procs
procs=$(awk -F: '/^[a-z_]+:/ && $1 !~ /worker/ {print $1}' ~/frappe-bench/Procfile)
honcho start -f ~/frappe-bench/Procfile $procs &>> ~/frappe-bench/bench_start.log &
}
function retry() {
for attempt in 1 2 3; do
"$@" && return
echo "Attempt $attempt failed: $*"
sleep 15
done
return 1
}
function update_to_version() {
version=$1
branch_name="version-$version-hotfix"
echo "Updating to v$version"
# Fetch and checkout branches
retry git -C "apps/frappe" fetch --depth 1 upstream $branch_name:$branch_name
retry git -C "apps/erpnext" fetch --depth 1 upstream $branch_name:$branch_name
git -C "apps/frappe" checkout -q -f $branch_name
git -C "apps/erpnext" checkout -q -f $branch_name
# Resetup env and install apps
pgrep honcho | xargs kill
sleep 10
rm -rf ~/frappe-bench/env
bench -v setup env --python "$2"
bench pip install -e ./apps/erpnext
start_bench_without_workers
bench --site test_site migrate
}
uv python install 3.13
update_to_version 15 "$(uv python find 3.13)"
echo "Updating to latest version"
fallback_to_hotfix=0
if [ -n "${GITHUB_BASE_REF:-}" ]; then
frappe_ref="refs/heads/$GITHUB_BASE_REF"
fallback_to_hotfix=1
elif [ "${GITHUB_REF_TYPE:-}" = "branch" ]; then
frappe_ref="$GITHUB_REF"
fallback_to_hotfix=1
elif [ "${GITHUB_REF_TYPE:-}" = "tag" ]; then
frappe_ref="$GITHUB_REF"
else
echo "Unsupported GitHub ref type: '${GITHUB_REF_TYPE:-unset}'"
exit 1
fi
ls_remote_status=0
git -C "apps/frappe" ls-remote --exit-code upstream "$frappe_ref" >/dev/null \
|| ls_remote_status=$?
if [ "$ls_remote_status" -eq 2 ] && [ "$fallback_to_hotfix" -eq 1 ]; then
echo "frappe has no '$frappe_ref'; falling back to version-16-hotfix"
frappe_ref=refs/heads/version-16-hotfix
elif [ "$ls_remote_status" -ne 0 ]; then
exit "$ls_remote_status"
fi
retry git -C "apps/frappe" fetch --depth 1 upstream "$frappe_ref"
git -C "apps/frappe" checkout -q -f FETCH_HEAD
git -C "apps/erpnext" checkout -q -f "$GITHUB_SHA"
pgrep honcho | xargs kill
rm -rf ~/frappe-bench/env
bench -v setup env --python python3.14
bench pip install -e ./apps/erpnext
start_bench_without_workers
bench --site test_site migrate
EOF
- name: Show bench output
if: ${{ always() }}
run: |
cd ~/frappe-bench
cat bench_start.log || true
cd logs
for f in ./*.log*; do
echo "Printing log: $f";
cat $f
done