Skip to content

Commit 6007ac4

Browse files
Configure Dependabot for dependency updates (#16) (#17)
* Configure Dependabot for dependency updates (#16) * Add packageManager to package.json
1 parent 7c72aac commit 6007ac4

File tree

4 files changed

+164
-0
lines changed

4 files changed

+164
-0
lines changed

.github/dependabot.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "npm"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
7+
commit-message:
8+
prefix: "deps"
9+
open-pull-requests-limit: 5
10+
labels:
11+
- "dependencies"
12+
allow:
13+
- dependency-type: "all"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Dependabot Auto Merge and Resolve Lockfile Conflicts
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
types:
8+
- opened
9+
- synchronize
10+
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
15+
jobs:
16+
resolve-conflicts:
17+
if: github.event.pull_request.user.login == 'dependabot[bot]'
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
with:
24+
ref: ${{ github.event.pull_request.head.ref }}
25+
26+
- name: Set up Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: "lts/*"
30+
cache: pnpm
31+
32+
- name: Install pnpm
33+
uses: pnpm/action-setup@v4
34+
35+
- name: Check for lockfile conflicts
36+
id: check-conflict
37+
run: |
38+
if git diff --name-only | grep 'pnpm-lock.yaml'; then
39+
echo "Lockfile conflict detected."
40+
echo "conflict=true" >> $GITHUB_ENV
41+
else
42+
echo "No lockfile conflict."
43+
echo "conflict=false" >> $GITHUB_ENV
44+
fi
45+
46+
- name: Resolve lockfile conflict
47+
if: env.conflict == 'true'
48+
run: |
49+
echo "Deleting pnpm-lock.yaml..."
50+
rm pnpm-lock.yaml
51+
echo "Reinstalling dependencies..."
52+
pnpm install
53+
54+
- name: Commit and push updated lockfile
55+
if: env.conflict == 'true'
56+
run: |
57+
git config --global user.name "dependabot-bot"
58+
git config --global user.email "[email protected]"
59+
git add pnpm-lock.yaml
60+
git commit -m "fix: Resolve pnpm-lock.yaml conflicts"
61+
git push origin ${{ github.event.pull_request.head.ref }}
62+
63+
auto-merge:
64+
needs: resolve-conflicts
65+
if: github.event.pull_request.user.login == 'dependabot[bot]' && github.job == 'resolve-conflicts' && github.event.pull_request.head.ref != 'null'
66+
runs-on: ubuntu-latest
67+
68+
steps:
69+
- name: Fetch Dependabot metadata
70+
id: metadata
71+
uses: dependabot/fetch-metadata@v1
72+
with:
73+
github-token: "${{ secrets.GITHUB_TOKEN }}"
74+
75+
- name: Enable auto-merge for Dependabot PRs
76+
run: gh pr merge --auto --merge "$PR_URL"
77+
env:
78+
PR_URL: ${{ github.event.pull_request.html_url }}
79+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/general-ci.yml

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Dependabot Auto Merge and Resolve Lockfile Conflicts
2+
3+
on:
4+
push:
5+
branches:
6+
- dependabot/**
7+
8+
jobs:
9+
resolve-conflicts:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: "lts/*"
20+
21+
- name: Install pnpm
22+
run: npm install -g pnpm
23+
24+
- name: Install dependencies
25+
run: pnpm install
26+
27+
- name: Check for lockfile conflicts
28+
id: check-conflict
29+
run: |
30+
if git diff --name-only | grep 'pnpm-lock.yaml'; then
31+
echo "Lockfile conflict detected."
32+
echo "conflict=true" >> $GITHUB_ENV
33+
else
34+
echo "No lockfile conflict."
35+
echo "conflict=false" >> $GITHUB_ENV
36+
fi
37+
38+
- name: Resolve lockfile conflict
39+
if: env.conflict == 'true'
40+
run: |
41+
echo "Deleting pnpm-lock.yaml..."
42+
rm pnpm-lock.yaml
43+
echo "Reinstalling dependencies..."
44+
pnpm install
45+
46+
- name: Commit and push updated lockfile
47+
if: env.conflict == 'true'
48+
run: |
49+
git config --global user.name "dependabot-bot"
50+
git config --global user.email "[email protected]"
51+
git add pnpm-lock.yaml
52+
git commit -m "fix: Resolve pnpm-lock.yaml conflicts"
53+
git push origin HEAD:dependabot/${{ github.head_ref }}
54+
55+
auto-merge:
56+
needs: resolve-conflicts
57+
runs-on: ubuntu-latest
58+
if: github.event.pull_request.user.login == 'dependabot[bot]' && github.job == 'resolve-conflicts'
59+
60+
steps:
61+
- name: Fetch Dependabot metadata
62+
id: metadata
63+
uses: dependabot/fetch-metadata@v1
64+
with:
65+
github-token: "${{ secrets.GITHUB_TOKEN }}"
66+
67+
- name: Enable auto-merge for Dependabot PRs
68+
run: gh pr merge --auto --merge "$PR_URL"
69+
env:
70+
PR_URL: ${{ github.event.pull_request.html_url }}
71+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "fastify-swc-typescript-server",
3+
"packageManager": "[email protected]",
34
"version": "1.0.0",
45
"description": "A Fastify server leveraging SWC for transpilation and Jest for testing.",
56
"main": "dist/index.js",

0 commit comments

Comments
 (0)