Skip to content

[FIX] 레이아웃 겹침 문제 수정 #7

[FIX] 레이아웃 겹침 문제 수정

[FIX] 레이아웃 겹침 문제 수정 #7

name: Bump Version and Publish
on:
pull_request:
types:
- closed
permissions:
contents: write
pull-requests: write
packages: write
jobs:
bump-and-publish:
if: >
github.event.pull_request.merged == true &&
github.event.pull_request.base.ref == 'main'
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
- 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
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
});
const touched = files.some(
f => f.filename === 'package.json' && /"version"\s*:/.test(f.patch || '')
);
core.setOutput('changed', touched ? 'true' : 'false');
- name: Detect new UI folder
id: new_ui_folder
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
});
const addedDirs = new Set();
for (const f of files) {
if (f.status === 'added' && f.filename.startsWith('src/shared/ui/')) {
const parts = f.filename.split('/');
if (parts.length > 3) {
addedDirs.add(parts.slice(0, 4).join('/'));
}
}
}
core.setOutput('new_ui_folder', addedDirs.size > 0 ? 'true' : 'false');
- name: Bump version based on PR type
if: steps.ver_changed.outputs.changed != 'true'
run: |
node -e "
const fs = require('fs');
const pr_title = process.env.PR_TITLE;
const is_new_ui = process.env.NEW_UI_FOLDER === 'true';
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
const [a,b,c] = pkg.version.split('.').map(Number);
let new_version;
if(is_new_ui) new_version = [a+1,0,0].join('.');
else 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');
"
env:
PR_TITLE: ${{ github.event.pull_request.title }}
NEW_UI_FOLDER: ${{ steps.new_ui_folder.outputs.new_ui_folder }}
- name: Install dependencies
run: npm ci
- name: Sync exports
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');
if(fs.existsSync(uiRoot)){
fs.readdirSync(uiRoot,{withFileTypes:true})
.filter(d=>d.isDirectory())
.forEach(dir=>{
const dirPath = path.join(uiRoot,dir.name);
const hasIndex = ['index.ts','index.tsx'].some(file=>fs.existsSync(path.join(dirPath,file)));
if(hasIndex){
const exportPath = './ui/'+dir.name;
if(!existingExports.has(exportPath)) adds.push(`export { ${dir.name} } from '${exportPath}';`);
}
});
}
if(adds.length){
const next = (indexContent.trim()?indexContent.trim()+'\n':'') + adds.join('\n') + '\n';
fs.writeFileSync(indexPath,next);
console.log('Added exports:',adds);
}else console.log('No new exports found.');
"
- name: Build package
run: npm run build
- name: Commit and push changes directly to main
run: |
if git diff --quiet; then
echo "No changes to commit."
echo "NO_CHANGES=true" >> $GITHUB_ENV
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
git commit -m "chore: bump version and sync exports"
git push https://x-access-token:${{ secrets.PAT }}@github.com/${{ github.repository }} main
- name: Publish to npm
if: env.NO_CHANGES != 'true'
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}