Skip to content

Commit

Permalink
Refactor for readability and adds better output messages
Browse files Browse the repository at this point in the history
Authored-by: Wayne Adams <wayne.adams@broadcom.com>
  • Loading branch information
wayneadams committed Mar 11, 2024
1 parent 926bf2d commit 6541724
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions .github/workflows/upgrade-golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,34 @@ jobs:
name: Commit changes and create PR
working-directory: om
run: |
files_changed=$(git status --porcelain)
if [[ -n ${files_changed} ]]; then
git config --global url.https://${GITHUB_TOKEN}@github.com/.insteadOf https://github.com/
git config --global user.email "149723437+tas-operability-bot@users.noreply.github.com"
git config --global user.name "tas-operability-bot"
branch_suffix=$(echo "${GITHUB_SHA}" | cut -c1-7)
branch_name="tmp/upgrade-golang-${branch_suffix}"
if git show-ref --verify --quiet "refs/remotes/origin/${branch_name}"; then
echo "Branch ${branch_name} already exists. Exiting..."
exit 0
fi
branch_suffix=$(echo "${GITHUB_SHA}" | cut -c1-7)
branch_name="tmp/upgrade-golang-${branch_suffix}"
existing_pr=$(gh pr list --search "Upgrade Golang in:title" | grep "Upgrade Golang")
if [[ -n ${existing_pr} ]]; then
echo "PR with title 'Upgrade Golang' already exists. Exiting..."
exit 0
fi
files_changed=$(git status --porcelain)
if [[ -z ${files_changed} ]]; then
echo "No changes to detected. Exiting..."
exit 0
fi
if git show-ref --verify --quiet "refs/remotes/origin/${branch_name}"; then
echo "Branch ${branch_name} already exists. Exiting..."
exit 0
fi
git config --global url.https://${GITHUB_TOKEN}@github.com/.insteadOf https://github.com/
git config --global user.email "149723437+tas-operability-bot@users.noreply.github.com"
git config --global user.name "tas-operability-bot"
git checkout -b tmp/upgrade-golang-${branch_suffix}
git add .
git commit -m "Upgrade Golang"
git push --set-upstream origin tmp/upgrade-golang-${branch_suffix}
gh pr create --title "Upgrade Golang" --body "Upgrade Golang" --base main --head tmp/upgrade-golang-${branch_suffix}
gh pr merge tmp/upgrade-golang-${branch_suffix} --auto --rebase --delete-branch
fi
git checkout -b ${branch_name}
git add .
git commit -m "Upgrade Golang"
git push --set-upstream origin ${branch_name}
gh pr create --title "Upgrade Golang" --body "Upgrade Golang" --base main --head ${branch_name}
gh pr merge ${branch_name} --auto --rebase --delete-branch
env:
GITHUB_TOKEN: ${{ secrets.TAS_OPERABILITY_BOT_OM_REPO_PAT }}

0 comments on commit 6541724

Please sign in to comment.