[CI/CD] version sync with npm github #45
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: Node.js CI/CD | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| outputs: | |
| new_version: ${{ steps.bump_version.outputs.version }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Enable Corepack | |
| run: corepack enable | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| registry-url: 'https://registry.npmjs.org' | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Install dependencies (Yarn Berry) | |
| run: yarn install --immutable | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Run tests (if test script exists) | |
| run: yarn workspaces foreach --all --topological --parallel --no-private run test | |
| continue-on-error: true | |
| - name: Build project (if build script exists) | |
| run: yarn workspaces foreach --all --topological --parallel --no-private run build | |
| - name: Bump version & commit (only on main) | |
| id: bump_version | |
| if: github.ref == 'refs/heads/main' | |
| run: | | |
| yarn workspaces foreach --all version patch | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add -A | |
| git commit -m "chore(release): bump versions" | |
| NEW_VERSION=$(jq -r .version package.json) | |
| git tag v$NEW_VERSION | |
| git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} | |
| git push --follow-tags | |
| echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| - name: Publish to npm using yarn workspaces | |
| if: github.ref == 'refs/heads/main' | |
| run: yarn workspaces foreach --verbose --all --topological --no-private npm publish --access public | |
| call-publish: | |
| needs: [build] | |
| uses: ./.github/workflows/release.yml | |
| permissions: | |
| contents: write | |
| with: | |
| version: ${{ needs.build.outputs.new_version }} | |