diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml index 0a488132..415bd67e 100644 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/build-and-test.yaml @@ -1,9 +1,6 @@ name: CI Build and Test Pipeline on: - push: - branches: - - '**' pull_request: branches: - '**' diff --git a/.github/workflows/publish-package.yml b/.github/workflows/publish-package.yml new file mode 100644 index 00000000..ed7d476a --- /dev/null +++ b/.github/workflows/publish-package.yml @@ -0,0 +1,63 @@ +name: 🚀 Publish NPM Package + +on: + pull_request: + types: [closed] + branches: + - '**' + +jobs: + publish: + runs-on: ubuntu-latest + if: github.event.pull_request.merged == true # Check if the PR was merged + permissions: + contents: write + id-token: write + actions: write + packages: write + pull-requests: write + + steps: + - name: 📥 Checkout Code Repository + uses: actions/checkout@v4 + + - name: 🔧 Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + registry-url: 'https://registry.npmjs.org/' + + - name: 📦 Install Dependencies + run: npm install + + - name: 🛠️ Build Library + run: npm run build-lib + + - name: 🔍 Ensure jq is installed + run: sudo apt-get install -y jq + + - name: 🔍 Check if Version Exists + id: check-version + run: | + cd dist/quml-library + PACKAGE_NAME=$(jq -r .name package.json) + PACKAGE_VERSION=$(jq -r .version package.json) + NPM_REGISTRY="https://registry.npmjs.org" + STATUS=$(curl -s -o /dev/null -w "%{http_code}" "$NPM_REGISTRY/$PACKAGE_NAME/$PACKAGE_VERSION") + echo "status=$STATUS" >> $GITHUB_ENV + + - name: 🚢 Publish to NPM + if: env.status != '200' + run: | + cd dist/quml-library + if [[ "$(jq -r .version package.json)" == *"beta"* ]]; then + npm publish --tag=beta --access public + else + npm publish --access public + fi + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: 📜 Log Version Exists + if: env.status == '200' + run: echo "Version already exists, skipping publish." diff --git a/projects/quml-library/package.json b/projects/quml-library/package.json index 6611fcdf..27adca2d 100644 --- a/projects/quml-library/package.json +++ b/projects/quml-library/package.json @@ -1,6 +1,6 @@ { "name": "@tekdi/sunbird-quml-player", - "version": "8.0.0", + "version": "9.0.0-beta.7", "schematics": "./schematics/collection.json", "ng-add": { "save": "dependencies" @@ -17,6 +17,9 @@ "lodash-es": "^4.17.21", "@project-sunbird/client-services": "5.1.2" }, + "publishConfig": { + "access": "public" + }, "dependencies": { "@project-sunbird/sunbird-player-sdk-v9": "6.0.5" },