-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from conjure-cp/Github-Action-dependency-check
Added NPM dependency check GitHub Actions workflow
- Loading branch information
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
name: Check for outdated NPM dependencies | ||
|
||
on: | ||
push: | ||
branches: | ||
- main # 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'); | ||
try { | ||
execSync('npm update'); | ||
execSync('git config --global user.name "GitHub Actions"'); | ||
execSync('git config --global user.email "actions@github.com"'); | ||
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, | ||
}); |