From c728508818f1dd60c031501d73e9779535c546b6 Mon Sep 17 00:00:00 2001 From: Webb Scales <7795764+webbnh@users.noreply.github.com> Date: Mon, 4 Nov 2024 08:16:25 -0500 Subject: [PATCH] Update workflow for PRs (#45) * Streamline the difference check * Make doc updates support PRs * Experiment --- .github/workflows/reusable_workflow.yaml | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/reusable_workflow.yaml b/.github/workflows/reusable_workflow.yaml index 363626e..a5b991f 100644 --- a/.github/workflows/reusable_workflow.yaml +++ b/.github/workflows/reusable_workflow.yaml @@ -58,21 +58,23 @@ jobs: - name: Determine diff run: | - set +e - diff README.md README_TMP.md > arcaflow-docsgen.diff - set -e - echo "README_DIFF=$(cat arcaflow-docsgen.diff | wc -l)" >> $GITHUB_ENV + echo "README_DIFF=$(cmp -s README.md README_TMP.md ; echo $?)" >> $GITHUB_ENV - - name: Update README.md if necessary - if: env.README_DIFF != 0 && !github.ref_protected + - name: Update README.md if appropriate + # The github.head_ref variable is only available for pull requests, + # however, we probably shouldn't be updating the branch for anything + # which isn't a PR, anyway! + if: env.README_DIFF == 1 && github.event_name == 'pull_request' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_EMAIL: arcalot@redhat.com GH_USERNAME: arcabot run: | - mv README_TMP.md README.md git config --global user.name $GH_USERNAME git config --global user.email $GH_EMAIL - git add README.md - git commit -m 'Automatic update of README.md by arcaflow-docsgen arcabot' - git push + git fetch origin ${{ github.head_ref }} + git checkout -f ${{ github.head_ref }} + mv README_TMP.md README.md + git commit -m 'Automatic update of README.md by arcaflow-docsgen arcabot' README.md + git push origin HEAD:${{ github.head_ref }} + git checkout -f refs/remotes/pull/${{ github.ref_name }}