# Publish to npm (and so to the Joplin plugin directory) when a version tag is pushed. # # Release: npm run updateVersion → commit → git tag vX.Y.Z → git push --follow-tags # # Uses npm trusted publishing (OIDC), so no npm token is stored in the repo. Set it up # once with: npm trust github joplin-plugin-book-export --file publish.yml --allow-publish name: Publish on: push: tags: ['v*'] permissions: contents: write # create the GitHub release id-token: write # npm trusted publishing concurrency: group: publish cancel-in-progress: false jobs: publish: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - uses: actions/setup-node@v5 with: node-version: 24 registry-url: https://registry.npmjs.org cache: npm # Trusted publishing needs npm 11.5.1 or later. - run: npm install -g npm@latest - name: Check the tag matches package.json and the manifest run: | tag="${GITHUB_REF_NAME#v}" pkg="$(node -p 'require("./package.json").version')" manifest="$(node -p 'require("./src/manifest.json").version')" echo "tag=$tag package.json=$pkg manifest=$manifest" if [ "$tag" != "$pkg" ] || [ "$tag" != "$manifest" ]; then echo "::error::Tag v$tag does not match package.json ($pkg) and src/manifest.json ($manifest). Run npm run updateVersion, commit, then tag." exit 1 fi # npm ci runs the prepare script, which builds publish/*.jpl. - run: npm ci - run: npm test # Skipped when the version is already on npm (published by hand, or a re-run), # so the release step below still runs. - name: Publish to npm run: | name="$(node -p 'require("./package.json").name')" version="$(node -p 'require("./package.json").version')" if npm view "$name@$version" version >/dev/null 2>&1; then echo "::notice::$name@$version is already on npm; skipping publish." else npm publish --provenance --access public fi - name: Attach the plugin to a GitHub release env: GH_TOKEN: ${{ github.token }} run: gh release create "$GITHUB_REF_NAME" publish/*.jpl --title "$GITHUB_REF_NAME" --generate-notes