Skip to content

Update dependency-check.yml #5

Update dependency-check.yml

Update dependency-check.yml #5

name: Check for outdated NPM dependencies
on:
push:
branches:
- fixing-ci # Run after every commit pushed to the main branch
schedule:
- cron: '0 0 * * 0' # Run once a week on Sunday at midnight
jobs:
update-dependency:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Install Dependencies
run: npm install
- name: Check for outdated dependencies
run: npm outdated
continue-on-error: true
- name: Check for changes
id: git-check
run: echo "::set-output name=status::$(git status --porcelain)"
- name: Update outdated dependencies and create PR
if: steps.git-check.outputs.status != ''
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { execSync } = require('child_process');
const github = require('@actions/github');
try {
execSync('npm update');
execSync('git config --global user.name "GitHub Actions"');
execSync('git config --global user.email "[email protected]"');
execSync('git add package-lock.json package.json');
execSync('git commit -m "Update outdated dependencies"');
execSync('git push');
} catch (error) {
console.log(error);
}
const octokit = github.getOctokit(process.env.GITHUB_TOKEN);
const base = "main";
const branch = "main";
const title = "Update NPM Dependencies";
const body = "Automatically update outdated NPM dependencies.";
const { data: pullRequest } = await octokit.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title,
body,
head: branch,
base,
});