chore: fix ci/cd #8
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: Publish npm Package | |
| on: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| update-version: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.actor != 'github-actions[bot]' }} | |
| outputs: | |
| version: ${{ steps.get_version.outputs.new_version }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| persist-credentials: false | |
| - name: Configure Git Identity | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Read current version and bump | |
| id: get_version | |
| run: | | |
| current=$(jq -r '.version' package.json) | |
| echo "current version: $current" | |
| IFS='.' read -r major minor patch <<< "$current" | |
| patch=$((patch + 1)) | |
| new="$major.$minor.$patch" | |
| echo "new version: $new" | |
| echo "new_version=$new" >> $GITHUB_OUTPUT | |
| - name: Bump version in all package.json files | |
| run: | | |
| # Update root package.json | |
| jq --arg v "${{ steps.get_version.outputs.new_version }}" '.version = $v' package.json > package.json.tmp | |
| mv package.json.tmp package.json | |
| # Update all package.json files in packages/* | |
| for pkg in packages/*/package.json; do | |
| if [ -f "$pkg" ]; then | |
| jq --arg v "${{ steps.get_version.outputs.new_version }}" '.version = $v' "$pkg" > "$pkg.tmp" | |
| mv "$pkg.tmp" "$pkg" | |
| fi | |
| done | |
| - name: Commit & push version bump | |
| env: | |
| GH_TOKEN: ${{ secrets.GH_PAT }} | |
| run: | | |
| git remote set-url origin https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}.git | |
| git add package.json packages/*/package.json | |
| git diff --cached --quiet || git commit -m "chore: bump version to ${{ steps.get_version.outputs.new_version }} [skip ci]" | |
| git push origin HEAD | |
| build: | |
| runs-on: ubuntu-latest | |
| needs: update-version | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20.x" | |
| registry-url: "https://npm.pkg.github.com" | |
| scope: "@bitbybit-b3" | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| - name: Install dependencies | |
| run: pnpm install | |
| - name: Build packages | |
| run: pnpm build | |
| - name: Publish all packages | |
| run: | | |
| # Publish each package in packages/* directory | |
| for pkg_dir in packages/*; do | |
| if [ -d "$pkg_dir" ] && [ -f "$pkg_dir/package.json" ]; then | |
| pkg_name=$(jq -r '.name' "$pkg_dir/package.json") | |
| echo "Publishing $pkg_name from $pkg_dir" | |
| cd "$pkg_dir" | |
| pnpm publish --no-git-checks --access public || echo "Failed to publish $pkg_name (may already exist)" | |
| cd ../.. | |
| fi | |
| done | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |