Skip to content

Commit f37cecb

Browse files
authored
Update sync-content-to-next.yml
1 parent 6180f0b commit f37cecb

File tree

1 file changed

+28
-41
lines changed

1 file changed

+28
-41
lines changed

.github/workflows/sync-content-to-next.yml

+28-41
Original file line numberDiff line numberDiff line change
@@ -173,50 +173,19 @@ jobs:
173173
echo "PR Title: ${{ github.event.pull_request.title }}"
174174
echo "Added Label: ${{ github.event.label.name }}"
175175
176-
- name: Check PR files
177-
id: check-pr-files
178-
run: |
179-
echo "Checking PR files..."
180-
# Get list of modified files in the PR
181-
PR_FILES=$(gh pr view ${{ github.event.pull_request.number }} --json files --jq '.files[].path')
182-
echo "Files in PR:"
183-
echo "$PR_FILES"
184-
185-
# Check for content files
186-
CONTENT_FILES=""
187-
while IFS= read -r file; do
188-
if [[ "$file" =~ ^docusaurus/docs/cms/ || "$file" =~ ^docusaurus/docs/cloud/ || "$file" =~ ^docusaurus/static/img/assets/ ]]; then
189-
CONTENT_FILES="$CONTENT_FILES$file"$'\n'
190-
fi
191-
done <<< "$PR_FILES"
192-
193-
if [[ -n "$CONTENT_FILES" ]]; then
194-
echo "Content files found:"
195-
echo "$CONTENT_FILES"
196-
echo "has_content_files=true" >> $GITHUB_OUTPUT
197-
echo "content_files<<EOF" >> $GITHUB_OUTPUT
198-
echo "$CONTENT_FILES" >> $GITHUB_OUTPUT
199-
echo "EOF" >> $GITHUB_OUTPUT
200-
else
201-
echo "No content files found."
202-
echo "has_content_files=false" >> $GITHUB_OUTPUT
203-
fi
204-
env:
205-
GITHUB_TOKEN: ${{ secrets.SYNC_MAIN_TO_NEXT }}
206-
207176
- name: Create PR to next branch
208-
if: steps.check-pr-files.outputs.has_content_files == 'true'
209177
run: |
210178
echo "Creating PR to next branch..."
211179
SOURCE_BRANCH="${{ github.event.pull_request.head.ref }}"
212180
SOURCE_REPO="${{ github.event.pull_request.head.repo.full_name }}"
213181
PR_TITLE="${{ github.event.pull_request.title }}"
182+
PR_NUMBER="${{ github.event.pull_request.number }}"
214183
215184
echo "Source Branch: $SOURCE_BRANCH"
216185
echo "Source Repo: $SOURCE_REPO"
217186
218187
# Create a new branch based on next
219-
TARGET_BRANCH="next-port-pr${{ github.event.pull_request.number }}"
188+
TARGET_BRANCH="next-port-pr$PR_NUMBER"
220189
echo "Target Branch: $TARGET_BRANCH"
221190
222191
git fetch origin next
@@ -231,18 +200,36 @@ jobs:
231200
git fetch origin $SOURCE_BRANCH
232201
fi
233202
234-
# Get content files from PR
203+
# Get list of modified files in the PR
204+
echo "Getting list of modified files in PR #$PR_NUMBER..."
205+
PR_FILES=$(gh pr view $PR_NUMBER --json files --jq '.files[].path')
206+
echo "Files in PR:"
207+
echo "$PR_FILES"
208+
209+
# Process only content files
235210
echo "Processing content files from PR..."
236-
for file in ${{ steps.check-pr-files.outputs.content_files }}; do
237-
echo "Processing file: $file"
238-
mkdir -p $(dirname "$file")
239-
git checkout FETCH_HEAD -- "$file"
240-
done
211+
FOUND_CONTENT_FILES=false
212+
213+
# Traiter chaque fichier individuellement sans boucle for
214+
while IFS= read -r file; do
215+
if [[ "$file" =~ ^docusaurus/docs/cms/ || "$file" =~ ^docusaurus/docs/cloud/ || "$file" =~ ^docusaurus/static/img/assets/ ]]; then
216+
echo "Processing content file: $file"
217+
mkdir -p $(dirname "$file")
218+
git checkout FETCH_HEAD -- "$file"
219+
FOUND_CONTENT_FILES=true
220+
fi
221+
done <<< "$PR_FILES"
222+
223+
# Vérifier si des fichiers de contenu ont été trouvés
224+
if [ "$FOUND_CONTENT_FILES" != "true" ]; then
225+
echo "No content files found in PR. Nothing to port."
226+
exit 0
227+
fi
241228
242229
# Commit and push
243230
echo "Committing changes..."
244231
git add .
245-
git commit -m "Port PR #${{ github.event.pull_request.number }}: $PR_TITLE to next branch"
232+
git commit -m "Port PR #$PR_NUMBER: $PR_TITLE to next branch"
246233
247234
echo "Pushing branch..."
248235
git push origin $TARGET_BRANCH
@@ -251,7 +238,7 @@ jobs:
251238
echo "Creating PR from $TARGET_BRANCH to next..."
252239
gh pr create --base next --head $TARGET_BRANCH \
253240
--title "[Port to next] $PR_TITLE" \
254-
--body "Automatic port of PR #${{ github.event.pull_request.number }} to next branch.\n\nOriginal PR: #${{ github.event.pull_request.number }}\nCreated automatically after adding the 'temp - port to docs-next' label."
241+
--body "Automatic port of PR #$PR_NUMBER to next branch.\n\nOriginal PR: #$PR_NUMBER\nCreated automatically after adding the 'temp - port to docs-next' label."
255242
env:
256243
GITHUB_TOKEN: ${{ secrets.SYNC_MAIN_TO_NEXT }}
257244

0 commit comments

Comments
 (0)