From f2c9c9ebbb209c3f05f3495c7b94a9fb75155f60 Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Tue, 15 Jun 2021 13:17:15 -0700 Subject: [PATCH] Improve bump-jslib GH action (#1030) * Change reviewer to dept-engineering * Use modern command substitution instead of backticks * Fix truncation of git log, improve Github syntax * Change PR title --- .github/workflows/bump-jslib.yml | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/.github/workflows/bump-jslib.yml b/.github/workflows/bump-jslib.yml index ca8f014684..a472d5a543 100644 --- a/.github/workflows/bump-jslib.yml +++ b/.github/workflows/bump-jslib.yml @@ -24,7 +24,7 @@ jobs: if [ "$CHECKED_OUT_BRANCH_NAME" = "master" ]; then TARGET_BRANCH_NAME="auto-bump-jslib" git fetch origin - EXISTING_PR=`git ls-remote --heads origin $TARGET_BRANCH_NAME | wc -l` + EXISTING_PR=$(git ls-remote --heads origin $TARGET_BRANCH_NAME | wc -l) if [ "$EXISTING_PR" -gt 0 ]; then git checkout $TARGET_BRANCH_NAME echo "[*] Checked out existing PR branch $TARGET_BRANCH_NAME" @@ -39,11 +39,11 @@ jobs: fi npm run sub:init - OLD_JSLIB_HASH=`git submodule status | awk '{print $1}'` + OLD_JSLIB_HASH=$(git submodule status | awk '{print $1}') npm run sub:update - if [ `git diff jslib | wc -l` -eq 0 ]; then + if [ $(git diff jslib | wc -l) -eq 0 ]; then echo "Unable to bump jslib: branch $TARGET_BRANCH_NAME is already using the latest jslib commit." if [ "$EXISTING_PR" -gt 0 ]; then echo "Try merging the $TARGET_BRANCH_NAME branch into master first." @@ -54,38 +54,37 @@ jobs: git add jslib git commit -m "Bump jslib" - NEW_JSLIB_HASH=`git submodule status | awk '{print $1}'` - echo "[*] Bumped jslib to $NEW_JSLIB_HASH" - if [ "$EXISTING_PR" -eq 0 ]; then git push -u origin $TARGET_BRANCH_NAME else git push origin $TARGET_BRANCH_NAME fi echo "[*] Pushed to $TARGET_BRANCH_NAME" - - cd jslib - GIT_LOG=`git log $OLD_JSLIB_HASH..$NEW_JSLIB_HASH --oneline | sed 's/^/* /g' | sed 's/#[0-9]*[)]/bitwarden\/jslib&/g'` - echo "::set-output name=git-log::${GIT_LOG}" + echo "::set-output name=old-jslib-hash::${OLD_JSLIB_HASH}" echo "::set-output name=existing-pr::${EXISTING_PR}" - name: Submit or update PR against master branch if: github.ref == 'refs/heads/master' run: | + NEW_JSLIB_HASH=$(git submodule status | awk '{print $1}') + cd jslib + GIT_LOG="$(git log $OLD_JSLIB_HASH..$NEW_JSLIB_HASH --oneline | sed 's/^[a-zA-Z0-9]*/* `&`/g' | sed 's/#[0-9]*[)]/bitwarden\/jslib&/g')" + cd .. + BODY_TEXT="@${{github.actor}} would like to bump jslib in this repo. This will pull in the following new commits: $GIT_LOG" if [ "$EXISTING_PR" -eq 0 ]; then - gh pr create --title "Auto bump jslib" \ + gh pr create --title "[Bot] Bump jslib" \ --body "$BODY_TEXT" \ - --reviewer eliykat + --reviewer bitwarden/dept-engineering echo "[*] Submitted PR against master branch" else gh pr comment --body "$BODY_TEXT" echo "[*] Updated existing PR" fi env: - GIT_LOG: ${{ steps.bump.outputs.git-log }} + OLD_JSLIB_HASH: ${{ steps.bump.outputs.old-jslib-hash }} EXISTING_PR: ${{ steps.bump.outputs.existing-pr }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}