Issue #224544 feat: Enable GitHub Actions to publish NPM package #98
Workflow file for this run
This file contains 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: | |
pull_request: | |
branches: | |
- '**' | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
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' | |
- 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: ποΈ Change Directory to dist/quml-library | |
# run: | | |
# cd dist/quml-library | |
# pwd # Print the current directory | |
- name: π Check if Version Exists | |
id: check-version | |
run: | | |
cd dist/quml-library | |
pwd # Print the current directory | |
ls | |
PACKAGE_NAME=$(jq -r .name package.json) | |
echo "Package Name: $(jq -r .name package.json)" | |
PACKAGE_VERSION=$(jq -r .version package.json) | |
echo "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 | |
pwd # Print the current directory | |
ls | |
npm pack | |
ls | |
if [[ "$(jq -r .version package.json)" == *"beta"* ]]; then | |
echo "//registry.npmjs.org/:_authToken='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'" > ~/.npmrc | |
npm publish tekdi-sunbird-quml-player-* --tag=beta --access public | |
else | |
echo "//registry.npmjs.org/:_authToken='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'" > ~/.npmrc | |
npm publish tekdi-sunbird-quml-player-* --access public | |
fi | |
env: | |
NODE_AUTH_TOKEN: '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' | |
- name: π Log Version Exists | |
if: env.status == '200' | |
run: echo "Version already exists, skipping publish." |