Merge pull request #2436 from alixander/d2js-ci

d2js nightly ci
This commit is contained in:
Alexander Wang 2025-03-20 21:12:23 -07:00 committed by GitHub
commit 578d2e2176
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 83 additions and 2 deletions

View file

@ -25,3 +25,34 @@ 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
- 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 }}
GITHUB_TOKEN: ${{ secrets._GITHUB_TOKEN }}
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}

View file

@ -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.
@ -162,6 +172,16 @@ You can browse the examples by running the dev server:
Visit `http://localhost:3000` to see the example page.
### Publishing
TODO stable release publishing.
Nightly builds are automated by CI by running:
```bash
PUBLISH=1 ./make.sh build
```
## Contributing
Contributions are welcome!

View file

@ -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

View file

@ -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",
@ -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",