Skip to content

Commit e41f256

Browse files
Merge pull request #117 from maejima-fumika/feature/add-notebook
Add notebook to run command in CLI.
2 parents 9f084a3 + b7559ff commit e41f256

23 files changed

Lines changed: 23134 additions & 4176 deletions

File tree

‎.github/workflows/release-components.yml‎

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ jobs:
2626
env:
2727
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2828

29-
release-lang-and-cli:
30-
name: Publish @bscript/lang and @bscript/cli
29+
release-lang-cli-notebook:
30+
name: Publish @bscript/lang, @bscript/cli, and @bscript/notebook
3131
runs-on: ubuntu-latest
3232
permissions:
3333
contents: read
@@ -46,6 +46,32 @@ jobs:
4646
- name: Install latest npm
4747
run: npm install -g npm@latest
4848

49+
- name: Determine npm dist-tag
50+
id: npm_tag
51+
run: |
52+
TAG_VERSION="${GITHUB_REF_NAME#v}"
53+
54+
if [ "${{ github.event.release.prerelease }}" = "true" ]; then
55+
NPM_TAG=$(node -e "
56+
const m = process.argv[1].match(/-([0-9A-Za-z-]+)/);
57+
if (!m) {
58+
console.error('::error::GitHub pre-release requires a semver prerelease segment (e.g. 2.0.0-alpha.1)');
59+
process.exit(1);
60+
}
61+
process.stdout.write(m[1]);
62+
" "$TAG_VERSION")
63+
echo "Pre-release: publishing to npm dist-tag '${NPM_TAG}' (version ${TAG_VERSION})"
64+
else
65+
if [[ "$TAG_VERSION" == *-* ]]; then
66+
echo "::error::Stable GitHub release must not use a prerelease version (${TAG_VERSION}). Mark the release as pre-release or use a stable version."
67+
exit 1
68+
fi
69+
NPM_TAG="latest"
70+
echo "Stable release: publishing to npm dist-tag 'latest' (version ${TAG_VERSION})"
71+
fi
72+
73+
echo "tag=${NPM_TAG}" >> "$GITHUB_OUTPUT"
74+
4975
- name: Verify Version of @bscript/lang Matches Tag
5076
run: |
5177
TAG_VERSION="${GITHUB_REF_NAME#v}"
@@ -73,6 +99,22 @@ jobs:
7399
fi
74100
echo "Version check of @bscript/cli passed: $TAG_VERSION"
75101
102+
- name: Verify Version of @bscript/notebook Matches Tag and @bscript/notebook Installs Correct @bscript/lang Version
103+
run: |
104+
TAG_VERSION="${GITHUB_REF_NAME#v}"
105+
PKG_VERSION=$(node -p "require('./notebook/package.json').version")
106+
DEP_LANG_VERSION=$(node -p "require('./notebook/package.json').dependencies['@bscript/lang']")
107+
108+
if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then
109+
echo "::error::Version Mismatch! Tag ($TAG_VERSION) != ./notebook/package.json ($PKG_VERSION)"
110+
exit 1
111+
fi
112+
if [ "$TAG_VERSION" != "$DEP_LANG_VERSION" ]; then
113+
echo "::error::Version Mismatch! @bscript/lang@($DEP_LANG_VERSION) in dependencies is incorrect."
114+
exit 1
115+
fi
116+
echo "Version check of @bscript/notebook passed: $TAG_VERSION"
117+
76118
- name: Install Dependencies
77119
run: npm ci
78120

@@ -81,8 +123,12 @@ jobs:
81123

82124
- name: Publish @bscript/lang to npm
83125
working-directory: ./lang
84-
run: npm publish || echo 'Failed or skipped publishing @bscript/lang'
126+
run: npm publish --tag ${{ steps.npm_tag.outputs.tag }} || echo 'Failed or skipped publishing @bscript/lang'
85127

86128
- name: Publish @bscript/cli to npm
87129
working-directory: ./cli
88-
run: npm publish || echo 'Failed or skipped publishing @bscript/cli'
130+
run: npm publish --tag ${{ steps.npm_tag.outputs.tag }} || echo 'Failed or skipped publishing @bscript/cli'
131+
132+
- name: Publish @bscript/notebook to npm
133+
working-directory: ./notebook
134+
run: npm publish --tag ${{ steps.npm_tag.outputs.tag }} || echo 'Failed or skipped publishing @bscript/notebook'

‎.github/workflows/release-website.yml‎

Lines changed: 98 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
workflow_dispatch:
77
inputs:
88
version:
9-
description: 'Version number (e.g. 1.0.0)'
9+
description: 'Version number (e.g. 2.0.5 or 2.1.0-alpha.1)'
1010
required: true
1111

1212
jobs:
@@ -37,20 +37,107 @@ jobs:
3737
- name: Determine Version
3838
id: determine_version
3939
run: |
40-
# 1. Get raw version number (e.g., 1.0.0 or 1.0.5)
40+
# 1. Get raw version number (e.g. 2.0.5 or 2.1.0-alpha.1)
4141
if [ "${{ github.event_name }}" == "release" ]; then
4242
TAG_NAME=${{ github.ref_name }}
4343
RAW_VERSION=${TAG_NAME#v}
44+
IS_PRERELEASE="${{ github.event.release.prerelease }}"
4445
else
45-
RAW_VERSION=${{ inputs.version }}
46+
RAW_VERSION="${{ inputs.version }}"
47+
if [[ "$RAW_VERSION" == *-* ]]; then
48+
IS_PRERELEASE="true"
49+
else
50+
IS_PRERELEASE="false"
51+
fi
4652
fi
4753
echo "Detected raw version: $RAW_VERSION"
54+
echo "Pre-release: $IS_PRERELEASE"
55+
56+
# 2. Validate GitHub release type vs semver
57+
if [ "${{ github.event_name }}" == "release" ]; then
58+
if [ "$IS_PRERELEASE" = "true" ] && [[ "$RAW_VERSION" != *-* ]]; then
59+
echo "::error::GitHub pre-release requires a semver prerelease segment (e.g. 2.1.0-alpha.1)"
60+
exit 1
61+
fi
62+
if [ "$IS_PRERELEASE" != "true" ] && [[ "$RAW_VERSION" == *-* ]]; then
63+
echo "::error::Stable GitHub release must not use a prerelease version (${RAW_VERSION}). Mark the release as pre-release or use a stable version."
64+
exit 1
65+
fi
66+
fi
67+
68+
# 3. Convert to Docusaurus doc version
69+
if [ "$IS_PRERELEASE" = "true" ]; then
70+
DOC_VERSION=$(node -e "
71+
const m = process.argv[1].match(/^(\d+\.\d+\.\d+)-([0-9A-Za-z-]+)/);
72+
if (!m) {
73+
console.error('::error::Could not derive doc version from prerelease (${RAW_VERSION}). Expected format like 2.1.0-alpha.1');
74+
process.exit(1);
75+
}
76+
process.stdout.write(m[1] + '-' + m[2].split('.')[0] + '.x');
77+
" "$RAW_VERSION")
78+
else
79+
BASE_VER=${RAW_VERSION%.*}
80+
DOC_VERSION="${BASE_VER}.x"
81+
fi
4882
49-
# 2. Convert to .x format (e.g., 1.0.5 -> 1.0.x)
50-
BASE_VER=${RAW_VERSION%.*}
51-
DOC_VERSION="${BASE_VER}.x"
5283
echo "Target Docusaurus Version: $DOC_VERSION"
5384
echo "doc_version=$DOC_VERSION" >> $GITHUB_OUTPUT
85+
echo "is_prerelease=$IS_PRERELEASE" >> $GITHUB_OUTPUT
86+
echo "raw_version=$RAW_VERSION" >> $GITHUB_OUTPUT
87+
88+
- name: Remove prerelease doc versions on stable release
89+
if: steps.determine_version.outputs.is_prerelease != 'true'
90+
working-directory: ./website
91+
env:
92+
RAW_VERSION: ${{ steps.determine_version.outputs.raw_version }}
93+
run: |
94+
VERSIONS_JSON="versions.json"
95+
96+
remove_doc_version() {
97+
local v="$1"
98+
local VERSION_DIR="versioned_docs/version-$v"
99+
local SIDEBAR_FILE="versioned_sidebars/version-$v-sidebars.json"
100+
101+
echo "Removing prerelease doc version: $v"
102+
103+
if [ -d "$VERSION_DIR" ]; then
104+
rm -rf "$VERSION_DIR"
105+
echo "Removed $VERSION_DIR"
106+
fi
107+
108+
if [ -f "$SIDEBAR_FILE" ]; then
109+
rm -f "$SIDEBAR_FILE"
110+
echo "Removed $SIDEBAR_FILE"
111+
fi
112+
113+
if [ -f "$VERSIONS_JSON" ]; then
114+
tmp=$(mktemp)
115+
jq --arg v "$v" 'map(select(. != $v))' "$VERSIONS_JSON" > "$tmp" && mv "$tmp" "$VERSIONS_JSON"
116+
echo "Removed $v from $VERSIONS_JSON"
117+
fi
118+
}
119+
120+
# e.g. stable 2.1.0 -> 2.1.0-alpha.x, 2.1.0-beta.x
121+
PRERELEASE_VERSIONS=$(
122+
{
123+
if [ -f "$VERSIONS_JSON" ]; then
124+
jq -r --arg raw "$RAW_VERSION" '.[] | select(startswith($raw + "-") and endswith(".x"))' "$VERSIONS_JSON"
125+
fi
126+
shopt -s nullglob
127+
for dir in versioned_docs/version-"${RAW_VERSION}"-*.x; do
128+
basename "$dir" | sed 's/^version-//'
129+
done
130+
} | sort -u
131+
)
132+
133+
if [ -z "$PRERELEASE_VERSIONS" ]; then
134+
echo "No prerelease doc versions found for stable release ${RAW_VERSION}."
135+
exit 0
136+
fi
137+
138+
while IFS= read -r v; do
139+
[ -n "$v" ] && remove_doc_version "$v"
140+
done <<< "$PRERELEASE_VERSIONS"
54141
55142
- name: Clean up existing version (if any)
56143
working-directory: ./website
@@ -95,8 +182,8 @@ jobs:
95182
uses: peter-evans/create-pull-request@v6
96183
with:
97184
token: ${{ secrets.GITHUB_TOKEN }}
98-
commit-message: "docs: update version ${{ steps.determine_version.outputs.doc_version }}"
99-
title: "docs: update version ${{ steps.determine_version.outputs.doc_version }}"
100-
body: "Automated docs update for version ${{ steps.determine_version.outputs.doc_version }}"
101-
branch: "docs-version-${{ steps.determine_version.outputs.doc_version }}"
102-
base: main
185+
commit-message: ${{ steps.determine_version.outputs.is_prerelease == 'true' && format('docs: update pre-release version {0} ({1})', steps.determine_version.outputs.doc_version, steps.determine_version.outputs.raw_version) || format('docs: update version {0}', steps.determine_version.outputs.doc_version) }}
186+
title: ${{ steps.determine_version.outputs.is_prerelease == 'true' && format('docs: update pre-release version {0} ({1})', steps.determine_version.outputs.doc_version, steps.determine_version.outputs.raw_version) || format('docs: update version {0}', steps.determine_version.outputs.doc_version) }}
187+
body: ${{ steps.determine_version.outputs.is_prerelease == 'true' && format('Automated docs update for pre-release {0} (tag version {1}).', steps.determine_version.outputs.doc_version, steps.determine_version.outputs.raw_version) || format('Automated docs update for version {0}.', steps.determine_version.outputs.doc_version) }}
188+
branch: docs-version-${{ steps.determine_version.outputs.doc_version }}
189+
base: main

‎cli/package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@
4848
"dependencies": {
4949
"@abandonware/noble": "^1.9.2-26",
5050
"@bscript/lang": "2.0.2",
51+
"@bscript/notebook": "2.0.2",
5152
"axios": "^1.12.2",
5253
"chalk": "^4.1.2",
5354
"commander": "^14.0.1",
5455
"extract-zip": "^2.0.1",
5556
"inquirer": "^12.11.0",
5657
"serialport": "^13.0.0",
58+
"sirv": "^3.0.2",
5759
"zod": "^4.1.11"
5860
}
5961
}

0 commit comments

Comments
 (0)