Skip to content

Commit

Permalink
feat: publish to jsr.io
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari committed Mar 14, 2024
1 parent 6b07bef commit 84250fb
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 31 deletions.
90 changes: 63 additions & 27 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ env:
RUST_LOG: "off"

jobs:
publish-npm:
if: startsWith(github.ref, 'refs/tags/v')
wasm-build:
name: Wasm build
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v4

Expand All @@ -25,60 +23,98 @@ jobs:
- name: Build wasm
run: ./crates/ruff_fmt/scripts/build.sh

- name: Package
run: npm pack
working-directory: crates/ruff_fmt/pkg

- name: Upload
uses: actions/upload-artifact@v4
with:
name: build
path: crates/ruff_fmt/pkg

publish-npm:
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
needs: wasm-build
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ".node-version"
registry-url: "https://registry.npmjs.org"

- run: |
cd crates/ruff_fmt/pkg
npm publish --provenance
- uses: actions/download-artifact@v4
with:
name: build
path: crates/ruff_fmt/pkg

- run: npm publish --provenance
working-directory: crates/ruff_fmt/pkg
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

publish-github:
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
needs: wasm-build
permissions:
packages: write
steps:
- uses: actions/checkout@v4

- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

- name: Build wasm
run: ./crates/ruff_fmt/scripts/build.sh

- uses: actions/setup-node@v4
with:
node-version-file: ".node-version"
registry-url: "https://npm.pkg.github.com"

- run: |
cd crates/ruff_fmt/pkg
npm publish
- uses: actions/download-artifact@v4
with:
name: build
path: crates/ruff_fmt/pkg

- run: npm publish
working-directory: crates/ruff_fmt/pkg
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

publish-jsr:
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
needs: wasm-build
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ".node-version"

- uses: actions/download-artifact@v4
with:
name: build
path: crates/ruff_fmt/pkg

- run: npx jsr publish
working-directory: crates/ruff_fmt/pkg

publish-github-release:
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
needs: wasm-build
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: build
path: crates/ruff_fmt/pkg

- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

- name: Build wasm
run: |
# build for JS API
./crates/ruff_fmt/scripts/build.sh
(cd crates/ruff_fmt/pkg && npm pack)
# build for dprint plugin
cargo build --release --target=wasm32-unknown-unknown -p ruff_fmt_dprint
- name: Build dprint plugin
run: cargo build --release --target=wasm32-unknown-unknown -p ruff_fmt_dprint

- name: Get tag version
id: get_tag_version
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ jobs:
- name: Build wasm
run: ./crates/ruff_fmt/scripts/build.sh

- name: npm pack
run: cd crates/ruff_fmt/pkg && npm pack
- name: Package
run: npm pack
working-directory: crates/ruff_fmt/pkg

- name: Upload
uses: actions/upload-artifact@v4
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolver = "2"

[workspace.package]
authors = ["magic-akari <[email protected]>"]
description = "A wasm based python formatter"
description = "A WASM Based Python Formatter"
edition = "2021"
homepage = "https://github.com/wasm-fmt/ruff_fmt"
keywords = ["wasm", "ruff", "python", "formatter"]
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
[![Test](https://github.com/wasm-fmt/ruff_fmt/actions/workflows/test.yml/badge.svg)](https://github.com/wasm-fmt/ruff_fmt/actions/workflows/test.yml)
[![npm](https://img.shields.io/npm/v/@wasm-fmt/ruff_fmt)](https://www.npmjs.com/package/@wasm-fmt/ruff_fmt)

# Install

[![npm](https://img.shields.io/npm/v/@wasm-fmt/ruff_fmt)](https://www.npmjs.com/package/@wasm-fmt/ruff_fmt)

```bash
npm install @wasm-fmt/ruff_fmt
```

[![jsr.io](https://jsr.io/badges/@fmt/ruff-fmt)](https://jsr.io/@fmt/ruff-fmt)

```bash
npx jsr add @fmt/ruff-fmt
```

# Usage

```javascript
Expand Down
1 change: 1 addition & 0 deletions crates/ruff_fmt/extra/.npmignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.tgz
jsr.jsonc
8 changes: 8 additions & 0 deletions crates/ruff_fmt/scripts/package.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,11 @@ pkg_json.exports = {
};

fs.writeFileSync(pkg_path, JSON.stringify(pkg_json, null, 4));

// JSR

const jsr_path = path.resolve(pkg_path, "..", "jsr.jsonc");
pkg_json.name = "@fmt/ruff-fmt";
pkg_json.exports = "./ruff_fmt.js";
pkg_json.exclude = ["!**", "*.tgz"];
fs.writeFileSync(jsr_path, JSON.stringify(pkg_json, null, 4));

0 comments on commit 84250fb

Please sign in to comment.