Skip to content

Commit

Permalink
Publish package to JSR in addition to npm.
Browse files Browse the repository at this point in the history
  • Loading branch information
theengineear committed Feb 29, 2024
1 parent 7d0e83d commit c44297a
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 4 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/publish-to-jsr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Publish package to npm whenever a release is pushed.
# See https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
name: Publish to JSR
on: [workflow_call]
jobs:
main:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
# Can we get this to use “deno publish”?
# - run: deno publish
- run: npx jsr publish
4 changes: 4 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ jobs:
needs: test
uses: ./.github/workflows/publish-to-npm.yaml
secrets: inherit
publish-to-jsr:
needs: test
uses: ./.github/workflows/publish-to-jsr.yaml
secrets: inherit
4 changes: 1 addition & 3 deletions PUBLISHING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
We use GitHub actions to publish new versions of this repository. To publish, perform the following actions:

1. Ensure your local `main` branch is checked-out and current — `git checkout main && git pull origin main`.
2. Run `npm version` to view the current version. Then…
* **For Normal Releases** use a keyword like `major`, `minor`, or `patch` (e.g., `npm version patch`).
* **For Release Candidates** manually declare the next version (e.g., `npm version 1.0.0-rc.57`).
2. Run `npm run bump` to view the current version. Then, run the same command and provide the version to bump to (e.g., `npm run bump 1.0.0-rc.57`). Note, keywords like `major`, `minor`, `patch`, etc. are not supported — you must provide the full version string.
3. Push the resulting commit and tags — `git push origin main --follow-tags`.
4. In the GitHub UI, find [the tag you just pushed](https://github.com/Netflix/x-element/tags) and find the "Create release" option. Add any additional release information (including to check the box if it's a "pre-release", it probably is!).

Expand Down
47 changes: 47 additions & 0 deletions bump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

# Wrapper around “npm version” which appends additional logic to also update the
# “deno.json” file which controls how we publish to JSR.

# Exit upon any failure. I.e., make script strictly sequential.
set -e

# Bail if we don’t have a version string for some reason.
if [ -z "${1}" ]
then
npm version
echo "Pass in a version string (e.g., 1.0.0-rc.58)."
exit 0
fi

# Bail if a keyword is being used. We cannot currently support that.
for keyword in "major" "minor" "patch" "premajor" "preminor" "prepatch" "prerelease" "from-git"
do
if [ "$1" = "$keyword" ]
then
echo "Version keywords are not allowed."
exit 1
fi
done

# Print current version information.
npm version

# Bump version in package.json using npm version itself. This ensures that we
# stay anchored to first-class tooling.
npm version "${1}"

# Get pointers to files we need to manually update.
root_directory="$(dirname "$(realpath "${0}")")"

# Bump version in deno.json.
deno_json_file="${root_directory}/deno.json"
deno_json_find="\"version\": \"[^\"]*\""
deno_json_repl="\"version\": \"${1}\""
next_deno_json_file=$(sed "s/${deno_json_find}/${deno_json_repl}/g" "${deno_json_file}")
echo "updating \"${deno_json_file}\""
echo "${next_deno_json_file}" > "${deno_json_file}"

# Amend the commit that should have been created from the earlier `npm version` command.
git add "${deno_json_file}"
git commit --amend --no-edit
5 changes: 5 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@netflix/x-element",
"version": "1.0.0-rc.58",
"exports": "./x-element.js"
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"start": "node ./server.js",
"lint": "eslint --max-warnings=0 .",
"lint-fix": "eslint --fix .",
"test": "node test.js | tap-parser -l"
"test": "node test.js | tap-parser -l",
"bump": "./bump.sh"
},
"files": [
"/x-element.js",
Expand Down

0 comments on commit c44297a

Please sign in to comment.