Skip to content

Commit 1b1a687

Browse files
Add workflow to run npm audit fix (#159)
* Add workflow to run npm audit fix * Tweak
1 parent 666b149 commit 1b1a687

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: autorun-npm-audit-fix
2+
run-name: Automatically run npm audit fix
3+
on:
4+
schedule:
5+
- cron: '45 05 * * WED'
6+
- cron: '30 20 * * MON'
7+
jobs:
8+
autorun-npm-audit-fix:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write
12+
defaults:
13+
run:
14+
shell: bash
15+
working-directory: ./
16+
steps:
17+
- name: Check out repository
18+
uses: actions/checkout@v4
19+
- name: Set up node
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '18'
23+
- name: Run npm audit fix
24+
run: |
25+
echo "Running npm audit fix"
26+
npm audit fix
27+
- name: Get whether autorun-npm-audit-fix branch exists
28+
run: |
29+
echo "Getting whether autorun-npm-audit-fix branch exists"
30+
git config user.name github-actions
31+
git config user.email github-actions@github.com
32+
{
33+
echo 'git_ls_remote_origin_autorun_npm_audit_fix<<EOF'
34+
git ls-remote origin autorun-npm-audit-fix
35+
echo EOF
36+
} >> "$GITHUB_OUTPUT"
37+
id: run_git_ls_remote_origin_autorun_npm_audit_fix
38+
- name: Delete autorun-npm-audit-fix if it exists
39+
if: ${{ contains(steps.run_git_ls_remote_origin_autorun_npm_audit_fix.outputs.git_ls_remote_origin_autorun_npm_audit_fix, '/autorun-npm-audit-fix') }}
40+
run: |
41+
echo "Deleting remote autorun-npm-audit-fix branch"
42+
git push origin --delete autorun-npm-audit-fix
43+
- name: Add any changes
44+
run: |
45+
echo "Determining if there are any changes"
46+
git config user.name github-actions
47+
git config user.email github-actions@github.com
48+
git checkout -b autorun-npm-audit-fix
49+
git add ../.
50+
- name: Run git status
51+
run: |
52+
{
53+
echo 'git_status<<EOF'
54+
git status
55+
echo EOF
56+
} >> "$GITHUB_OUTPUT"
57+
id: run_git_status
58+
- name: Commit and push changes if any
59+
if: ${{ !contains(steps.run_git_status.outputs.git_status, 'nothing to commit, working tree clean') }}
60+
run: |
61+
echo "Committing and pushing changes to autorun-npm-audit-fix branch"
62+
git commit -m "Automatically run npm audit fix"
63+
git push --set-upstream origin autorun-npm-audit-fix

0 commit comments

Comments
 (0)