Skip to content

Commit 435b51a

Browse files
committed
feat: refactor version update process in GitHub Actions workflow to improve package.json handling
1 parent 002907e commit 435b51a

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

.github/workflows/publish.yml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,6 @@ jobs:
9999
fs.writeFileSync('package.json', JSON.stringify(package, null, 2) + '\n');
100100
"
101101
102-
- name: Commit version update
103-
if: github.event_name == 'workflow_dispatch'
104-
run: |
105-
git config user.name 'github-actions[bot]'
106-
git config user.email 'github-actions[bot]@users.noreply.github.com'
107-
git add package.json
108-
git commit -m "chore: update package.json version to ${{ steps.new_version.outputs.version }}"
109-
git push
110-
111102
- name: Get Package Version
112103
id: package_version
113104
run: |
@@ -126,6 +117,24 @@ jobs:
126117
fi
127118
echo "version=${VERSION}" >> $GITHUB_OUTPUT
128119
120+
- name: Update package.json with version
121+
run: |
122+
# Use node to update package.json to preserve formatting
123+
node -e "
124+
const fs = require('fs');
125+
const package = JSON.parse(fs.readFileSync('package.json'));
126+
package.version = '${{ steps.package_version.outputs.version }}';
127+
fs.writeFileSync('package.json', JSON.stringify(package, null, 2) + '\n');
128+
"
129+
130+
- name: Commit version update
131+
run: |
132+
git config user.name 'github-actions[bot]'
133+
git config user.email 'github-actions[bot]@users.noreply.github.com'
134+
git add package.json
135+
git commit -m "chore: update package.json version to ${{ steps.package_version.outputs.version }}"
136+
git push
137+
129138
- name: Create Release
130139
env:
131140
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)