Bump version #10
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 | |
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: Configure npm for authentication | |
if: env.new_version == 'true' | |
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | |
- name: Publish to npm | |
if: env.new_version == 'true' | |
run: | | |
npm publish | |
- name: Configure Git for authentication | |
if: env.new_version == 'true' | |
run: | | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "github-actions[bot]" | |
git remote set-url origin https://x-access-token:${{ secrets.GH_PAT }}@github.com/${{ github.repository }} | |
- name: Push tags to repository | |
if: env.new_version == 'true' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_PAT }} | |
run: | | |
git tag v${{ env.version }} | |
git push origin --tags |