From 6e5d4c77d41f19d7f7c776262f8275f7aa5170a2 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Fri, 21 Mar 2025 10:04:48 -0600 Subject: [PATCH 1/4] change env var to flag --- .github/workflows/daily.yml | 2 +- d2js/js/ci/build.sh | 54 +++++++++++++++++++++++++++---------- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index 1e259799c..0738b8b75 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -51,7 +51,7 @@ jobs: - name: Publish nightly version to NPM if: steps.check_changes.outputs.has_changes == 'true' - run: COLOR=1 PUBLISH=1 ./make.sh js + run: COLOR=1 ./make.sh --version=nightly js env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} GITHUB_TOKEN: ${{ secrets._GITHUB_TOKEN }} diff --git a/d2js/js/ci/build.sh b/d2js/js/ci/build.sh index 3d78c0433..7d8771bfd 100755 --- a/d2js/js/ci/build.sh +++ b/d2js/js/ci/build.sh @@ -18,26 +18,52 @@ fi cd d2js/js sh_c bun build.js -if [ "${PUBLISH:-0}" = "1" ]; then - echo "Publishing nightly version to NPM..." - - DATE_TAG=$(date +'%Y%m%d') - COMMIT_SHORT=$(git rev-parse --short HEAD) - CURRENT_VERSION=$(node -p "require('./package.json').version") - NIGHTLY_VERSION="${CURRENT_VERSION}-nightly.${DATE_TAG}.${COMMIT_SHORT}" - +if [ -n "$VERSION" ]; then cp package.json package.json.bak trap 'rm -f .npmrc; mv package.json.bak package.json' EXIT - echo "Updating package version to ${NIGHTLY_VERSION}" - npm version "${NIGHTLY_VERSION}" --no-git-tag-version + if [ "$VERSION" = "nightly" ]; then + echo "Publishing nightly version to npm..." - echo "Publishing to npm with tag 'nightly'..." + DATE_TAG=$(date +'%Y%m%d') + COMMIT_SHORT=$(git rev-parse --short HEAD) + CURRENT_VERSION=$(node -p "require('./package.json').version") + PUBLISH_VERSION="${CURRENT_VERSION}-nightly.${DATE_TAG}.${COMMIT_SHORT}" + NPM_TAG="nightly" + + echo "Updating package version to ${PUBLISH_VERSION}" + else + echo "Publishing official version ${VERSION} to npm..." + PUBLISH_VERSION="$VERSION" + NPM_TAG="latest" + + echo "Setting package version to ${PUBLISH_VERSION}" + fi + + # Update package.json with the new version + npm version "${PUBLISH_VERSION}" --no-git-tag-version + + echo "Publishing to npm with tag '${NPM_TAG}'..." if [ -n "${NPM_TOKEN-}" ]; then + # Create .npmrc file with auth token echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc - trap 'rm -f .npmrc' EXIT - if npm publish --tag nightly; then - echo "Successfully published @terrastruct/d2@${NIGHTLY_VERSION} to npm with tag 'nightly'" + + if npm publish --tag "$NPM_TAG"; then + echo "Successfully published @terrastruct/d2@${PUBLISH_VERSION} to npm with tag '${NPM_TAG}'" + + # For official releases, bump the patch version + if [ "$VERSION" != "nightly" ]; then + # Restore original package.json first + mv package.json.bak package.json + + echo "Bumping version to ${VERSION}" + npm version "${VERSION}" --no-git-tag-version + git add package.json + git commit -m "Bump version to ${VERSION} [skip ci]" + + # Cancel the trap since we manually restored and don't want it to execute on exit + trap - EXIT + fi else echoerr "Failed to publish package to npm" exit 1 From 05f4923d7077e7470a553207940a869d56c31097 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Fri, 21 Mar 2025 11:43:54 -0600 Subject: [PATCH 2/4] Bump version to 0.1.23 [skip ci] --- d2js/js/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/d2js/js/package.json b/d2js/js/package.json index 4775805e0..e7923f7b7 100644 --- a/d2js/js/package.json +++ b/d2js/js/package.json @@ -2,7 +2,7 @@ "name": "@terrastruct/d2", "author": "Terrastruct, Inc.", "description": "D2.js is a wrapper around the WASM build of D2, the modern text-to-diagram language.", - "version": "0.1.22", + "version": "0.1.23", "repository": { "type": "git", "url": "git+https://github.com/terrastruct/d2.git", @@ -41,7 +41,7 @@ "test:integration": "bun test test/integration", "test:all": "bun run test && bun run test:integration", "dev": "bun --watch dev-server.js", - "prepublishOnly": "PUBLISH=0 ./make.sh all" + "prepublishOnly": "NPM_VERSION= ./make.sh all" }, "keywords": [ "d2", From b46fbb6270756c737422a4e2ac0f643a69e2ed35 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Fri, 21 Mar 2025 11:53:16 -0600 Subject: [PATCH 3/4] update readme --- .github/workflows/daily.yml | 2 +- README.md | 2 ++ ci/release/release-js.sh | 39 +++++++++++++++++++++++++++++++++++++ ci/release/release.sh | 21 ++++++++++++++++++++ d2js/js/ci/build.sh | 16 +++++++-------- 5 files changed, 71 insertions(+), 9 deletions(-) create mode 100755 ci/release/release-js.sh diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index 0738b8b75..0fec115fa 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -51,7 +51,7 @@ jobs: - name: Publish nightly version to NPM if: steps.check_changes.outputs.has_changes == 'true' - run: COLOR=1 ./make.sh --version=nightly js + run: COLOR=1 NPM_VERSION=nightly ./make.sh js env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} GITHUB_TOKEN: ${{ secrets._GITHUB_TOKEN }} diff --git a/README.md b/README.md index 390b1a48a..7a9763a4d 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ [![ci](https://github.com/terrastruct/d2/actions/workflows/ci.yml/badge.svg)](https://github.com/terrastruct/d2/actions/workflows/ci.yml) [![daily](https://github.com/terrastruct/d2/actions/workflows/daily.yml/badge.svg)](https://github.com/terrastruct/d2/actions/workflows/daily.yml) [![release](https://img.shields.io/github/v/release/terrastruct/d2)](https://github.com/terrastruct/d2/releases) +[![changelog](https://img.shields.io/badge/changelog-read-blue)](./CHANGELOG.md) +[![npm version](https://img.shields.io/npm/v/@terrastruct/d2)](https://www.npmjs.com/package/@terrastruct/d2) [![discord](https://img.shields.io/discord/1039184639652265985?label=discord)](https://discord.gg/NF6X8K4eDq) [![twitter](https://img.shields.io/twitter/follow/terrastruct?style=social)](https://twitter.com/terrastruct) [![license](https://img.shields.io/github/license/terrastruct/d2?color=9cf)](./LICENSE.txt) diff --git a/ci/release/release-js.sh b/ci/release/release-js.sh new file mode 100755 index 000000000..5cb5abea6 --- /dev/null +++ b/ci/release/release-js.sh @@ -0,0 +1,39 @@ +#!/bin/sh +set -eu +cd -- "$(dirname "$0")/../.." +. "./ci/sub/lib.sh" + +VERSION="" + +help() { + cat < + +Publishes the d2.js to NPM. + +Flags: + --version Version to publish (e.g., "0.1.2" or "nightly"). Note this is the js version, not related to the d2 version. A non-nightly version will publish to latest. +EOF +} + +for arg in "$@"; do + case "$arg" in + --help|-h) + help + exit 0 + ;; + --version=*) + VERSION="${arg#*=}" + ;; + esac +done + +if [ -z "$VERSION" ]; then + flag_errusage "--version is required" +fi + +FGCOLOR=6 header "Publishing JavaScript package to NPM (version: $VERSION)" + +sh_c "NPM_VERSION=$VERSION ./make.sh js" + +FGCOLOR=2 header 'NPM publish completed' diff --git a/ci/release/release.sh b/ci/release/release.sh index 517ae778d..c85120722 100755 --- a/ci/release/release.sh +++ b/ci/release/release.sh @@ -1,5 +1,26 @@ #!/bin/sh set -eu cd -- "$(dirname "$0")/../.." +. "./ci/sub/lib.sh" + + +NPM_VERSION="" + +for arg in "$@"; do + case "$arg" in + --npm-version=*) + NPM_VERSION="${arg#*=}" + ;; + esac +done + +if [ -z "$NPM_VERSION" ]; then + flag_errusage "--npm-version is required" +fi ./ci/sub/release/release.sh "$@" + +if [ -n "$NPM_VERSION" ]; then + ./ci/release/release-js.sh --version="$NPM_VERSION" +fi + diff --git a/d2js/js/ci/build.sh b/d2js/js/ci/build.sh index 7d8771bfd..031269ed4 100755 --- a/d2js/js/ci/build.sh +++ b/d2js/js/ci/build.sh @@ -18,11 +18,11 @@ fi cd d2js/js sh_c bun build.js -if [ -n "$VERSION" ]; then +if [ -n "$NPM_VERSION" ]; then cp package.json package.json.bak trap 'rm -f .npmrc; mv package.json.bak package.json' EXIT - if [ "$VERSION" = "nightly" ]; then + if [ "$NPM_VERSION" = "nightly" ]; then echo "Publishing nightly version to npm..." DATE_TAG=$(date +'%Y%m%d') @@ -33,8 +33,8 @@ if [ -n "$VERSION" ]; then echo "Updating package version to ${PUBLISH_VERSION}" else - echo "Publishing official version ${VERSION} to npm..." - PUBLISH_VERSION="$VERSION" + echo "Publishing official version ${NPM_VERSION} to npm..." + PUBLISH_VERSION="$NPM_VERSION" NPM_TAG="latest" echo "Setting package version to ${PUBLISH_VERSION}" @@ -52,14 +52,14 @@ if [ -n "$VERSION" ]; then echo "Successfully published @terrastruct/d2@${PUBLISH_VERSION} to npm with tag '${NPM_TAG}'" # For official releases, bump the patch version - if [ "$VERSION" != "nightly" ]; then + if [ "$NPM_VERSION" != "nightly" ]; then # Restore original package.json first mv package.json.bak package.json - echo "Bumping version to ${VERSION}" - npm version "${VERSION}" --no-git-tag-version + echo "Bumping version to ${NPM_VERSION}" + npm version "${NPM_VERSION}" --no-git-tag-version git add package.json - git commit -m "Bump version to ${VERSION} [skip ci]" + git commit -m "Bump version to ${NPM_VERSION} [skip ci]" # Cancel the trap since we manually restored and don't want it to execute on exit trap - EXIT From 7887fb58424c6de7a4134a8dc3f7eab11f878943 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Fri, 21 Mar 2025 12:18:32 -0600 Subject: [PATCH 4/4] update --- d2js/js/ci/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/d2js/js/ci/build.sh b/d2js/js/ci/build.sh index 031269ed4..87a692196 100755 --- a/d2js/js/ci/build.sh +++ b/d2js/js/ci/build.sh @@ -18,7 +18,7 @@ fi cd d2js/js sh_c bun build.js -if [ -n "$NPM_VERSION" ]; then +if [ -n "${NPM_VERSION:-}" ]; then cp package.json package.json.bak trap 'rm -f .npmrc; mv package.json.bak package.json' EXIT