diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..7d6de60 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,87 @@ +name: CI/CD Pipeline - SDK + +on: + push: + branches: [ main ] + +jobs: + build: + name: 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: Build + working-directory: ./${{ matrix.package }} + run: npm run build + + publish: + name: Publish to NPM + runs-on: ubuntu-latest + needs: 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 }}