Skip to content
Merged
21 changes: 4 additions & 17 deletions .github/workflows/build-gems.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:

push:
branches: [main]
tags: ["v*"]
paths:
- "src/**"
- "lib/**"
Expand All @@ -17,6 +16,7 @@ on:
- "Makefile"
- "Rakefile"
- ".ruby-version"
- "config.yml"

pull_request:
paths:
Expand All @@ -28,6 +28,7 @@ on:
- "Makefile"
- "Rakefile"
- ".ruby-version"
- "config.yml"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -110,21 +111,6 @@ jobs:
permissions:
contents: write
id-token: write
strategy:
fail-fast: false
matrix:
target:
- default
- aarch64-linux-gnu
- x86_64-linux-gnu
- x86_64-linux-musl
- aarch64-linux-musl
- x86_64-darwin
- arm64-darwin
- arm-linux-gnu
- arm-linux-musl
- x86-linux-gnu
- x86-linux-musl
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -147,8 +133,9 @@ jobs:
- name: Download gem artifacts
uses: actions/download-artifact@v4
with:
name: gem-${{ matrix.target }}
pattern: gem-*
path: pkg/
merge-multiple: true

- name: Configure trusted publishing credentials
uses: rubygems/configure-rubygems-credentials@v1.0.0
Expand Down
128 changes: 128 additions & 0 deletions .github/workflows/javascript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
branches:
- main
pull_request:
pull_request_review:
types: [submitted]
release:
types: [published]

permissions:
actions: read
Expand Down Expand Up @@ -59,14 +63,26 @@ jobs:
run: yarn playwright install

- name: Build tailwind-class-sorter package
env:
RELEASE_BUILD: ${{ github.event_name == 'release' && 'true' || 'false' }}
run: yarn nx build @herb-tools/tailwind-class-sorter

- name: Run `build` for all NX packages
env:
RELEASE_BUILD: ${{ github.event_name == 'release' && 'true' || 'false' }}
run: yarn build

- name: Run `test` for all NX packages
run: yarn test

- name: Upload package artifacts
uses: actions/upload-artifact@v4
with:
name: npm-packages
path: javascript/packages/*/
if-no-files-found: error
retention-days: 1

# NX is not able to properly detect affected changes if things change in C source or the WASM build
#
# - name: Set NX SHAs
Expand All @@ -75,3 +91,115 @@ jobs:
# # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected
# - run: npx nx affected -t build
# - run: npx nx affected -t test

publish:
name: Publish packages to npm
if: github.event_name == 'release' && github.repository_owner == 'marcoroth'
needs: main
runs-on: ubuntu-latest
timeout-minutes: 30

permissions:
contents: read
id-token: write

steps:
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'

- name: Download package artifacts
uses: actions/download-artifact@v4
with:
name: npm-packages
path: javascript/packages/

- name: Publish packages with provenance
run: |
for package_dir in javascript/packages/*; do
if [ -d "$package_dir" ] && [ -f "$package_dir/package.json" ]; then
package=$(basename "$package_dir")

if [ "$package" = "vscode" ]; then
echo "Skipping vscode package..."
continue
fi

echo "Publishing $package..."
(cd "$package_dir" && npm publish --provenance --access public)
fi
done

preview-check:
if: |
(github.repository == 'marcoroth/herb' && github.event_name == 'pull_request' && github.event.pull_request.user.login == github.repository_owner) ||
(github.repository == 'marcoroth/herb' && github.event_name == 'pull_request_review' && github.event.review.state == 'approved')

runs-on: ubuntu-latest
outputs:
has-permissions: ${{ steps.check.outputs.require-result }}

steps:
- name: Check permissions
id: check
uses: actions-cool/check-user-permission@v2
with:
require: write

preview:
name: Publish preview packages
needs: [main, preview-check]
if: needs.preview-check.outputs.has-permissions == 'true'
runs-on: ubuntu-latest

permissions:
contents: read
pull-requests: write

steps:
- uses: actions/setup-node@v4
with:
node-version: 20

- name: Download package artifacts
uses: actions/download-artifact@v4
with:
name: npm-packages
path: javascript/packages/

- name: Publish preview packages
run: npx pkg-pr-new publish --compact --comment=update --bin --no-template './javascript/packages/formatter' './javascript/packages/linter' './javascript/packages/language-server'

publish-vscode:
name: Publish VSCode extension
if: github.event_name == 'release' && github.repository_owner == 'marcoroth'
needs: main
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
- uses: actions/setup-node@v4
with:
node-version: 20

- name: Download package artifacts
uses: actions/download-artifact@v4
with:
name: npm-packages
path: javascript/packages/

- name: Publish to VS Code Marketplace
env:
VSCE_PAT: ${{ secrets.VSCE_PAT }}
run: |
cd javascript/packages/vscode
npx @vscode/vsce publish

- name: Publish to Open VSX Registry
env:
OVSX_PAT: ${{ secrets.OVSX_PAT }}
run: |
cd javascript/packages/vscode
npx ovsx publish -p $OVSX_PAT
42 changes: 42 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches:
- main
pull_request:
release:
types: [published]

permissions:
actions: read
Expand Down Expand Up @@ -74,3 +76,43 @@ jobs:
- name: Test cargo package
run: cargo package --allow-dirty
working-directory: rust

- name: Upload Rust artifacts
if: github.event_name == 'release'
uses: actions/upload-artifact@v4
with:
name: rust-package
path: rust/
if-no-files-found: error
retention-days: 1

publish:
name: Publish to crates.io
if: github.event_name == 'release' && github.repository_owner == 'marcoroth'
needs: build
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
id-token: write
steps:
- name: Download Rust artifacts
uses: actions/download-artifact@v4
with:
name: rust-package
path: rust/

- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable

- name: Authenticate with crates.io
uses: rust-lang/crates-io-auth-action@v1
id: auth

- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
run: cargo publish --allow-dirty
working-directory: rust
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@

<p align="center">
<a href="https://rubygems.org/gems/herb"><img alt="Gem Version" src="https://img.shields.io/gem/v/herb"></a>
<a href="https://crates.io/crates/herb"><img alt="Crates.io Version" src="https://img.shields.io/crates/v/herb"></a>
<a href="https://www.npmjs.com/package/@herb-tools/core"><img alt="npm Version" src="https://img.shields.io/npm/v/@herb-tools/core"></a>
<a href="https://marketplace.visualstudio.com/items?itemName=marcoroth.herb-lsp"><img alt="VS Code Marketplace" src="https://img.shields.io/visual-studio-marketplace/v/marcoroth.herb-lsp"></a>
<a href="https://open-vsx.org/extension/marcoroth/herb-lsp"><img alt="Open VSX" src="https://img.shields.io/open-vsx/v/marcoroth/herb-lsp"></a>
<a href="https://herb-tools.dev"><img alt="Documentation" src="https://img.shields.io/badge/documentation-available-green"></a>
<a href="https://herb-tools.dev/playground"><img alt="playground" src="https://img.shields.io/badge/playground-Try_it_in_the_browser!-green"></a>
<a href="https://pkg.pr.new/~/marcoroth/herb"><img alt="pkg.pr.new" src="https://pkg.pr.new/badge/marcoroth/herb"></a>
<a href="https://github.com/marcoroth/herb/blob/main/LICENSE.txt"><img alt="License" src="https://img.shields.io/github/license/marcoroth/herb"></a>
<a href="https://github.com/marcoroth/herb/issues"><img alt="Issues" src="https://img.shields.io/github/issues/marcoroth/herb"></a>
</p>
Expand Down Expand Up @@ -99,7 +104,7 @@ Commands:
bundle exec herb version Prints the versions of the Herb gem and the libherb library.
```

For detailed information, like how you can use Herb programatically in Ruby and JavaScript, visit the [documentation site](https://herb-tools.dev/bindings/ruby/reference).
For detailed information, like how you can use Herb programmatically in Ruby and JavaScript, visit the [documentation site](https://herb-tools.dev/bindings/ruby/reference).


## Background and Talk
Expand Down
44 changes: 44 additions & 0 deletions docs/docs/bindings/javascript/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,50 @@ Herb.load().then(() => {

You are now ready to parse HTML+ERB in Node.js.

## Using Unreleased Commits

Each commit on the `main` branch and pull requests with approved reviews are published to [pkg.pr.new](https://pkg.pr.new/~/marcoroth/herb). You can install preview packages directly from commits or PRs:

:::code-group
```shell [npm]
npm i https://pkg.pr.new/@herb-tools/core@{commit}
```

```shell [pnpm]
pnpm add https://pkg.pr.new/@herb-tools/core@{commit}
```

```shell [yarn]
yarn add https://pkg.pr.new/@herb-tools/core@{commit}
```

```shell [bun]
bun add https://pkg.pr.new/@herb-tools/core@{commit}
```
:::

Replace `{commit}` with the short commit SHA (e.g., `0d2eabe`) or branch name (e.g., `main`).

### Running CLI Tools from Previews

You can also run CLI tools directly from preview releases without installing:

:::code-group
```shell [Linter]
npx https://pkg.pr.new/@herb-tools/linter@{commit} template.html.erb
```

```shell [Formatter]
npx https://pkg.pr.new/@herb-tools/formatter@{commit} template.html.erb
```

```shell [Language Server]
npx https://pkg.pr.new/@herb-tools/language-server@{commit} --stdio
```
:::

This is perfect for testing bug fixes or new features before they're officially released!

## Getting Started

Regardless of whether you imported `Herb` from `@herb-tools/browser` or `@herb-tools/node`, the API remains the same for both packages.
2 changes: 1 addition & 1 deletion docs/docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ title: Getting Started
<h1 align="center" style="margin-top: 30px; font-size: 20pt;">Herb</h1>
</div>

<!-- @include: ../../README.md{21,} -->
<!-- @include: ../../README.md{25,} -->
10 changes: 10 additions & 0 deletions javascript/packages/formatter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ For occasional use without installing:
npx @herb-tools/formatter template.html.erb
```

### Preview Releases

Want to try unreleased features? Use pkg.pr.new to run the formatter from any commit or PR:

```bash
npx https://pkg.pr.new/@herb-tools/formatter@{commit} template.html.erb
```

Replace `{commit}` with a commit SHA (e.g., `0d2eabe`) or branch name (e.g., `main`). Find available previews at [pkg.pr.new/~/marcoroth/herb](https://pkg.pr.new/~/marcoroth/herb).

### Project Installation

:::code-group
Expand Down
10 changes: 10 additions & 0 deletions javascript/packages/language-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ npm install -g @herb-tools/language-server
yarn global add @herb-tools/language-server
```

##### Preview Releases

Want to try unreleased features? Use pkg.pr.new to run the language server from any commit or PR:

```bash
npx https://pkg.pr.new/@herb-tools/language-server@{commit} --stdio
```

Replace `{commit}` with a commit SHA (e.g., `0d2eabe`) or branch name (e.g., `main`). Find available previews at [pkg.pr.new/~/marcoroth/herb](https://pkg.pr.new/~/marcoroth/herb).

##### Run

```bash
Expand Down
Loading
Loading