Skip to content

Commit b19798b

Browse files
Copilotjyxjjjxrgzs
authored
feat(actions): automated NPM resource updates (#22)
* feat: add GitHub Actions workflow for automated NPM resource updates Agent-Logs-Url: https://github.com/OpenListTeam/OpenList-Resource/sessions/b444190d-7929-4aa8-a280-244eca105660 Co-authored-by: jyxjjj <16695261+jyxjjj@users.noreply.github.com> * plan: split single workflow into per-package workflow files Agent-Logs-Url: https://github.com/OpenListTeam/OpenList-Resource/sessions/b444190d-7929-4aa8-a280-244eca105660 Co-authored-by: jyxjjj <16695261+jyxjjj@users.noreply.github.com> * refactor: split into per-package workflow files for easy contribution Agent-Logs-Url: https://github.com/OpenListTeam/OpenList-Resource/sessions/b444190d-7929-4aa8-a280-244eca105660 Co-authored-by: jyxjjj <16695261+jyxjjj@users.noreply.github.com> * fix: use find instead of glob wildcard for safer file copy Agent-Logs-Url: https://github.com/OpenListTeam/OpenList-Resource/sessions/b444190d-7929-4aa8-a280-244eca105660 Co-authored-by: jyxjjj <16695261+jyxjjj@users.noreply.github.com> * chore: update actions/checkout and actions/setup-node from v4 to v6 Agent-Logs-Url: https://github.com/OpenListTeam/OpenList-Resource/sessions/3d8b51c0-1dfe-40cd-9c17-204277cb22ff Co-authored-by: jyxjjj <16695261+jyxjjj@users.noreply.github.com> * refactor: consolidate workflows into reusable workflow_call pattern Agent-Logs-Url: https://github.com/OpenListTeam/OpenList-Resource/sessions/fc9914a6-773d-4fe1-8dab-fc3532f6c27d Co-authored-by: xrgzs <26499123+xrgzs@users.noreply.github.com> * fix: add explicit permissions to reusable workflow for defense-in-depth Agent-Logs-Url: https://github.com/OpenListTeam/OpenList-Resource/sessions/fc9914a6-773d-4fe1-8dab-fc3532f6c27d Co-authored-by: xrgzs <26499123+xrgzs@users.noreply.github.com> * chore(actions): upgrade node 20 to 24 Co-authored-by: MadDogOwner <xiaoran@xrgzs.top> Signed-off-by: ShenLin <773933146@qq.com> * fix: remove update-pdfjs.yaml (manual sync) and delete index.html for GenerateDirectoryTree Agent-Logs-Url: https://github.com/OpenListTeam/OpenList-Resource/sessions/0a0fa5b4-629d-4519-b73c-dfab8db142b2 Co-authored-by: xrgzs <26499123+xrgzs@users.noreply.github.com> * fix: check for changes before deleting index.html to avoid false has_changes=true Agent-Logs-Url: https://github.com/OpenListTeam/OpenList-Resource/sessions/aaf5d3d8-0654-4e82-90f6-792fc6f28000 Co-authored-by: xrgzs <26499123+xrgzs@users.noreply.github.com> * refactor: remove workflow_display_name input, use inputs.npm_package in PR body Agent-Logs-Url: https://github.com/OpenListTeam/OpenList-Resource/sessions/55d67a67-ef82-478c-8676-a776685a0f3d Co-authored-by: xrgzs <26499123+xrgzs@users.noreply.github.com> --------- Signed-off-by: ShenLin <773933146@qq.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jyxjjj <16695261+jyxjjj@users.noreply.github.com> Co-authored-by: xrgzs <26499123+xrgzs@users.noreply.github.com> Co-authored-by: ShenLin <773933146@qq.com> Co-authored-by: MadDogOwner <xiaoran@xrgzs.top>
1 parent c9df062 commit b19798b

8 files changed

Lines changed: 250 additions & 1 deletion

.github/workflows/GenerateDirectoryTree.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
steps:
1515
- name: Checkout code
16-
uses: actions/checkout@v4
16+
uses: actions/checkout@v6
1717
with:
1818
fetch-depth: 0 # 获取完整的仓库历史
1919

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Reusable workflow for updating vendored NPM packages.
2+
# Caller workflows only need to define schedule/dispatch triggers,
3+
# the three package identifiers, and a custom extract script.
4+
#
5+
# To add a new package, create a thin caller workflow — see any update-*.yaml for an example.
6+
7+
name: Reusable NPM Update
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
on:
14+
workflow_call:
15+
inputs:
16+
npm_package:
17+
description: 'NPM package name (e.g. exceljs, @ruffle-rs/ruffle)'
18+
required: true
19+
type: string
20+
target_dir:
21+
description: 'Target directory in the repo to vendor files into'
22+
required: true
23+
type: string
24+
branch_name:
25+
description: 'Branch name for the auto-update PR (e.g. auto-update/exceljs)'
26+
required: true
27+
type: string
28+
extract_script:
29+
description: 'Shell script to extract/copy files from $PKG_DIR into $TARGET_DIR'
30+
required: true
31+
type: string
32+
33+
jobs:
34+
update:
35+
runs-on: ubuntu-latest
36+
env:
37+
NPM_PACKAGE: ${{ inputs.npm_package }}
38+
TARGET_DIR: ${{ inputs.target_dir }}
39+
BRANCH_NAME: ${{ inputs.branch_name }}
40+
steps:
41+
- name: Checkout code
42+
uses: actions/checkout@v6
43+
44+
- name: Setup Node.js
45+
uses: actions/setup-node@v6
46+
with:
47+
node-version: '24'
48+
49+
- name: Fetch latest version
50+
id: fetch
51+
run: |
52+
LATEST=$(npm view "$NPM_PACKAGE" version 2>/dev/null)
53+
echo "version=$LATEST" >> "$GITHUB_OUTPUT"
54+
echo "Latest $NPM_PACKAGE version: $LATEST"
55+
56+
- name: Download and extract package
57+
run: |
58+
set -euo pipefail
59+
TMP=$(mktemp -d)
60+
cd "$TMP"
61+
npm pack "$NPM_PACKAGE" > /dev/null 2>&1
62+
mkdir -p extracted
63+
tar -xzf *.tgz -C extracted
64+
cd -
65+
echo "PKG_DIR=$TMP/extracted/package" >> "$GITHUB_ENV"
66+
67+
- name: Extract files
68+
run: |
69+
set -euo pipefail
70+
${{ inputs.extract_script }}
71+
72+
- name: Check for changes
73+
id: changes
74+
run: |
75+
if [[ -n $(git status --porcelain) ]]; then
76+
echo "has_changes=true" >> "$GITHUB_OUTPUT"
77+
else
78+
echo "has_changes=false" >> "$GITHUB_OUTPUT"
79+
echo "No changes detected."
80+
fi
81+
82+
- name: Remove index.html for GenerateDirectoryTree regeneration
83+
if: steps.changes.outputs.has_changes == 'true'
84+
run: |
85+
find "$TARGET_DIR" -name 'index.html' -exec rm -f {} + 2>/dev/null || true
86+
87+
- name: Create Pull Request
88+
if: steps.changes.outputs.has_changes == 'true'
89+
uses: peter-evans/create-pull-request@v7
90+
with:
91+
token: ${{ secrets.GITHUB_TOKEN }}
92+
commit-message: 'chore: update ${{ inputs.npm_package }} to ${{ steps.fetch.outputs.version }}'
93+
branch: ${{ inputs.branch_name }}
94+
delete-branch: true
95+
title: 'chore: update `${{ inputs.npm_package }}` to ${{ steps.fetch.outputs.version }}'
96+
body: |
97+
## Automated Update
98+
99+
| Package | Version | Directory |
100+
|---------|---------|-----------|
101+
| `${{ inputs.npm_package }}` | `${{ steps.fetch.outputs.version }}` | `${{ inputs.target_dir }}/` |
102+
103+
---
104+
_Auto-generated by updating **`${{ inputs.npm_package }}`**. Please review before merging._
105+
labels: |
106+
automated
107+
dependencies
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: 'Update: docxjs (docx-preview)'
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * 1'
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
update:
14+
uses: ./.github/workflows/reusable-update-npm.yaml
15+
secrets: inherit
16+
with:
17+
npm_package: docx-preview
18+
target_dir: docxjs
19+
branch_name: auto-update/docxjs
20+
extract_script: |
21+
# Full package copy — replace entire directory contents
22+
find "$TARGET_DIR" -mindepth 1 -exec rm -rf {} + 2>/dev/null || true
23+
mkdir -p "$TARGET_DIR"
24+
cp -r "$PKG_DIR"/* "$TARGET_DIR/"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: 'Update: exceljs'
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * 1'
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
update:
14+
uses: ./.github/workflows/reusable-update-npm.yaml
15+
secrets: inherit
16+
with:
17+
npm_package: exceljs
18+
target_dir: exceljs
19+
branch_name: auto-update/exceljs
20+
extract_script: |
21+
mkdir -p "$TARGET_DIR"
22+
# Only copy the minified bundle
23+
cp "$PKG_DIR/dist/exceljs.min.js" "$TARGET_DIR/exceljs.min.js"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: 'Update: jszip'
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * 1'
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
update:
14+
uses: ./.github/workflows/reusable-update-npm.yaml
15+
secrets: inherit
16+
with:
17+
npm_package: jszip
18+
target_dir: jszip
19+
branch_name: auto-update/jszip
20+
extract_script: |
21+
mkdir -p "$TARGET_DIR"
22+
# Only copy the minified bundle
23+
cp "$PKG_DIR/dist/jszip.min.js" "$TARGET_DIR/jszip.min.js"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: 'Update: libass-wasm'
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * 1'
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
update:
14+
uses: ./.github/workflows/reusable-update-npm.yaml
15+
secrets: inherit
16+
with:
17+
npm_package: libass-wasm
18+
target_dir: libass-wasm
19+
branch_name: auto-update/libass-wasm
20+
extract_script: |
21+
# Replace directory with dist/js/* files (worker scripts + wasm)
22+
find "$TARGET_DIR" -mindepth 1 -exec rm -rf {} + 2>/dev/null || true
23+
mkdir -p "$TARGET_DIR"
24+
find "$PKG_DIR/dist/js" -maxdepth 1 -type f -exec cp {} "$TARGET_DIR/" \;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: 'Update: libheif (libheif-js)'
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * 1'
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
update:
14+
uses: ./.github/workflows/reusable-update-npm.yaml
15+
secrets: inherit
16+
with:
17+
npm_package: libheif-js
18+
target_dir: libheif
19+
branch_name: auto-update/libheif
20+
extract_script: |
21+
# Replace directory with libheif-wasm/* files (wasm bundle + types)
22+
find "$TARGET_DIR" -mindepth 1 -exec rm -rf {} + 2>/dev/null || true
23+
mkdir -p "$TARGET_DIR"
24+
find "$PKG_DIR/libheif-wasm" -maxdepth 1 -type f -exec cp {} "$TARGET_DIR/" \;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: 'Update: ruffle (@ruffle-rs/ruffle)'
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * 1'
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
update:
14+
uses: ./.github/workflows/reusable-update-npm.yaml
15+
secrets: inherit
16+
with:
17+
npm_package: '@ruffle-rs/ruffle'
18+
target_dir: ruffle
19+
branch_name: auto-update/ruffle
20+
extract_script: |
21+
# Full package copy — replace entire directory contents
22+
find "$TARGET_DIR" -mindepth 1 -exec rm -rf {} + 2>/dev/null || true
23+
mkdir -p "$TARGET_DIR"
24+
cp -r "$PKG_DIR"/* "$TARGET_DIR/"

0 commit comments

Comments
 (0)