From bd9bf21e9fa3f9f1cc0021e45b6694d754836056 Mon Sep 17 00:00:00 2001 From: Edoardo Federici <55538139+Ohswedd@users.noreply.github.com> Date: Sat, 30 Nov 2024 15:48:15 +0100 Subject: [PATCH] Create release-to-npm.yml --- .github/workflows/release-to-npm.yml | 57 ++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 .github/workflows/release-to-npm.yml diff --git a/.github/workflows/release-to-npm.yml b/.github/workflows/release-to-npm.yml new file mode 100644 index 0000000..f975a1d --- /dev/null +++ b/.github/workflows/release-to-npm.yml @@ -0,0 +1,57 @@ +name: Release to NPM + +on: + release: + types: [published] + +jobs: + release: + runs-on: ubuntu-latest + + steps: + # Step 1: Check out the repository + - name: Checkout code + uses: actions/checkout@v3 + + # Step 2: Set up Node.js + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '16' + cache: 'npm' + + # Step 3: Install dependencies + - name: Install dependencies + run: npm install + + # Step 4: Sync package.json version with release + - name: Sync version with release tag + run: | + RELEASE_VERSION=${GITHUB_REF#refs/tags/} + echo "Updating package.json to version ${RELEASE_VERSION}" + npm version ${RELEASE_VERSION} --no-git-tag-version + + # Step 5: Generate/update changelog + - name: Update changelog + run: npx standard-version --skip.tag --skip.commit + + # Step 6: Authenticate with npm + - name: Authenticate with npm + run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc + + # Step 7: Publish package to npm + - name: Publish to npm + run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + # Step 8: Push updated files back to repository + - name: Push updated files back + run: | + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + git add package.json CHANGELOG.md + git commit -m "chore(release): ${GITHUB_REF#refs/tags/} [skip ci]" + git push + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}