Skip to content

Instantly share code, notes, and snippets.

@PrinOrange
Created May 23, 2024 03:02
Show Gist options
  • Save PrinOrange/d222b0acde1c37079d0fc195f032dcee to your computer and use it in GitHub Desktop.
Save PrinOrange/d222b0acde1c37079d0fc195f032dcee to your computer and use it in GitHub Desktop.
Update npm dependencies (pr)
name: Update Dependencies
on:
schedule:
# 每周一凌晨 2 点运行
- cron: "0 2 * * MON"
workflow_dispatch: # 允许手动触发
jobs:
update-dependencies:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "16" # 这里可以设置你需要的 Node.js 版本
- name: Install npm dependencies
run: npm install
- name: Update npm dependencies
run: npm update
- name: Create branch for updates
run: |
git checkout -b update-dependencies-$(date +%Y%m%d)
- name: Commit updated dependencies
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add package-lock.json package.json
git commit -m 'chore: weekly npm dependencies update' || echo "No changes to commit"
- name: Push changes
uses: ad-m/github-push-action@v0.6.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: update-dependencies-$(date +%Y%m%d)
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: update-dependencies-$(date +%Y%m%d)
title: "chore: weekly npm dependencies update"
body: "This is an automated pull request to update the npm dependencies to their latest versions."
labels: "dependencies, automated pr"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment