Skip to content

Commit 753c11a

Browse files
Generate license.json via GitHub Actions after deps updates (#38)
1 parent 259e4be commit 753c11a

File tree

3 files changed

+108
-40
lines changed

3 files changed

+108
-40
lines changed

.github/workflows/update-licenses.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Update Licenses on Dependency Changes
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- "licenses.json"
9+
10+
pull_request:
11+
branches:
12+
- master
13+
paths:
14+
- "package.json"
15+
- "pnpm-lock.yaml"
16+
types:
17+
- opened
18+
- synchronize
19+
- reopened
20+
21+
permissions:
22+
contents: write
23+
pull-requests: write
24+
25+
jobs:
26+
update-licenses:
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- name: Checkout code
31+
uses: actions/checkout@v4
32+
with:
33+
ref: ${{ github.event.pull_request.head.ref || 'master' }}
34+
35+
- name: Set up pnpm
36+
uses: pnpm/action-setup@v4
37+
38+
- name: Set up Node.js
39+
uses: actions/setup-node@v4
40+
with:
41+
node-version: "lts/*"
42+
cache: pnpm
43+
44+
- name: Install dependencies
45+
run: pnpm install --frozen-lockfile
46+
47+
- name: Generate licenses.json
48+
run: |
49+
pnpm add -g license-checker
50+
license-checker --json > licenses.json
51+
52+
- name: Display licenses.json content
53+
run: cat licenses.json
54+
55+
- name: Commit and push updated licenses
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
run: |
59+
git config --global user.name "github-actions[bot]"
60+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
61+
git add licenses.json
62+
if ! git diff --cached --quiet; then
63+
git commit -m "chore: Update licenses.json"
64+
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}
65+
git push origin HEAD:${{ github.event.pull_request.head.ref || 'master' }}
66+
else
67+
echo "No changes to commit."
68+
fi

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@swc/core": "^1.10.12",
2424
"@swc/helpers": "^0.5.15",
2525
"@types/jest": "^29.5.14",
26-
"@types/node": "^22.12.0",
26+
"@types/node": "^22.13.0",
2727
"jest": "^29.7.0",
2828
"nodemon": "^3.1.9",
2929
"rimraf": "^6.0.1",

pnpm-lock.yaml

Lines changed: 39 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)