From adf92c580a9d238e19d21721c962b2c9519b5b4a Mon Sep 17 00:00:00 2001 From: George McCabe <23407799+georgemccabe@users.noreply.github.com> Date: Thu, 23 May 2024 09:40:20 -0600 Subject: [PATCH 1/4] Enhance update truth data workflow to create a uniquely named branch to update *-ref branches and commit/append to a log file that tracks the reasons for updating the truth data. This is done to ensure that the *-ref branch testing workflow run that actually updates the truth data is always run even if there are no other changes to the METplus branch since the last update, e.g. when a change to another component like MET warrants the truth data update --- .github/workflows/update_truth.yml | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/.github/workflows/update_truth.yml b/.github/workflows/update_truth.yml index 4b8c310dd7..523c1cc11e 100644 --- a/.github/workflows/update_truth.yml +++ b/.github/workflows/update_truth.yml @@ -32,6 +32,7 @@ jobs: fetch-depth: 0 token: ${{ secrets.METPLUS_BOT_TOKEN }} - name: Resolve conflicts between branch and branch-ref + id: resolve_conflicts run: | branch_name=${{ env.branch_name }} cd ${GITHUB_WORKSPACE} @@ -43,17 +44,43 @@ jobs: echo ${branch_name}-ref does exist -- update it git config --global user.name "metplus-bot" git config --global user.email "97135045+metplus-bot@users.noreply.github.com" + # checkout branch (develop or main_vX.Y) echo git checkout ${branch_name} git checkout ${branch_name} + + # merge -ref branch into branch (favoring branch changes) echo git merge -s ours origin/${branch_name}-ref git merge -s ours origin/${branch_name}-ref + + # push changes to branch (develop or main_vX.Y) echo git push origin ${branch_name} git push origin ${branch_name} + # create unique branch name to update *-ref branch + update_branch=update_${branch_name}_$(uuidgen | cut -d "-" -f1) + echo "update_branch=${update_branch}" >> $GITHUB_OUTPUT + + # create update branch from branch (develop or main_vX.Y) + echo git checkout -b ${update_branch} + git checkout -b ${update_branch} + + # create or append to file to track truth data changes + # and ensure that PR merge into *-ref branch triggered testing workflow + change_log_path=.github/update_truth_change_log.txt + change_entry="[$(date +%Y%m%d_%H:%M:%S) ${branch_name}] ${{ github.event.inputs.pull_requests }} - ${{ github.event.inputs.change_summary }}" + echo "${change_entry}" >> ${change_log_path} + echo git commit ${change_log_path} + git commit -m "added entry to update truth change log: ${branch_name} ${{ github.event.inputs.pull_requests }}" ${change_log_path} + cmd="git push origin ${update_branch}" + echo $cmd + $cmd + + # create pull request from $HEAD into $BASE - name: Create Pull Request - run: gh pr create --base $BASE --body "$BODY" --title "$TITLE" + run: gh pr create --head $HEAD --base $BASE --body "$BODY" --title "$TITLE" env: GH_TOKEN: ${{ github.token }} + HEAD: ${{ steps.resolve_conflicts.outputs.update_branch }} BASE: ${{ env.branch_name }}-ref BODY: ${{ github.event.inputs.change_summary }}
Created by @${{ github.actor}} TITLE: Update ${{ env.branch_name }}-ref after ${{ github.event.inputs.pull_requests }} From 033203261aebba58011d2b80f3882b93f76064a6 Mon Sep 17 00:00:00 2001 From: George McCabe <23407799+georgemccabe@users.noreply.github.com> Date: Thu, 23 May 2024 09:45:43 -0600 Subject: [PATCH 2/4] git add change log file in case it doesn't already exist --- .github/workflows/update_truth.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/update_truth.yml b/.github/workflows/update_truth.yml index 523c1cc11e..ea937857ba 100644 --- a/.github/workflows/update_truth.yml +++ b/.github/workflows/update_truth.yml @@ -69,8 +69,17 @@ jobs: change_log_path=.github/update_truth_change_log.txt change_entry="[$(date +%Y%m%d_%H:%M:%S) ${branch_name}] ${{ github.event.inputs.pull_requests }} - ${{ github.event.inputs.change_summary }}" echo "${change_entry}" >> ${change_log_path} + + # add file if it does not already exist + cmd="git add ${change_log_path}" + echo $cmd + $cmd + + # commit changes to change log file echo git commit ${change_log_path} git commit -m "added entry to update truth change log: ${branch_name} ${{ github.event.inputs.pull_requests }}" ${change_log_path} + + # push changes to update branch on GitHub cmd="git push origin ${update_branch}" echo $cmd $cmd From 5bbb590d362039994908462c8a8d55d156f732bc Mon Sep 17 00:00:00 2001 From: George McCabe <23407799+georgemccabe@users.noreply.github.com> Date: Thu, 23 May 2024 11:42:04 -0600 Subject: [PATCH 3/4] changed logic to no longer push changes to develop/main_vX.Y, but instead merge changes from -ref into the update branch --- .github/workflows/update_truth.yml | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/.github/workflows/update_truth.yml b/.github/workflows/update_truth.yml index ea937857ba..df66b16a77 100644 --- a/.github/workflows/update_truth.yml +++ b/.github/workflows/update_truth.yml @@ -12,7 +12,7 @@ on: jobs: update_truth: - name: "Update or create truth reference branch" + name: "Update truth reference branch" runs-on: ubuntu-latest steps: - name: Check if branch is develop or main_vX.Y @@ -48,14 +48,6 @@ jobs: echo git checkout ${branch_name} git checkout ${branch_name} - # merge -ref branch into branch (favoring branch changes) - echo git merge -s ours origin/${branch_name}-ref - git merge -s ours origin/${branch_name}-ref - - # push changes to branch (develop or main_vX.Y) - echo git push origin ${branch_name} - git push origin ${branch_name} - # create unique branch name to update *-ref branch update_branch=update_${branch_name}_$(uuidgen | cut -d "-" -f1) echo "update_branch=${update_branch}" >> $GITHUB_OUTPUT @@ -64,6 +56,10 @@ jobs: echo git checkout -b ${update_branch} git checkout -b ${update_branch} + # merge -ref branch into update branch (favoring branch changes) + echo git merge -s ours origin/${branch_name}-ref + git merge -s ours origin/${branch_name}-ref + # create or append to file to track truth data changes # and ensure that PR merge into *-ref branch triggered testing workflow change_log_path=.github/update_truth_change_log.txt From cd07c025c6df2da7793ed7c8d291001cc5fd8e8b Mon Sep 17 00:00:00 2001 From: George McCabe <23407799+georgemccabe@users.noreply.github.com> Date: Thu, 23 May 2024 12:05:53 -0600 Subject: [PATCH 4/4] retain update truth history file from *-ref --- .github/workflows/update_truth.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/update_truth.yml b/.github/workflows/update_truth.yml index df66b16a77..6b190e42fa 100644 --- a/.github/workflows/update_truth.yml +++ b/.github/workflows/update_truth.yml @@ -60,9 +60,15 @@ jobs: echo git merge -s ours origin/${branch_name}-ref git merge -s ours origin/${branch_name}-ref + change_log_path=.github/update_truth_change_log.txt + + # get truth change log from *-ref branch + cmd="git checkout origin/${branch_name}-ref -- ${change_log_path}" + echo $cmd + $cmd + # create or append to file to track truth data changes # and ensure that PR merge into *-ref branch triggered testing workflow - change_log_path=.github/update_truth_change_log.txt change_entry="[$(date +%Y%m%d_%H:%M:%S) ${branch_name}] ${{ github.event.inputs.pull_requests }} - ${{ github.event.inputs.change_summary }}" echo "${change_entry}" >> ${change_log_path}