fix/태그 변경 #71
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| - name: Lint | |
| run: pnpm exec eslint . --ext .ts,.tsx | |
| - name: Typecheck | |
| run: pnpm exec tsc --noEmit | |
| - 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 }} | |
| - name: Pack the package | |
| run: | | |
| PACKAGE_TGZ=$(pnpm pack | tail -n 1) | |
| echo "PACKAGE_TGZ=$(realpath $PACKAGE_TGZ)" >> $GITHUB_ENV | |
| - name: Verify install with pnpm | |
| run: pnpm add $PACKAGE_TGZ | |
| - name: Verify install with npm | |
| run: | | |
| mkdir npm-test | |
| cd npm-test | |
| npm init -y | |
| npm install $PACKAGE_TGZ | |
| - name: Publish to npm | |
| run: pnpm publish --access public --no-git-checks | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - 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; | |
| } | |
| } | |
| - name: Send email | |
| uses: dawidd6/action-send-mail@v3 | |
| with: | |
| server_address: smtp.gmail.com | |
| server_port: 587 | |
| secure: false | |
| 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: xp-components | |
| Repository: ${{ github.repository }} | |
| to: [email protected] | |
| from: [email protected] |