Skip to content

feat/test-deployment - 테스트 배포 #25

feat/test-deployment - 테스트 배포

feat/test-deployment - 테스트 배포 #25

Workflow file for this run

name: CI & Release (pnpm, secure + optimized)
on:
push:
branches: [main]
tags:
- 'v*'
pull_request:
permissions:
contents: write
packages: write
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20
- run: corepack enable
- name: Cache pnpm store
uses: actions/cache@v3
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
- run: pnpm install --frozen-lockfile
- run: pnpm test
release:
needs: test
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'
- run: corepack enable
- name: Use stable npm (downgrade from v10 to v9)
run: npm install -g npm@9
- name: Cache pnpm store
uses: actions/cache@v3
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
- run: pnpm install --frozen-lockfile
- run: pnpm build
- name: Configure npm auth
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
- name: Verify npm user
run: npm whoami
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# tgz 생성
- name: Pack the package
run: |
echo "Packing the package..."
PACKAGE_TGZ=$(pnpm pack | tail -n 1)
echo "PACKAGE_TGZ=$(realpath $PACKAGE_TGZ)" >> $GITHUB_ENV
# pnpm 설치 테스트
- name: Verify install with pnpm
run: |
echo "Testing install with pnpm..."
pnpm add $PACKAGE_TGZ
# npm 설치 테스트
- name: Verify install with npm
run: |
echo "Testing install with npm..."
mkdir npm-test
cd npm-test
npm init -y
npm install $PACKAGE_TGZ
# npm publish (Git 체크 비활성화)
- name: Publish to npm
run: pnpm publish --access public --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# GitHub Release 생성
- name: Create GitHub Release
uses: actions/github-script@v7
with:
github-token: ${{ secrets.PERSONAL_GITHUB_TOKEN }}
script: |
const tagName = context.ref.replace('refs/tags/', '');
try {
await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tagName,
name: `Release ${tagName}`,
body: `🚀 Package successfully published to NPM!\n\n**Version:** ${tagName}\n**Package:** [@ramong26/xp-components](https://www.npmjs.com/package/@ramong26/xp-components)`,
draft: false,
prerelease: tagName.includes('-')
});
console.log(`✅ Release ${tagName} created successfully!`);
} catch (error) {
if (error.status === 422) {
console.log(`⚠️ Release ${tagName} already exists`);
} else {
throw error;
}
}
# Release 완료 이메일 발송
- name: Send email
uses: dawidd6/action-send-mail@v3
with:
server_address: smtp.gmail.com
server_port: 587
secure: true
username: ${{ secrets.GMAIL_USERNAME }}
password: ${{ secrets.GMAIL_APP_PASSWORD }}
subject: 🚀 Release ${{ github.ref_name }} completed
body: |
Your package has been successfully published to NPM!
Version: ${{ github.ref_name }}
Package: recomponent
Repository: ${{ github.repository }}
to: [email protected]
from: [email protected]