This commit is contained in:
Alexander Wang 2025-03-20 21:56:41 -06:00
parent e9353e74dc
commit c946055511
No known key found for this signature in database
GPG key ID: BE3937D0D52D8927
4 changed files with 59 additions and 1 deletions

View file

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

View file

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

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

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