Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/check_updates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: check_updates

on:
workflow_dispatch:
schedule:
# do this once per day
- cron: "0 7 * * *"

jobs:
build:
name: check updates
if: github.repository == 'dprint/dprint-plugin-sql'
runs-on: ubuntu-latest
timeout-minutes: 45

steps:
- name: Clone repository
uses: actions/checkout@v6
with:
token: ${{ secrets.GH_DPRINTBOT_PAT }}

- uses: denoland/setup-deno@v2
- uses: dsherret/rust-toolchain-file@v1

- name: Run script
run: |
git config user.email "dprintbot@users.noreply.github.com"
git config user.name "dprintbot"
deno run -A ./scripts/update.ts
# This is necessary to prevent GH automatically disabling this workflow after 60 days.
workflow-keepalive:
if: github.event_name == 'schedule'
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- uses: liskin/gh-workflow-keepalive@f72ff1a1336129f29bf0166c0fd0ca6cf1bcb38c
222 changes: 96 additions & 126 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,126 +1,96 @@
name: CI

on: [push, pull_request]

jobs:
build:
name: ${{ matrix.config.kind }} ${{ matrix.config.os }}
runs-on: ${{ matrix.config.os }}
strategy:
matrix:
config:
- os: ubuntu-latest
kind: test_release
- os: ubuntu-latest
kind: test_debug

env:
CARGO_INCREMENTAL: 0
RUST_BACKTRACE: full

steps:
- uses: actions/checkout@v3
- uses: dsherret/rust-toolchain-file@v1
- name: Install wasm32 target
if: matrix.config.kind == 'test_release'
run: rustup target add wasm32-unknown-unknown

- uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref == 'refs/heads/main' }}

- name: Build debug
if: matrix.config.kind == 'test_debug'
run: cargo build --verbose
- name: Build release
if: matrix.config.kind == 'test_release'
run: cargo build --target wasm32-unknown-unknown --features wasm --release --verbose

- name: Test debug
if: matrix.config.kind == 'test_debug'
run: cargo test --verbose
- name: Test release
if: matrix.config.kind == 'test_release'
run: cargo test --release --verbose

- name: Get tag version
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
id: get_tag_version
run: echo ::set-output name=TAG_VERSION::${GITHUB_REF/refs\/tags\//}

# NPM
- uses: actions/setup-node@v2
if: matrix.config.kind == 'test_release'
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'

- name: Setup and test npm deployment
if: matrix.config.kind == 'test_release'
run: |
cd deployment/npm
npm install
node setup.js ${{ steps.get_tag_version.outputs.TAG_VERSION }}
npm run test

- name: npm publish
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
cd deployment/npm
npm publish --access public
git reset --hard

# CARGO PUBLISH
- name: Cargo login
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
run: cargo login ${{ secrets.CRATES_TOKEN }}

- name: Cargo publish
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
run: cargo publish

# GITHUB RELEASE
- name: Pre-release
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
run: |
# update config schema to have version
sed -i 's/sql\/0.0.0/sql\/${{ steps.get_tag_version.outputs.TAG_VERSION }}/' deployment/schema.json
# rename the wasm file
(cd target/wasm32-unknown-unknown/release/ && mv dprint_plugin_sql.wasm plugin.wasm)
- name: Release
uses: softprops/action-gh-release@v1
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: |
target/wasm32-unknown-unknown/release/plugin.wasm
deployment/schema.json
body: |
## Install

[Install](https://dprint.dev/install/) and [setup](https://dprint.dev/setup/) dprint.

Then in your project's dprint configuration file:

1. Specify the plugin url in the `"plugins"` array.
2. Add a `"sql"` configuration property if desired.
```jsonc
{
// ...etc...
"sql": {
// sql config goes here
},
"plugins": [
"https://plugins.dprint.dev/sql-${{ steps.get_tag_version.outputs.TAG_VERSION }}.wasm"
]
}
```

## JS Formatting API

* [JS Formatter](https://github.com/dprint/js-formatter) - Browser/Deno and Node
* [npm package](https://www.npmjs.com/package/@dprint/sql)
draft: false
name: CI

on:
push:
branches: [main]
tags:
- '*'
pull_request:
branches: [main]

jobs:
build:
name: ${{ matrix.config.kind }} ${{ matrix.config.os }}
runs-on: ${{ matrix.config.os }}
strategy:
matrix:
config:
- os: ubuntu-latest
kind: test_release
- os: ubuntu-latest
kind: test_debug

env:
CARGO_INCREMENTAL: 0
RUST_BACKTRACE: full

steps:
- uses: actions/checkout@v6
- uses: dsherret/rust-toolchain-file@v1
- name: Install wasm32 target
if: matrix.config.kind == 'test_release'
run: rustup target add wasm32-unknown-unknown

- uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref == 'refs/heads/main' }}

- name: Build debug
if: matrix.config.kind == 'test_debug'
run: cargo build
- name: Build release
if: matrix.config.kind == 'test_release'
run: cargo build --target wasm32-unknown-unknown --features wasm --release

- name: Test debug
if: matrix.config.kind == 'test_debug'
run: cargo test
- name: Test release
if: matrix.config.kind == 'test_release'
run: cargo test --release

- name: Get tag version
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
id: get_tag_version
run: echo "TAG_VERSION=${GITHUB_REF/refs\/tags\//}" >> "$GITHUB_OUTPUT"

# NPM
- uses: actions/setup-node@v6
if: matrix.config.kind == 'test_release'
with:
node-version: '24.x'
registry-url: 'https://registry.npmjs.org'

- name: Setup and test npm deployment
if: matrix.config.kind == 'test_release'
run: |
cd deployment/npm
npm install
node setup.js
npm run test

# GITHUB RELEASE
- uses: denoland/setup-deno@v2
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
with:
deno-version: v2.x
- name: Pre-release
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
run: |
# update config schema to have version
sed -i 's/sql\/0.0.0/sql\/${{ steps.get_tag_version.outputs.TAG_VERSION }}/' deployment/schema.json
# rename the wasm file
(cd target/wasm32-unknown-unknown/release/ && mv dprint_plugin_sql.wasm plugin.wasm)
# create release notes
deno run -A ./scripts/generateReleaseNotes.ts ${{ steps.get_tag_version.outputs.TAG_VERSION }} > ${{ github.workspace }}-CHANGELOG.txt
- name: Release
uses: softprops/action-gh-release@v2
if: matrix.config.kind == 'test_release' && startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: |
target/wasm32-unknown-unknown/release/plugin.wasm
deployment/schema.json
body_path: ${{ github.workspace }}-CHANGELOG.txt
draft: false
38 changes: 38 additions & 0 deletions .github/workflows/publish_npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: publish npm

on:
workflow_dispatch:
push:
tags:
- '*'

permissions:
id-token: write
contents: read

jobs:
build:
name: publish-npm
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: dsherret/rust-toolchain-file@v1
- name: Install wasm32 target
run: rustup target add wasm32-unknown-unknown
- name: Build release
run: cargo build --target wasm32-unknown-unknown --features wasm --release

- uses: actions/setup-node@v6
with:
node-version: '24.x'
registry-url: 'https://registry.npmjs.org'
- name: Setup and test npm deployment
run: |
cd deployment/npm
npm install
node setup.js sync-version
npm run test
- name: npm publish
run: |
cd deployment/npm
npm publish --access public
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ jobs:

steps:
- name: Clone repository
uses: actions/checkout@v3
uses: actions/checkout@v6
with:
token: ${{ secrets.GH_DPRINTBOT_PAT }}

- uses: denoland/setup-deno@v1
- uses: denoland/setup-deno@v2
- uses: dsherret/rust-toolchain-file@v1

- name: Bump version and tag
Expand All @@ -34,4 +34,4 @@ jobs:
run: |
git config user.email "${{ github.actor }}@users.noreply.github.com"
git config user.name "${{ github.actor }}"
deno run -A https://raw.githubusercontent.com/dprint/automation/0.5.1/tasks/publish_release.ts --${{github.event.inputs.releaseKind}}
deno run -A https://raw.githubusercontent.com/dprint/automation/0.10.0/tasks/publish_release.ts --${{github.event.inputs.releaseKind}}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.claude
/target
Cargo.lock
deployment/npm/buffer.generated.js
deployment/npm/plugin.wasm
deployment/npm/node_modules
2 changes: 1 addition & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
max_width = 120
tab_spaces = 2
edition = "2021"
edition = "2024"
45 changes: 45 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# dprint-plugin-sql

Wrapper around [sqlformat-rs](https://github.com/shssoichiro/sqlformat-rs) for use as a dprint formatting plugin.

## Commands

- `cargo test` — run all tests
- `cargo build --target wasm32-unknown-unknown --features wasm --release` — build the wasm plugin
- `cd deployment/npm && node setup.js && npm test` — test the npm package (requires wasm build first)

## Architecture

- `src/format_text.rs` — core formatting logic, delegates to `sqlformat::format()`
- `src/wasm_plugin.rs` — dprint wasm plugin interface (compiled only for wasm32 target with `wasm` feature)
- `src/configuration/` — config types, resolution, and builder
- `deployment/npm/` — npm package that ships `plugin.wasm`
- `deployment/schema.json` — JSON schema for plugin configuration
- `scripts/update.ts` — Deno script that checks crates.io for new sqlformat versions and auto-publishes
- `scripts/generateReleaseNotes.ts` — generates changelog for GitHub releases

## Adding a new config option

When sqlformat-rs adds new options:

1. Add the field to `Configuration` in `src/configuration/configuration.rs` (add enums with `generate_str_to_from!` if needed)
2. Add resolution in `src/configuration/resolve_config.rs` using `get_value()`
3. Add a builder method in `src/configuration/builder.rs` and update the `check_all_values_set` test
4. Wire it through in `src/format_text.rs` when constructing `FormatOptions`
5. Add the property to `deployment/schema.json`
6. Add a spec test file in `tests/specs/Config/`

## Test specs

Spec files live in `tests/specs/` and use the dprint-development format:

- `== message ==` starts a test case
- `[expect]` separates input from expected output
- `~~ key: value, key: value ~~` at the top of a file sets config for all specs in that file
- Each config variation needs its own file since config is file-level

## Releases

- Manual: trigger the `release` workflow with patch/minor
- Automatic: `check_updates` workflow runs daily, detects new sqlformat versions, and auto-publishes
- On tag push: CI creates a GitHub release with `plugin.wasm`, and `publish_npm` publishes to npm
Loading