Skip to content

Commit 7fd5920

Browse files
authored
chore(ci): enable automatic audit fix pull requests (#125)
1 parent 33c4fa1 commit 7fd5920

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Audit fix Auto-merge
2+
3+
on:
4+
pull_request:
5+
branches: ["main"]
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
11+
jobs:
12+
auto-merge:
13+
name: Auto-merge audit fix pull requests
14+
runs-on: ubuntu-latest
15+
if: "contains(github.event.pull_request.labels.*.name, 'audit: fix')"
16+
steps:
17+
- name: Approve
18+
run: gh pr review "$PR_URL" --approve --comment --body "Auto-approve audit fix pull requests"
19+
env:
20+
PR_URL: ${{ github.event.pull_request.html_url }}
21+
GH_TOKEN: ${{ secrets.LOCALSTACK_BOT_TOKEN }}
22+
- name: Enable auto-merge
23+
run: gh pr merge "$PR_URL" --auto --squash
24+
env:
25+
PR_URL: ${{ github.event.pull_request.html_url }}
26+
GH_TOKEN: ${{ secrets.LOCALSTACK_BOT_TOKEN }}

.github/workflows/audit-fix.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Audit fix
2+
3+
on:
4+
schedule:
5+
- cron: '0 9 * * *'
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
audit-fix:
14+
name: Run npm audit fix and create pull request
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v5
19+
20+
- name: Setup Node
21+
uses: actions/setup-node@v4
22+
with:
23+
cache: npm
24+
25+
- name: Install dependencies
26+
run: npm ci
27+
28+
- name: Run npm audit fix
29+
run: npm audit fix --force
30+
31+
- name: Create pull request
32+
env:
33+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
GH_REPO: ${{ github.repository }}
35+
run: |
36+
if git diff --quiet; then
37+
echo "No changes after npm audit fix, skipping PR creation"
38+
exit 0
39+
fi
40+
41+
BRANCH="npm-audit-fix-$(date +%Y%m%d)"
42+
git config user.name "github-actions[bot]"
43+
git config user.email "github-actions[bot]@users.noreply.github.com"
44+
git checkout -b "$BRANCH"
45+
git add package.json package-lock.json
46+
git commit -m "chore(deps): npm audit fix"
47+
git push origin "$BRANCH"
48+
49+
gh pr create \
50+
--title "chore(deps): npm audit fix" \
51+
--body "Automated security fixes via \`npm audit fix --force\`." \
52+
--label "audit: fix" \
53+
--base main \
54+
--head "$BRANCH"

0 commit comments

Comments
 (0)