Skip to content

Commit 90ef4da

Browse files
committed
ci: auto-sync package.json description from README on every push to main
1 parent 4682ef1 commit 90ef4da

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

.github/workflows/publish-release.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,33 @@ jobs:
3333
echo "published=false" >> "$GITHUB_OUTPUT"
3434
fi
3535
36+
- name: Sync package.json description from README
37+
run: |
38+
DESC=$(node -e "
39+
const fs = require('fs');
40+
const lines = fs.readFileSync('README.md','utf-8').split('\n');
41+
for (const line of lines) {
42+
const t = line.trim();
43+
if (!t || t.startsWith('#') || t.startsWith('[') || t.startsWith('http') || t.startsWith('![')) continue;
44+
console.log(t.replace(/[*_\`]/g,'').replace(/\s+/g,' ').trim());
45+
break;
46+
}
47+
")
48+
PKG_DESC=$(node -p "require('./package.json').description")
49+
if [ "$DESC" != "$PKG_DESC" ]; then
50+
node -e "
51+
const fs = require('fs');
52+
const pkg = JSON.parse(fs.readFileSync('package.json','utf-8'));
53+
pkg.description = process.argv[1];
54+
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
55+
" "$DESC"
56+
git config user.name "github-actions[bot]"
57+
git config user.email "github-actions[bot]@users.noreply.github.com"
58+
git add package.json
59+
git commit -m "chore: sync package.json description from README"
60+
git push
61+
fi
62+
3663
- name: Build and publish
3764
if: steps.check.outputs.published == 'false'
3865
run: pnpm build && npm publish --access public

0 commit comments

Comments
 (0)