Skip to content

Attempt to fix publishing to npm #5

Attempt to fix publishing to npm

Attempt to fix publishing to npm #5

Workflow file for this run

name: Publish to npm
on:
push:
branches:
- main
jobs:
test-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Install dependencies
run: npm install
- name: Install jq
run: sudo apt-get install -y jq
- name: Run tests
run: npm test
- name: Get current version
id: get_version
run: echo "version=$(jq -r .version package.json)" >> $GITHUB_ENV
- name: Check if version is published
id: version_check
run: |
PUBLISHED_VERSIONS=$(npm view . versions --json)
CURRENT_VERSION=$(jq -r .version package.json)
if echo "$PUBLISHED_VERSIONS" | jq -e ". | index(\"$CURRENT_VERSION\")" > /dev/null; then
echo "Version $CURRENT_VERSION is already published."
exit 1
else
echo "Version $CURRENT_VERSION is new and will be published."
echo "new_version=true" >> $GITHUB_ENV
fi
- name: Publish to npm
if: env.new_version == 'true'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
npm publish
git tag v${{ env.version }}
git push origin --tags