Skip to content

Commit 4219b00

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

File tree

4 files changed

+153
-41
lines changed

4 files changed

+153
-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

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Update Licenses on Dependency Changes
2+
3+
on:
4+
push:
5+
branches:
6+
- "**"
7+
pull_request:
8+
branches:
9+
- "**"
10+
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
actions: write
15+
16+
jobs:
17+
update-licenses:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0 # Fetch all history for proper branch tracking
25+
26+
- name: Set up pnpm
27+
uses: pnpm/action-setup@v4
28+
29+
- name: Set up Node.js
30+
uses: actions/setup-node@v4
31+
with:
32+
node-version: "lts/*"
33+
cache: pnpm
34+
35+
- name: Install dependencies
36+
run: pnpm install --frozen-lockfile
37+
38+
- name: Generate licenses.json
39+
run: |
40+
pnpm add -g license-checker
41+
license-checker --json > licenses.json
42+
43+
- name: Display licenses.json content
44+
run: cat licenses.json
45+
46+
- name: Commit and Push Updated Licenses
47+
env:
48+
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
49+
run: |
50+
git config --global user.name "github-actions[bot]"
51+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
52+
53+
BRANCH_NAME="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME:-$(git rev-parse --abbrev-ref HEAD)}}"
54+
echo "Working on branch: $BRANCH_NAME"
55+
56+
# Fetch latest changes from the remote repository
57+
git fetch origin $BRANCH_NAME
58+
59+
# Ensure we are on the correct branch
60+
git checkout -B $BRANCH_NAME origin/$BRANCH_NAME
61+
62+
# Reset any local changes to match remote branch
63+
git reset --hard origin/$BRANCH_NAME
64+
65+
# Stage the updated licenses.json
66+
git add licenses.json
67+
68+
if ! git diff --cached --quiet; then
69+
git commit -m "chore: Update licenses.json"
70+
71+
# Explicitly set upstream branch to avoid stale refs
72+
git branch --set-upstream-to=origin/$BRANCH_NAME
73+
74+
# Force push with lease (safe force push)
75+
git push --force-with-lease https://x-access-token:${PERSONAL_ACCESS_TOKEN}@github.com/${{ github.repository }} HEAD:$BRANCH_NAME
76+
else
77+
echo "No changes to commit."
78+
fi
79+
80+
- name: Verify Commit
81+
run: git log -n 3 --oneline
82+
83+
- name: Trigger test-and-build Workflow
84+
env:
85+
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
86+
run: |
87+
curl -X POST \
88+
-H "Authorization: token ${PERSONAL_ACCESS_TOKEN}" \
89+
-H "Accept: application/vnd.github.v3+json" \
90+
https://api.github.com/repos/${{ github.repository }}/dispatches \
91+
-d '{"event_type": "trigger-test-and-build"}'

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)