mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-06 09:20:43 +01:00
f2c9c9ebbb
* Change reviewer to dept-engineering * Use modern command substitution instead of backticks * Fix truncation of git log, improve Github syntax * Change PR title
91 lines
3.1 KiB
YAML
91 lines
3.1 KiB
YAML
name: Bump jslib
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
bump-jslib:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout repo
|
|
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
|
|
|
|
- name: Setup git config
|
|
run: |
|
|
git config user.name = "GitHub Action Bot"
|
|
git config user.email = "<>"
|
|
|
|
- name: Bump jslib and commit
|
|
id: bump
|
|
run: |
|
|
CHECKED_OUT_BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})
|
|
|
|
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)
|
|
if [ "$EXISTING_PR" -gt 0 ]; then
|
|
git checkout $TARGET_BRANCH_NAME
|
|
echo "[*] Checked out existing PR branch $TARGET_BRANCH_NAME"
|
|
else
|
|
git checkout -b $TARGET_BRANCH_NAME
|
|
echo "[*] Checked out new branch $TARGET_BRANCH_NAME"
|
|
fi
|
|
else
|
|
TARGET_BRANCH_NAME="$CHECKED_OUT_BRANCH_NAME"
|
|
EXISTING_PR=0
|
|
echo "[*] Running on existing feature branch $TARGET_BRANCH_NAME"
|
|
fi
|
|
|
|
npm run sub:init
|
|
OLD_JSLIB_HASH=$(git submodule status | awk '{print $1}')
|
|
|
|
npm run sub:update
|
|
|
|
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."
|
|
fi
|
|
exit 1
|
|
fi
|
|
|
|
git add jslib
|
|
git commit -m "Bump jslib"
|
|
|
|
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"
|
|
|
|
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 "[Bot] Bump jslib" \
|
|
--body "$BODY_TEXT" \
|
|
--reviewer bitwarden/dept-engineering
|
|
echo "[*] Submitted PR against master branch"
|
|
else
|
|
gh pr comment --body "$BODY_TEXT"
|
|
echo "[*] Updated existing PR"
|
|
fi
|
|
env:
|
|
OLD_JSLIB_HASH: ${{ steps.bump.outputs.old-jslib-hash }}
|
|
EXISTING_PR: ${{ steps.bump.outputs.existing-pr }}
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|