fix: npm publish #9
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 to npm | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- 'package.json' | |
schedule: | |
- cron: "0 0 * * 1,4" | |
jobs: | |
publish: | |
name: Publish Package | |
runs-on: ubuntu-latest | |
services: | |
mongodb: | |
image: mongo:5.0 | |
ports: | |
- 27017:27017 | |
options: >- | |
--health-cmd="mongosh --eval 'db.runCommand({ ping: 1 })'" | |
--health-interval=10s | |
--health-timeout=5s | |
--health-retries=5 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '20' | |
registry-url: 'https://registry.npmjs.org/' | |
- name: Install dependencies | |
run: npm install | |
- name: Wait for MongoDB | |
run: | | |
for i in {1..10}; do | |
if mongosh --eval "db.runCommand({ ping: 1 })"; then | |
echo "MongoDB is ready"; | |
exit 0; | |
fi; | |
echo "Waiting for MongoDB..."; | |
sleep 5; | |
done; | |
exit 1 | |
- name: Run tests | |
env: | |
MONGO_URI: mongodb://localhost:27017/poet_app | |
run: npm test | |
- name: Publish to npm | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
run: | | |
CURRENT_VERSION=$(npm view poet-app version) | |
PACKAGE_VERSION=$(node -p "require('./package.json').version") | |
if [ "$CURRENT_VERSION" = "$PACKAGE_VERSION" ]; then | |
echo "Version $PACKAGE_VERSION already published. Skipping publish."; | |
else | |
npm publish; | |
fi | |
- name: Post publish verification | |
run: | | |
echo "Package published successfully." | |
npm view poet-app version |