name: Publish to npm on: push: branches: - main jobs: publish: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 with: fetch-depth: 0 - uses: actions/setup-node@v3 with: node-version: 20 registry-url: https://registry.npmjs.org/ - run: npm config set registry https://registry.npmjs.org/ - run: npm install # Check if only the 'website' folder is modified - name: Check for changes outside /website id: check_changes run: | git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -v '^website/' > changes.txt || true if [ -s changes.txt ]; then echo "Changes detected outside the /website folder. Proceeding with version bump and publish." echo "publish=true" >> $GITHUB_ENV else echo "No changes outside the /website folder. Skipping publish." echo "publish=false" >> $GITHUB_ENV fi - name: Bump version if: env.publish == 'true' run: npm version patch --no-git-tag-version - name: Commit changes and create tag if: env.publish == 'true' run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git add package.json git commit -m "Bump version in package.json" VERSION=$(node -p "require('./package.json').version") git tag v$VERSION git push origin main git push origin v$VERSION env: GITHUB_TOKEN: ${{ secrets.LIGHTBOX_GITHUB_TOKEN }} - run: npm run build:package if: env.publish == 'true' - run: npm publish if: env.publish == 'true' env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}