adoroszlai commented on code in PR #10826:
URL: https://github.com/apache/ozone/pull/10826#discussion_r3655258401


##########
.github/workflows/update-ozone-site-config-doc.yml:
##########
@@ -128,29 +132,37 @@ jobs:
       
       - name: Commit and push changes
         if: steps.check-changes.outputs.changed == 'true'
+        env:
+          GH_TOKEN: ${{ secrets.OZONE_WEBSITE_BUILD }}
         run: |
           cd ozone-site
-          
-          echo "Current branch: $(git branch --show-current)"
-          echo "Current commit: $(git rev-parse HEAD)"
-          
-          # Create/reset branch at current commit
-          git checkout -B "$BRANCH_NAME"
-          echo "Created/reset branch $BRANCH_NAME at current commit"
-          
-          git add "$TARGET_FILE"
-          
-          # Build commit message with JIRA ID if available
+
+          EXISTING_PR=$(gh pr list --repo "$REPO_OWNER/ozone-site" \
+            --head "$BRANCH_NAME" --base master --json number --jq 
'.[0].number' || echo "")
+
           COMMIT_MSG="[Auto] Update configuration documentation from ozone 
$SHA"
           if [ -n "$JIRA_ID" ]; then
             COMMIT_MSG="$JIRA_ID. $COMMIT_MSG"
           fi
-          
-          git commit -m "$COMMIT_MSG"
-          
-          echo "Pushing $BRANCH_NAME to origin"
-          git push -f origin "$BRANCH_NAME"
-      
+
+          if [ -n "$EXISTING_PR" ]; then
+            echo "Open PR #$EXISTING_PR exists, appending commit to preserve 
history"
+            git fetch --depth=1 origin "$BRANCH_NAME"
+            git checkout -B "$BRANCH_NAME" FETCH_HEAD
+            cp ../Configurations.md "$TARGET_FILE"
+            git add "$TARGET_FILE"
+            git commit -m "$COMMIT_MSG"
+            git push origin "$BRANCH_NAME"
+          else
+            echo "No open PR, recreating branch from master"
+            git checkout master
+            git checkout -B "$BRANCH_NAME"
+            cp ../Configurations.md "$TARGET_FILE"
+            git add "$TARGET_FILE"
+            git commit -m "$COMMIT_MSG"
+            git push -f origin "$BRANCH_NAME"
+          fi

Review Comment:
   For "existing PR" case, the branch is already created in step `Check if 
documentation changed`.  We should also create it there for the "no PR" case, 
and avoid checking for PR again in this step.
   
   Use `--force-with-lease` instead of `-f/--force`: overwrite will succeed if 
branch is simply leftover, but fail if it is updated in the meantime (e.g. by 
other workflow).  We can use the flag in both cases, so `if-else` will be 
unnecessary.



##########
.github/workflows/update-ozone-site-config-doc.yml:
##########
@@ -53,21 +53,25 @@ jobs:
       
       - name: Checkout ozone-site repository
         if: steps.check-site-repo.outputs.exists == 'true'
+        env:
+          GH_TOKEN: ${{ secrets.OZONE_WEBSITE_BUILD }}
         run: |
           git config --global url."https://asf-ci-deploy:${{ 
secrets.OZONE_WEBSITE_BUILD }}@github.com/".insteadOf "https://github.com/";
           git config --global user.name 'github-actions[bot]'
           git config --global user.email 
'github-actions[bot]@users.noreply.github.com'
           
           git clone --depth=1 --branch=master 
https://github.com/$REPO_OWNER/ozone-site.git ozone-site
-          
-          # Check if $BRANCH_NAME branch exists remotely
           cd ozone-site
-          if git ls-remote --heads origin $BRANCH_NAME | grep -q $BRANCH_NAME; 
then
-            echo "PR branch exists, checking it out for comparison"
-            git fetch --depth=1 origin $BRANCH_NAME
-            git checkout -B $BRANCH_NAME FETCH_HEAD
+
+          EXISTING_PR=$(gh pr list --repo "$REPO_OWNER/ozone-site" \
+            --head "$BRANCH_NAME" --base master --json number --jq 
'.[0].number' || echo "")

Review Comment:
   This should be saved in GITHUB_ENV for reuse in step `Create or update Pull 
Request in ozone-site`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to