@@ -168,3 +168,83 @@ jobs:
168168 if : steps.check-exists.outputs.exists == 'true' && steps.detect.outputs.is_tag != 'true'
169169 run : |
170170 echo "⏭️ Pre-release version already exists, skipping"
171+
172+ publish-demo :
173+ name : publish @ghostty-web/demo to npm
174+ runs-on : ubuntu-latest
175+ needs : publish
176+ if : ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'push' }}
177+ steps :
178+ - name : Checkout code
179+ uses : actions/checkout@v4
180+ with :
181+ ref : ${{ github.ref }}
182+ fetch-depth : 0
183+
184+ - name : Setup Node.js for npm
185+ uses : actions/setup-node@v4
186+ with :
187+ node-version : ' 20'
188+ registry-url : ' https://registry.npmjs.org'
189+
190+ - run : npm install -g npm@latest
191+
192+ - name : Detect trigger type
193+ id : detect
194+ run : |
195+ if [[ $GITHUB_REF == refs/tags/* ]]; then
196+ echo "is_tag=true" >> $GITHUB_OUTPUT
197+ echo "trigger_name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
198+ else
199+ echo "is_tag=false" >> $GITHUB_OUTPUT
200+ echo "trigger_name=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
201+ fi
202+
203+ - name : Generate demo version
204+ id : version
205+ working-directory : demo
206+ run : |
207+ BASE_VERSION=$(jq -r .version package.json)
208+
209+ if [[ "${{ steps.detect.outputs.is_tag }}" == "true" ]]; then
210+ NPM_VERSION="${BASE_VERSION}"
211+ NPM_TAG="latest"
212+ GHOSTTY_WEB_DEP="latest"
213+ else
214+ GIT_COMMIT=$(git rev-parse --short HEAD)
215+ COMMITS_SINCE_TAG=$(git rev-list --count HEAD ^$(git describe --tags --abbrev=0 2>/dev/null || echo HEAD) 2>/dev/null || echo "0")
216+ NPM_VERSION="${BASE_VERSION}-next.${COMMITS_SINCE_TAG}.g${GIT_COMMIT}"
217+ NPM_TAG="next"
218+ GHOSTTY_WEB_DEP="next"
219+ fi
220+
221+ echo "version=${NPM_VERSION}" >> $GITHUB_OUTPUT
222+ echo "tag=${NPM_TAG}" >> $GITHUB_OUTPUT
223+
224+ # Update version and ghostty-web dependency
225+ node -e "
226+ const fs = require('fs');
227+ const pkg = JSON.parse(fs.readFileSync('package.json'));
228+ pkg.version = '${NPM_VERSION}';
229+ pkg.dependencies['ghostty-web'] = '${GHOSTTY_WEB_DEP}';
230+ fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
231+ "
232+ echo "Updated demo package.json: version=${NPM_VERSION}, ghostty-web=${GHOSTTY_WEB_DEP}"
233+
234+ - name : Check if demo version exists
235+ id : check-exists
236+ working-directory : demo
237+ run : |
238+ PACKAGE_NAME=$(node -p "require('./package.json').name")
239+ VERSION="${{ steps.version.outputs.version }}"
240+
241+ if npm view "${PACKAGE_NAME}@${VERSION}" version &>/dev/null; then
242+ echo "exists=true" >> $GITHUB_OUTPUT
243+ else
244+ echo "exists=false" >> $GITHUB_OUTPUT
245+ fi
246+
247+ - name : Publish demo to npm
248+ if : steps.check-exists.outputs.exists == 'false'
249+ working-directory : demo
250+ run : npm publish --tag ${{ steps.version.outputs.tag }} --provenance --access public
0 commit comments