Skip to content

Commit 70cde93

Browse files
authored
Merge pull request #105 from COW-dev/feat/#84
[FIX] pr생성 커밋 플로우 통합
2 parents 6d633a4 + 36196db commit 70cde93

File tree

2 files changed

+48
-121
lines changed

2 files changed

+48
-121
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Bump Version on Merge to main
1+
name: Bump Version and Publish
22

33
on:
44
pull_request:
@@ -7,9 +7,11 @@ on:
77

88
permissions:
99
contents: write
10+
pull-requests: write
11+
packages: write
1012

1113
jobs:
12-
bump-version:
14+
bump-and-publish:
1315
if: >
1416
github.event.pull_request.merged == true &&
1517
github.event.pull_request.base.ref == 'main'
@@ -25,8 +27,9 @@ jobs:
2527
uses: actions/setup-node@v4
2628
with:
2729
node-version: '20'
30+
registry-url: 'https://registry.npmjs.org'
2831

29-
- name: Detect if package.json version changed in PR
32+
- name: Detect if package.json version changed
3033
id: ver_changed
3134
uses: actions/github-script@v7
3235
with:
@@ -42,7 +45,7 @@ jobs:
4245
);
4346
core.setOutput('changed', touched ? 'true' : 'false');
4447
45-
- name: Detect if new UI folder added
48+
- name: Detect new UI folder
4649
id: new_ui_folder
4750
uses: actions/github-script@v7
4851
with:
@@ -53,7 +56,6 @@ jobs:
5356
repo: context.repo.repo,
5457
pull_number: pr
5558
});
56-
5759
const addedDirs = new Set();
5860
for (const f of files) {
5961
if (f.status === 'added' && f.filename.startsWith('src/shared/ui/')) {
@@ -63,34 +65,23 @@ jobs:
6365
}
6466
}
6567
}
66-
6768
core.setOutput('new_ui_folder', addedDirs.size > 0 ? 'true' : 'false');
6869
6970
- name: Bump version based on PR type
7071
if: steps.ver_changed.outputs.changed != 'true'
7172
run: |
7273
node -e "
7374
const fs = require('fs');
74-
7575
const pr_title = process.env.PR_TITLE;
7676
const is_new_ui = process.env.NEW_UI_FOLDER === 'true';
77-
7877
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
79-
const [a, b, c] = pkg.version.split('.').map(Number);
80-
78+
const [a,b,c] = pkg.version.split('.').map(Number);
8179
let new_version;
82-
83-
if (is_new_ui) {
84-
new_version = [a + 1, 0, 0].join('.');
85-
} else if (pr_title.toLowerCase().startsWith('feat')) {
86-
new_version = [a, b + 1, 0].join('.');
87-
} else {
88-
new_version = [a, b, c + 1].join('.');
89-
}
90-
80+
if(is_new_ui) new_version = [a+1,0,0].join('.');
81+
else if(pr_title.toLowerCase().startsWith('feat')) new_version = [a,b+1,0].join('.');
82+
else new_version = [a,b,c+1].join('.');
9183
pkg.version = new_version;
92-
93-
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\\n');
84+
fs.writeFileSync('package.json', JSON.stringify(pkg,null,2)+'\n');
9485
"
9586
env:
9687
PR_TITLE: ${{ github.event.pull_request.title }}
@@ -99,75 +90,71 @@ jobs:
9990
- name: Install dependencies
10091
run: npm ci
10192

102-
- name: Sync exports (inline)
93+
- name: Sync exports
10394
run: |
10495
node -e "
10596
const fs = require('fs');
10697
const path = require('path');
107-
10898
const root = 'src/shared';
10999
const indexPath = path.join(root, 'index.ts');
110-
const indexContent = fs.existsSync(indexPath)
111-
? fs.readFileSync(indexPath, 'utf8')
112-
: '';
113-
100+
const indexContent = fs.existsSync(indexPath) ? fs.readFileSync(indexPath,'utf8') : '';
114101
const existingExports = new Set(
115102
(indexContent.match(/from\\s+['\\\"](\\.\\/|\\.\\.\\/)([^'\\\"]+)['\\\"]/g) || [])
116103
.map(line => line.match(/from\\s+['\\\"]([^'\\\"]+)['\\\"]/)[1])
117104
);
118-
119105
const adds = [];
120-
const uiRoot = path.join(root, 'ui');
121-
122-
if (fs.existsSync(uiRoot)) {
123-
fs.readdirSync(uiRoot, { withFileTypes: true })
124-
.filter(d => d.isDirectory())
125-
.forEach(dir => {
126-
const dirPath = path.join(uiRoot, dir.name);
127-
const hasIndex = ['index.ts', 'index.tsx']
128-
.some(file => fs.existsSync(path.join(dirPath, file)));
129-
130-
if (hasIndex) {
131-
const exportPath = './ui/' + dir.name;
132-
if (!existingExports.has(exportPath)) {
133-
adds.push(`export { ${dir.name} } from '${exportPath}';`);
134-
}
106+
const uiRoot = path.join(root,'ui');
107+
if(fs.existsSync(uiRoot)){
108+
fs.readdirSync(uiRoot,{withFileTypes:true})
109+
.filter(d=>d.isDirectory())
110+
.forEach(dir=>{
111+
const dirPath = path.join(uiRoot,dir.name);
112+
const hasIndex = ['index.ts','index.tsx'].some(file=>fs.existsSync(path.join(dirPath,file)));
113+
if(hasIndex){
114+
const exportPath = './ui/'+dir.name;
115+
if(!existingExports.has(exportPath)) adds.push(`export { ${dir.name} } from '${exportPath}';`);
135116
}
136117
});
137118
}
138-
139-
if (adds.length) {
140-
const next = (indexContent.trim() ? indexContent.trim() + '\\n' : '')
141-
+ adds.join('\\n')
142-
+ '\\n';
143-
144-
fs.writeFileSync(indexPath, next);
145-
console.log('Added exports to index.ts:', adds);
146-
} else {
147-
console.log('No new UI components found to export.');
148-
}
119+
if(adds.length){
120+
const next = (indexContent.trim()?indexContent.trim()+'\n':'') + adds.join('\n') + '\n';
121+
fs.writeFileSync(indexPath,next);
122+
console.log('Added exports:',adds);
123+
}else console.log('No new exports found.');
149124
"
150125
151126
- name: Build package
152127
run: npm run build
153128

154-
- name: Create bump branch and push
129+
- name: Create bump branch and merge
155130
run: |
156131
TIMESTAMP=$(date -u +'%Y%m%d-%H%M%S%N' | cut -c1-14)
157132
BRANCH="bump/$TIMESTAMP"
158-
159133
git checkout -b "$BRANCH"
160-
161134
if git diff --quiet; then
162135
echo "NO_CHANGES=true" >> $GITHUB_ENV
163136
exit 0
164137
fi
165-
166138
git config user.name "github-actions[bot]"
167139
git config user.email "github-actions[bot]@users.noreply.github.com"
168-
169140
git add .
170141
git commit -m "chore: bump version and sync exports"
171142
git push https://x-access-token:${{ secrets.PAT }}@github.com/${{ github.repository }} "$BRANCH"
172-
173-
echo "BRANCH_NAME=$BRANCH" >> $GITHUB_ENV
143+
pr_number=$(gh pr create --base main --head $BRANCH --title "chore: bump version & sync exports" --body "Automated bump and sync")
144+
gh pr merge $pr_number --squash --admin
145+
for i in {1..10}; do
146+
git fetch origin main
147+
VERSION_IN_MAIN=$(git show origin/main:package.json | jq -r '.version')
148+
VERSION_IN_BRANCH=$(jq -r '.version' package.json)
149+
if [ "$VERSION_IN_MAIN" = "$VERSION_IN_BRANCH" ]; then
150+
break
151+
fi
152+
sleep 5
153+
done
154+
git checkout main
155+
git pull origin main
156+
157+
- name: Publish to npm
158+
run: npm publish
159+
env:
160+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/bump-pr.yaml

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)