diff --git a/.github/workflows/publish-to-jsr.yaml b/.github/workflows/publish-to-jsr.yaml new file mode 100644 index 0000000..021add4 --- /dev/null +++ b/.github/workflows/publish-to-jsr.yaml @@ -0,0 +1,19 @@ +# Publish package to JSR. +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 diff --git a/.github/workflows/publish-to-npm.yaml b/.github/workflows/publish-to-npm.yaml index c9d4112..ec01535 100644 --- a/.github/workflows/publish-to-npm.yaml +++ b/.github/workflows/publish-to-npm.yaml @@ -1,4 +1,4 @@ -# Publish package to npm whenever a release is pushed. +# Publish package to npm. # See https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages name: Publish to npm on: [workflow_call] diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index bb38d0f..cff3d31 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -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 diff --git a/PUBLISHING.md b/PUBLISHING.md index 4c907b5..6974aa4 100644 --- a/PUBLISHING.md +++ b/PUBLISHING.md @@ -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_ supported. 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!). diff --git a/bump.sh b/bump.sh new file mode 100755 index 0000000..e987c72 --- /dev/null +++ b/bump.sh @@ -0,0 +1,44 @@ +#!/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 + +# Print current version information. +npm version + +# Bail if we don’t have a version string for some reason. This is not an error. +if [ -z "${1}" ] +then + exit 0 +fi + +# Bump version in package.json using npm version itself. This ensures that we +# stay anchored to first-class tooling. We pass “--git-tag-version=false” to +# prevent the command from (1) committing changes and (2) creating a tag. +prefixed_version="$(npm version --git-tag-version=false "${1}")" + +# The “npm version” command will return the value with a “v” prefix. Ditch that. +version="${prefixed_version:1}" + +# Get pointers to files we need to manually update. +root_directory="$(dirname "$(realpath "${0}")")" +deno_json_file="${root_directory}/deno.json" +package_json_file="${root_directory}/package.json" +package_lock_json_file="${root_directory}/package-lock.json" + +# Bump version in deno.json. +deno_json_find="\"version\": \"[^\"]*\"" +deno_json_repl="\"version\": \"${version}\"" +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}" + +# Commit all our changes. +git add "${package_json_file}" +git add "${package_lock_json_file}" +git add "${deno_json_file}" +git commit --message="${version}" +git tag --annotate "v${version}" --message="${version}" diff --git a/deno.json b/deno.json new file mode 100644 index 0000000..fc1fd77 --- /dev/null +++ b/deno.json @@ -0,0 +1,5 @@ +{ + "name": "@netflix/x-element", + "version": "1.0.0-rc.58", + "exports": "./x-element.js" +} diff --git a/package.json b/package.json index ec86594..4c5422a 100644 --- a/package.json +++ b/package.json @@ -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",