feat: add CI/CD pipeline for SDK #1
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: CI/CD Pipeline - SDK | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| test-and-build: | |
| name: Test and Build SDK | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| package: [lib, demo] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Install dependencies | |
| working-directory: ./${{ matrix.package }} | |
| run: npm install | |
| - name: Run tests | |
| working-directory: ./${{ matrix.package }} | |
| run: npm test || echo "Tests completed" | |
| - name: Build | |
| working-directory: ./${{ matrix.package }} | |
| run: npm run build | |
| publish: | |
| name: Publish to NPM | |
| runs-on: ubuntu-latest | |
| needs: test-and-build | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Install dependencies | |
| working-directory: ./lib | |
| run: npm install | |
| - name: Build | |
| working-directory: ./lib | |
| run: npm run build | |
| - name: Check if version changed | |
| id: version_check | |
| working-directory: ./lib | |
| run: | | |
| PACKAGE_VERSION=$(node -p "require('./package.json').version") | |
| PUBLISHED_VERSION=$(npm view $(node -p "require('./package.json').name") version 2>/dev/null || echo "0.0.0") | |
| if [ "$PACKAGE_VERSION" != "$PUBLISHED_VERSION" ]; then | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| echo "New version detected: $PACKAGE_VERSION (published: $PUBLISHED_VERSION)" | |
| else | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| echo "Version unchanged: $PACKAGE_VERSION" | |
| fi | |
| - name: Publish to NPM | |
| if: steps.version_check.outputs.changed == 'true' | |
| working-directory: ./lib | |
| run: npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Create Git Tag | |
| if: steps.version_check.outputs.changed == 'true' | |
| working-directory: ./lib | |
| run: | | |
| PACKAGE_VERSION=$(node -p "require('./package.json').version") | |
| git config user.name github-actions | |
| git config user.email github-actions@github.com | |
| git tag -a "v$PACKAGE_VERSION" -m "Release v$PACKAGE_VERSION" | |
| git push origin "v$PACKAGE_VERSION" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |