Skip to content

Commit

Permalink
main_v5.1 - Enhance update truth data workflow to create a uniquely n…
Browse files Browse the repository at this point in the history
…amed branch... (#2678)

* 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

* git add change log file in case it doesn't already exist

* changed logic to no longer push changes to develop/main_vX.Y, but instead merge changes from -ref into the update branch

* retain update truth history file from *-ref
  • Loading branch information
georgemccabe authored Sep 6, 2024
1 parent a07b368 commit 3769e0f
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions .github/workflows/update_truth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand All @@ -43,17 +44,54 @@ 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}
# 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}
# 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
echo git push origin ${branch_name}
git push origin ${branch_name}
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_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
# 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 }}<br/>Created by @${{ github.actor}}
TITLE: Update ${{ env.branch_name }}-ref after ${{ github.event.inputs.pull_requests }}

0 comments on commit 3769e0f

Please sign in to comment.