|
| 1 | +name: Release to NPM |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +jobs: |
| 8 | + release: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + |
| 11 | + steps: |
| 12 | + # Step 1: Check out the repository |
| 13 | + - name: Checkout code |
| 14 | + uses: actions/checkout@v3 |
| 15 | + |
| 16 | + # Step 2: Set up Node.js |
| 17 | + - name: Set up Node.js |
| 18 | + uses: actions/setup-node@v3 |
| 19 | + with: |
| 20 | + node-version: '16' |
| 21 | + cache: 'npm' |
| 22 | + |
| 23 | + # Step 3: Install dependencies |
| 24 | + - name: Install dependencies |
| 25 | + run: npm install |
| 26 | + |
| 27 | + # Step 4: Sync package.json version with release |
| 28 | + - name: Sync version with release tag |
| 29 | + run: | |
| 30 | + RELEASE_VERSION=${GITHUB_REF#refs/tags/} |
| 31 | + echo "Updating package.json to version ${RELEASE_VERSION}" |
| 32 | + npm version ${RELEASE_VERSION} --no-git-tag-version |
| 33 | +
|
| 34 | + # Step 5: Generate/update changelog |
| 35 | + - name: Update changelog |
| 36 | + run: npx standard-version --skip.tag --skip.commit |
| 37 | + |
| 38 | + # Step 6: Authenticate with npm |
| 39 | + - name: Authenticate with npm |
| 40 | + run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc |
| 41 | + |
| 42 | + # Step 7: Publish package to npm |
| 43 | + - name: Publish to npm |
| 44 | + run: npm publish |
| 45 | + env: |
| 46 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 47 | + |
| 48 | + # Step 8: Push updated files back to repository |
| 49 | + - name: Push updated files back |
| 50 | + run: | |
| 51 | + git config user.name "GitHub Actions" |
| 52 | + git config user.email "actions@github.com" |
| 53 | + git add package.json CHANGELOG.md |
| 54 | + git commit -m "chore(release): ${GITHUB_REF#refs/tags/} [skip ci]" |
| 55 | + git push |
| 56 | + env: |
| 57 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments