Skip to content

Commit 3715c74

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

File tree

4 files changed

+133
-41
lines changed

4 files changed

+133
-41
lines changed

.github/workflows/general-ci.yml

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
name: General CI Workflow
22

33
on:
4+
push:
5+
branches:
6+
- "**"
7+
48
pull_request:
59
branches:
6-
- master
10+
- "**"
711

812
jobs:
913
test-and-build:
@@ -32,3 +36,20 @@ jobs:
3236

3337
- name: Build the project
3438
run: pnpm build
39+
40+
- name: Trigger Update Licenses Workflow
41+
env:
42+
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
43+
run: |
44+
echo "Triggering Update Licenses Workflow for branch: ${{ github.ref_name }}"
45+
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
46+
-H "Authorization: token ${PERSONAL_ACCESS_TOKEN}" \
47+
-H "Accept: application/vnd.github.v3+json" \
48+
https://api.github.com/repos/${{ github.repository }}/dispatches \
49+
-d '{"event_type": "trigger-update-licenses", "client_payload": {"branch": "${{ github.ref_name }}"}}')
50+
51+
echo "Dispatch Event Response: $RESPONSE"
52+
if [ "$RESPONSE" -ne 204 ]; then
53+
echo "Failed to trigger the workflow"
54+
exit 1
55+
fi

.github/workflows/update-licenses.yml

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

package.json

+1-1
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",

0 commit comments

Comments
 (0)