-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (116 loc) · 4.86 KB
/
auto-bump-version.yaml
File metadata and controls
137 lines (116 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: Auto Bump Version on Merge to main
on:
pull_request:
types: [closed]
permissions:
contents: write
jobs:
bump-version:
if: >
github.event.pull_request.merged == true &&
github.event.pull_request.base.ref == 'main' &&
github.actor != 'github-actions[bot]'
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@v4
with:
ref: main
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Detect if package.json version changed in PR
id: ver_changed
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request.number;
const files = await github.paginate(github.rest.pulls.listFiles, {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr,
per_page: 100
});
const touched = files.some(f => f.filename === 'package.json' && /"version"\s*:/.test(f.patch || ''));
core.setOutput('changed', touched ? 'true' : 'false');
- name: Bump patch version (+0.0.1) if not changed in PR
if: steps.ver_changed.outputs.changed != 'true'
run: |
node -e "
const fs = require('fs');
const pr_title = context.payload.pull_request.title;
const pkg = JSON.parse(fs.readFileSync('package.json','utf8'));
const [a,b,c] = pkg.version.split('.').map(Number);
let new_version;
if (pr_title.toLowerCase().startsWith('feat')) {
new_version = [a,b+1,0].join('.');
} else {
new_version = [a,b,c+1].join('.');
}
pkg.version = new_version;
fs.writeFileSync('package.json', JSON.stringify(pkg,null,2)+'\n');
console.log('Bumped to', pkg.version);
"
- name: Install dependencies
run: npm ci
- name: Sync exports to src/shared/index.ts (Revised)
run: |
node -e "
const fs = require('fs');
const path = require('path');
const root = 'src/shared';
const indexPath = path.join(root, 'index.ts');
const indexContent = fs.existsSync(indexPath) ? fs.readFileSync(indexPath,'utf8') : '';
const existingExports = new Set((indexContent.match(/from\\s+['\\\"](\\.\\/|\\.\\.\\/)([^'\\\"]+)['\\\"]/g) || [])
.map(line => line.match(/from\\s+['\\\"]([^'\\\"]+)['\\\"]/)[1]));
const adds = [];
const uiRoot = path.join(root, 'ui');
const componentFiles = [];
if (fs.existsSync(uiRoot)) {
fs.readdirSync(uiRoot, { withFileTypes: true })
.filter(d => d.isDirectory())
.forEach(dir => {
const dirPath = path.join(uiRoot, dir.name);
const innerItems = fs.readdirSync(dirPath, { withFileTypes: true });
for (const item of innerItems) {
if (item.isFile() && (item.name.endsWith('.ts') || item.name.endsWith('.tsx')) && item.name !== 'index.ts') {
componentFiles.push(path.join(dir.name, item.name));
}
});
}
for (const relativeFilePath of componentFiles) {
const componentName = path.basename(relativeFilePath, path.extname(relativeFilePath));
const exportPath = './ui/' + relativeFilePath.replace(path.extname(relativeFilePath), '');
if (existingExports.has(exportPath)) {
continue;
}
const line = \`export { \${componentName} } from '\${exportPath}'\`;
adds.push(line);
}
if (adds.length) {
const next = (indexContent.trim() ? indexContent.trim()+'\\n' : '') + adds.join(';\\n') + ';\\n';
fs.writeFileSync(indexPath, next);
console.log('Added exports to index.ts:', adds);
} else {
console.log('No new files found to export.');
}
"
- name: Build package
run: npm run build
- name: Commit & Push
run: |
if git diff --quiet; then
echo "No changes to commit."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add package.json src/shared/index.ts || true
git commit -m "chore: bump version and sync shared exports [skip ci]"
git push
- name: Publish to npm
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}