⏫ Bot — Dependencies #167
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Groups minor and patch dependency updates into a single PR. | |
name: '⏫ Bot — Dependencies' | |
on: | |
schedule: | |
- cron: '0 15 * * 1-5' | |
workflow_dispatch: | |
env: | |
TITLE: 'chore: update dependencies' | |
BRANCH: 'deps' | |
PACKAGE_PATH: '.' | |
BODY: '- 🤖 Update project dependencies' | |
LABELS: | | |
dependencies | |
jobs: | |
update-deps: | |
runs-on: ubuntu-latest | |
if: github.event.repository.fork == false | |
name: Update | |
steps: | |
- name: ➕ Actions - Checkout | |
uses: actions/checkout@v4 | |
- name: ➕ Actions - Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '22.x' | |
- name: ➕ Cache dependencies | |
uses: actions/cache@v4 | |
with: | |
path: ~/.npm | |
key: npm-linux-${{ hashFiles('package-lock.json') }} | |
restore-keys: npm-linux- | |
- name: 🔒 Checking if branch is main | |
run: | | |
MAIN_BRANCH=$(git remote show origin | grep 'HEAD branch' | awk '{print $NF}') | |
if [ "${{ env.BRANCH }}" = "$MAIN_BRANCH" ]; then | |
exit 1 | |
fi | |
- name: 📦 Installing Dependencies | |
run: cd ${{ env.PACKAGE_PATH }} && npm ci | |
- name: ⏫ Updating Dependencies | |
run: cd ${{ env.PACKAGE_PATH }} && npm run update | |
- name: ⚙️ Configuring Git | |
run: | | |
git config --global user.name 'wellwelwel' | |
git config --global user.email '46850407+wellwelwel@users.noreply.github.com' | |
git update-index --refresh > /dev/null 2>&1 || true | |
- name: 🔎 Checking for Changes | |
id: check_changes | |
run: | | |
if git diff-index --quiet HEAD --; then | |
echo "changes=false" >> $GITHUB_OUTPUT | |
else | |
echo "changes=true" >> $GITHUB_OUTPUT | |
fi | |
- name: 🗑️ Deleting Branch | |
if: steps.check_changes.outputs.changes == 'true' | |
run: | | |
curl -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
https://api.github.com/repos/${{ github.repository }}/git/refs/heads/${{ env.BRANCH }} || true | |
- name: 🚀 Commiting and Pushing Changes | |
if: steps.check_changes.outputs.changes == 'true' | |
run: | | |
git add . | |
git commit -m "${{ env.TITLE }}" | |
git push origin HEAD:refs/heads/${{ env.BRANCH }} --force | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT }} | |
- name: 🧙🏻 Creating Pull Request | |
if: steps.check_changes.outputs.changes == 'true' | |
uses: peter-evans/create-pull-request@v6 | |
with: | |
token: ${{ secrets.PAT }} | |
branch: ${{ env.BRANCH }} | |
title: '${{ env.TITLE }}' | |
body: ${{ env.BODY }} | |
labels: ${{ env.LABELS }} | |
delete-branch: true |