diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..d8fdc397 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,33 @@ +name: Publish to NPM + +on: + release: + types: + - published + +env: + GH_TOKEN: ${{ secrets.GH_TOKEN_COMMIT }} + +jobs: + test-action: + runs-on: ubuntu-latest + name: Update Release + + steps: + - name: Checkout + id: checkout + uses: actions/checkout@v4 + with: + ref: '3.x' + fetch-depth: 0 + token: ${{ secrets.GH_TOKEN_COMMIT }} + + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: 18.x + + - name: Publish to NPM + run: ./scripts/publish.sh + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 929a5630..f1cdcf48 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,10 +30,10 @@ jobs: - name: Update RELEASES.MD uses: vonage/generate-release-log@1.0.2 - - name: Commit release + - name: Commit release notes run: | git config --local user.name github-actions git config --local user.email github-actions@github.com git add RELEASES.md git commit -m "chore: updated release log" - git push --force-with-lease + git push --force-with-leaseCallUpdateResultc diff --git a/lerna.json b/lerna.json index a2bb50ba..50084954 100644 --- a/lerna.json +++ b/lerna.json @@ -2,5 +2,13 @@ "packages": [ "packages/*" ], - "version": "independent" + "version": "independent", + "command": { + "version": { + "message": "chore(release): publish", + "conventionalCommits": true, + "noCommitHooks": true, + "exact": true + } + } } diff --git a/package.json b/package.json index f71d6431..87162c97 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "format": "prettier -- -w", "jest": "jest", "lerna": "lerna", - "version": "lerna version --conventional-commits --no-commit-hooks --message='chore(release): publish %s'", + "version": "lerna version --conventional-commits --no-commit-hooks", "lint": "eslint .", "lint:fix": "eslint --fix .", "prepare": "is-ci || husky install", diff --git a/scripts/publish.sh b/scripts/publish.sh new file mode 100755 index 00000000..07b33725 --- /dev/null +++ b/scripts/publish.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Enable error handling +set -e + +# Run the `lerna changed` command to get the list of changed packages +changed_packages=$(npm run --silent lerna -- changed) + +# Loop through each changed package +echo "$changed_packages" | while read -r package; do + # Extract the package name without the `@vonage/` prefix + package_name=${package#@vonage/} + + # Change directory into the package folder and publish + if [ -d "packages/$package_name" ]; then + cd "packages/$package_name" || exit + echo "Publishing $package_name..." + if ! npm publish; then + echo "Failed to publish $package_name" >&2 + exit 1 + fi + cd - > /dev/null || exit # Return to the previous directory + else + echo "Directory packages/$package_name does not exist, skipping..." + fi +done + +echo "Publishing process completed!"