fix: use linear history for deploy branch instead of orphan/force-push
Hostinger's git pull fails with divergent branches when force-pushing orphan commits. Switch to a linear commit strategy: checkout the existing deploy branch, sync plugin files from main, and push normally. This keeps Hostinger's git pull fast-forward compatible. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
34
.github/workflows/deploy.yml
vendored
34
.github/workflows/deploy.yml
vendored
@@ -32,29 +32,43 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Build deploy branch
|
- name: Sync deploy branch
|
||||||
run: |
|
run: |
|
||||||
git config user.name "github-actions[bot]"
|
git config user.name "github-actions[bot]"
|
||||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
|
|
||||||
# Create a temporary orphan branch with only plugin files.
|
# Fetch the remote deploy branch (may not exist on first run).
|
||||||
git checkout --orphan deploy-staging
|
git fetch origin deploy:deploy 2>/dev/null || true
|
||||||
|
|
||||||
# Remove everything from the index.
|
# If deploy branch exists, check it out; otherwise create it.
|
||||||
git rm -rf --cached . > /dev/null 2>&1 || true
|
if git rev-parse --verify deploy >/dev/null 2>&1; then
|
||||||
|
git checkout deploy
|
||||||
|
else
|
||||||
|
git checkout --orphan deploy
|
||||||
|
git rm -rf --cached . > /dev/null 2>&1 || true
|
||||||
|
fi
|
||||||
|
|
||||||
# Stage only the plugin runtime files.
|
# Remove all tracked files so we start clean each time.
|
||||||
git add -f \
|
git rm -rf . > /dev/null 2>&1 || true
|
||||||
|
|
||||||
|
# Checkout only the plugin runtime files from main.
|
||||||
|
git checkout main -- \
|
||||||
admin/ \
|
admin/ \
|
||||||
includes/ \
|
includes/ \
|
||||||
languages/ \
|
languages/ \
|
||||||
public/ \
|
public/ \
|
||||||
peptide-news-plugin.php
|
peptide-news-plugin.php
|
||||||
|
|
||||||
git commit -m "Deploy ${GITHUB_SHA::7} from main"
|
# Commit only if there are actual changes.
|
||||||
|
git add -A
|
||||||
|
if git diff-index --quiet HEAD -- 2>/dev/null; then
|
||||||
|
echo "No changes to deploy."
|
||||||
|
else
|
||||||
|
git commit -m "Deploy ${GITHUB_SHA::7} from main"
|
||||||
|
fi
|
||||||
|
|
||||||
# Force-push to the deploy branch (Hostinger webhook triggers auto-pull).
|
# Normal push (fast-forward compatible with Hostinger's git pull).
|
||||||
git push --force origin deploy-staging:deploy
|
git push origin deploy
|
||||||
|
|
||||||
- name: Purge LiteSpeed Cache
|
- name: Purge LiteSpeed Cache
|
||||||
if: success()
|
if: success()
|
||||||
|
|||||||
Reference in New Issue
Block a user