Skip to content

Commit 0f62a24

Browse files
committed
ci: 优化 CI 配置
1 parent ed3dd72 commit 0f62a24

2 files changed

Lines changed: 73 additions & 51 deletions

File tree

.github/workflows/detect-deps.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Detect Deps
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- package.json
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
check:
16+
name: Check
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v6
22+
with:
23+
fetch-depth: 0
24+
fetch-tags: true
25+
ref: ${{ github.ref }}
26+
27+
- name: Detect
28+
run: |
29+
DEPS=("vitepress")
30+
TARGET_FILE="package.json"
31+
32+
if git rev-parse HEAD~1 >/dev/null 2>&1; then
33+
OLD_COMMIT="HEAD~1"
34+
else
35+
OLD_COMMIT="HEAD"
36+
fi
37+
38+
changed_list=()
39+
40+
echo "Target file: $TARGET_FILE"
41+
echo "Comparing with: $OLD_COMMIT"
42+
43+
for dep in "${DEPS[@]}"; do
44+
old_content=$(git show "$OLD_COMMIT":"$TARGET_FILE" 2>/dev/null || echo '{}')
45+
old_version=$(echo "$old_content" | jq -r --arg dep "$dep" '.dependencies[$dep] // .devDependencies[$dep] // empty')
46+
new_version=$(jq -r --arg dep "$dep" '.dependencies[$dep] // .devDependencies[$dep] // empty' "$TARGET_FILE")
47+
48+
echo "Checking $dep..."
49+
echo "Old: $old_version"
50+
echo "New: $new_version"
51+
52+
if [ "$old_version" != "$new_version" ]; then
53+
echo "➡ $dep version changed!"
54+
changed_list+=("$dep")
55+
fi
56+
done
57+
58+
if [ ${#changed_list[@]} -eq 0 ]; then
59+
echo "No dependencies changed. Stopping workflow."
60+
exit 1 # failure
61+
fi
62+
63+
echo "Changed dependencies: ${changed_list[*]}"
64+
65+
echo "Dependencies changed. Starting next workflow."
66+
exit 0 # success

.github/workflows/release.yml

Lines changed: 7 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,21 @@
1-
name: Release on Deps Change
1+
name: Release Project
22

33
on:
4-
push:
5-
branches:
6-
- master
7-
paths:
8-
- package.json
9-
- pnpm-lock.yaml
10-
workflow_dispatch: { }
4+
workflow_run:
5+
workflows: [ "Detect Deps" ]
6+
types:
7+
- completed
8+
workflow_dispatch:
119

1210
permissions:
1311
contents: write
1412
id-token: write
1513

1614
jobs:
17-
check:
18-
name: Check Deps Change
19-
runs-on: ubuntu-latest
20-
outputs:
21-
changed: ${{ steps.check.outputs.changed }}
22-
23-
steps:
24-
- name: Checkout
25-
uses: actions/checkout@v6
26-
with:
27-
fetch-depth: 0
28-
fetch-tags: true
29-
ref: ${{ github.ref }}
30-
31-
- name: Install pnpm
32-
uses: pnpm/action-setup@v6
33-
with:
34-
version: 10.33.0
35-
36-
- name: Install Node
37-
uses: actions/setup-node@v6
38-
with:
39-
node-version: 24.14.1
40-
registry-url: https://registry.npmjs.org/
41-
package-manager-cache: false
42-
43-
- name: Detect Deps version change
44-
id: check
45-
run: |
46-
old_version=$(git show HEAD^:package.json | jq -r '.devDependencies.vitepress // .dependencies.vitepress // empty')
47-
new_version=$(jq -r '.devDependencies.vitepress // .dependencies.vitepress // empty' package.json)
48-
49-
echo "Old Deps: $old_version"
50-
echo "New Deps: $new_version"
51-
52-
if [ "$old_version" != "$new_version" ]; then
53-
echo "changed=true" >> $GITHUB_OUTPUT
54-
else
55-
echo "changed=false" >> $GITHUB_OUTPUT
56-
fi
57-
5815
release:
5916
name: Release
60-
needs: check
61-
if: needs.check.outputs.changed == 'true'
6217
runs-on: ubuntu-latest
18+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
6319

6420
steps:
6521
- name: Checkout

0 commit comments

Comments
 (0)