From c94605551170a6148bcfa0477d3c280c2e8a0924 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Thu, 20 Mar 2025 21:56:41 -0600 Subject: [PATCH 1/5] d2js ci --- .github/workflows/daily.yml | 18 ++++++++++++++++++ d2js/js/README.md | 10 ++++++++++ d2js/js/ci/build.sh | 30 ++++++++++++++++++++++++++++++ d2js/js/package.json | 2 +- 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index 1a7075a1f..1275cfb66 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -25,3 +25,21 @@ jobs: with: name: d2chaos path: ./d2chaos/out + npm-nightly: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 # Needed for git history and version tags + + - uses: actions/setup-go@v4 + with: + go-version-file: ./go.mod + cache: true + + - name: Publish nightly version to NPM + run: COLOR=1 PUBLISH=1 ./make.sh js + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + GITHUB_TOKEN: ${{ secrets._GITHUB_TOKEN }} + DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} diff --git a/d2js/js/README.md b/d2js/js/README.md index 55cb9e159..4cf7cf016 100644 --- a/d2js/js/README.md +++ b/d2js/js/README.md @@ -162,6 +162,16 @@ You can browse the examples by running the dev server: Visit `http://localhost:3000` to see the example page. +### Publishing + +WIP. + +Nightly builds are automated by CI upon pull request merging by running: + +```bash +PUBLISH=1 ./make.sh build +``` + ## Contributing Contributions are welcome! diff --git a/d2js/js/ci/build.sh b/d2js/js/ci/build.sh index f081d8e4f..3d78c0433 100755 --- a/d2js/js/ci/build.sh +++ b/d2js/js/ci/build.sh @@ -17,3 +17,33 @@ 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}" + + 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 + + echo "Publishing to npm with tag 'nightly'..." + if [ -n "${NPM_TOKEN-}" ]; then + 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'" + else + echoerr "Failed to publish package to npm" + exit 1 + fi + else + echoerr "NPM_TOKEN environment variable is required for publishing to npm" + exit 1 + fi +fi diff --git a/d2js/js/package.json b/d2js/js/package.json index a876c24be..0c3f84c6c 100644 --- a/d2js/js/package.json +++ b/d2js/js/package.json @@ -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": "./make.sh all" + "prepublishOnly": "PUBLISH=0 ./make.sh all" }, "keywords": [ "d2", From 36df3344a3b69d165752345d68a855c8247dafdb Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Thu, 20 Mar 2025 22:01:56 -0600 Subject: [PATCH 2/5] run daily --- .github/workflows/daily.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index 1275cfb66..1e259799c 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -32,12 +32,25 @@ jobs: with: fetch-depth: 0 # Needed for git history and version tags + - name: Check for changes + id: check_changes + run: | + if [ $(git rev-list --count --since="24 hours ago" HEAD) -gt 0 ]; then + echo "has_changes=true" >> $GITHUB_OUTPUT + echo "Found changes in the last 24 hours, proceeding to publish d2js nightly" + else + echo "has_changes=false" >> $GITHUB_OUTPUT + echo "No changes in the last 24 hours, skipping d2js nightly publish" + fi + - uses: actions/setup-go@v4 + if: steps.check_changes.outputs.has_changes == 'true' with: go-version-file: ./go.mod cache: true - name: Publish nightly version to NPM + if: steps.check_changes.outputs.has_changes == 'true' run: COLOR=1 PUBLISH=1 ./make.sh js env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} From 3536f9846adfb89643f73164fc54b716ddfdf838 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Thu, 20 Mar 2025 22:02:49 -0600 Subject: [PATCH 3/5] update readme --- d2js/js/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/d2js/js/README.md b/d2js/js/README.md index 4cf7cf016..bb3166849 100644 --- a/d2js/js/README.md +++ b/d2js/js/README.md @@ -164,9 +164,9 @@ Visit `http://localhost:3000` to see the example page. ### Publishing -WIP. +TODO stable release publishing. -Nightly builds are automated by CI upon pull request merging by running: +Nightly builds are automated by CI by running: ```bash PUBLISH=1 ./make.sh build From e073d06b39039016c1c09c5d3c9e1f9dce0dcad9 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Thu, 20 Mar 2025 22:03:37 -0600 Subject: [PATCH 4/5] bump version --- d2js/js/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/d2js/js/package.json b/d2js/js/package.json index 0c3f84c6c..4775805e0 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.21", + "version": "0.1.22", "repository": { "type": "git", "url": "git+https://github.com/terrastruct/d2.git", From bb5b0224cba89a042f43937dc24976379591704a Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Thu, 20 Mar 2025 22:06:46 -0600 Subject: [PATCH 5/5] readme --- d2js/js/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/d2js/js/README.md b/d2js/js/README.md index bb3166849..76f0132f3 100644 --- a/d2js/js/README.md +++ b/d2js/js/README.md @@ -29,6 +29,16 @@ pnpm add @terrastruct/d2 bun add @terrastruct/d2 ``` +### Nightly + +Use the `@nightly` tag to get the version that is built by daily CI on the master branch. + +For example, + +```bash +yarn add @terrastruct/d2@nightly +``` + ## Usage D2.js uses webworkers to call a WASM file.