Commit 6f998a91 authored by chenhe's avatar chenhe

add check for empty commit

parent 4a26d2ae
...@@ -21,12 +21,12 @@ jobs: ...@@ -21,12 +21,12 @@ jobs:
TARGET_BRANCH: 'test-howto-sync' TARGET_BRANCH: 'test-howto-sync'
ACCESS_TOKEN: ${{ secrets.DIFY_DOCS_ACCESS_TOKEN }} ACCESS_TOKEN: ${{ secrets.DIFY_DOCS_ACCESS_TOKEN }}
run: | run: |
CHANGED_FILES=$(git diff --name-only --diff-filter=AMDR ${{ github.event.before }}..${{ github.event.after }} | grep -e 'howto-.*\.md$' || true) CHANGED_HOWTOS=$(git diff --no-renames --name-only --diff-filter=AMDR ${{ github.event.before }}..${{ github.event.after }} | grep -e 'howto-.*\.md$' || true)
echo "Changed files:" echo "Changed how-to files:"
echo "$CHANGED_FILES" echo "$CHANGED_HOWTOS"
if [ -z "$CHANGED_FILES" ]; then if [ -z "$CHANGED_HOWTOS" ]; then
echo "No new how-to file changes to sync" echo "No new how-to file changes to sync"
exit 0 exit 0
fi fi
...@@ -36,14 +36,13 @@ jobs: ...@@ -36,14 +36,13 @@ jobs:
cd dify-docs-sparse cd dify-docs-sparse
git checkout $TARGET_BRANCH git checkout $TARGET_BRANCH
echo "checked out target branch" echo "checked out target branch: $TARGET_BRANCH"
echo "Current branch: $TARGET_BRANCH"
git sparse-checkout set en/tutorials/ zh_CN/tutorials/ git sparse-checkout set en/tutorials/ zh_CN/tutorials/
echo "set sparse checked out directories of dify-docs repo" echo "set sparse checked out directories of dify-docs repo"
# Sync files to different language directories # Sync files to different language directories
for file in $CHANGED_FILES; do for file in $CHANGED_HOWTOS; do
echo "Processing file: $file" echo "Processing file: $file"
if [[ $file == *"_CN.md" ]]; then if [[ $file == *"_CN.md" ]]; then
TARGET_DIR="zh_CN/tutorials" TARGET_DIR="zh_CN/tutorials"
...@@ -63,15 +62,22 @@ jobs: ...@@ -63,15 +62,22 @@ jobs:
git config user.name github-actions git config user.name github-actions
git config user.email github-actions@github.com git config user.email github-actions@github.com
git add . git add --all
git commit -m "Sync how-to markdown files from PR #${{ github.event.pull_request.number }} on main repo"
echo "Pushing files to $TARGET_BRANCH branch of $TARGET_REPO" GIT_STATUS=$(git status --porcelain)
echo "staged changes: $GIT_STATUS"
if git push https://${ACCESS_TOKEN}@${TARGET_REPO#https://} HEAD:${TARGET_BRANCH}; then if [ -z "$GIT_STATUS" ]; then
echo "Files have been successfully pushed to $TARGET_BRANCH branch of $TARGET_REPO" echo "Nothing to commit, skipping push"
else else
echo "Failed to push files to $TARGET_BRANCH branch of $TARGET_REPO" git commit -m "Sync how-to markdown files from PR #${{ github.event.pull_request.number }} on main repo"
exit 1
echo "Pushing files to $TARGET_BRANCH branch of $TARGET_REPO"
if git push https://${ACCESS_TOKEN}@${TARGET_REPO#https://} HEAD:${TARGET_BRANCH}; then
echo "Files have been successfully pushed to $TARGET_BRANCH branch of $TARGET_REPO"
else
echo "Failed to push files to $TARGET_BRANCH branch of $TARGET_REPO"
exit 1
fi
fi fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment