Skip to content

Commit

Permalink
Add support for multi-part questions (#33)
Browse files Browse the repository at this point in the history
* Document schema, generate JSON schema in CI

* Run CI on branch push

* Install Aquascope in CI

* Add frontend support for multi-part questions

* Only include json schema stuff if needed

* Revert to old example
  • Loading branch information
willcrichton authored Sep 21, 2023
1 parent cd65a26 commit c6f7823
Show file tree
Hide file tree
Showing 30 changed files with 1,035 additions and 148 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Tests
on:
push:
branches:
- "main"
- "**"
tags-ignore:
- "v*"
pull_request:
Expand All @@ -17,3 +17,16 @@ jobs:
- uses: actions/checkout@v2
- name: Setup
uses: ./.github/workflows/setup
- name: Install Aquascope
# tag should match mdbook-aquascope version
run: |
git clone -b v0.3.0 https://github.com/cognitive-engineering-lab/aquascope
cd aquascope
cargo make install-mdbook
- name: Test Rust package
run: cargo test --all-features --locked
- name: Lint Rust package
run: cargo clippy --all-features --locked -- -D warnings
- name: Test JS package
run: depot test
working-directory: js
32 changes: 17 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,10 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- name: Setup
uses: ./.github/workflows/setup
with:
toolchain: stable
target: ${{ matrix.target }}
profile: minimal
override: true
- name: Install cargo-make
uses: baptiste0928/cargo-install@v2
with:
crate: cargo-make
- name: Install Depot
run: |
curl https://raw.githubusercontent.com/cognitive-engineering-lab/depot/main/scripts/install.sh | sh
echo "PATH=$HOME/.local/bin:$PATH" >> $GITHUB_ENV
- name: Initialize TS bindings
run: cargo make init-bindings
- name: Build Rust package
run: cargo build -p mdbook-quiz --release --locked ${{ matrix.kind == 'full' && '--features rust-editor --features aquascope' || '' }}
- name: Package artifact
Expand All @@ -60,9 +48,22 @@ jobs:
with:
name: ${{ matrix.target }}_${{ matrix.kind }}
path: target/release/mdbook-quiz_${{ matrix.target }}_${{ matrix.kind }}.tar.gz

build-schema:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup
uses: ./.github/workflows/setup
- name: Build schema
run: cargo run --bin gen-json-schema --features json-schema > mdbook-quiz.schema.json
- uses: actions/upload-artifact@v2
with:
name: schema
path: mdbook-quiz.schema.json

publish-artifacts:
needs: build-artifacts
needs: [build-artifacts, build-schema]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v2
Expand All @@ -74,6 +75,7 @@ jobs:
x86_64-apple-darwin_bare/mdbook-quiz_x86_64-apple-darwin_bare.tar.gz
aarch64-unknown-linux-gnu_bare/mdbook-quiz_aarch64-unknown-linux-gnu_bare.tar.gz
aarch64-apple-darwin_bare/mdbook-quiz_aarch64-apple-darwin_bare.tar.gz
schema/mdbook-quiz.schema.json
publish-crate:
needs: publish-artifacts
Expand Down
18 changes: 7 additions & 11 deletions .github/workflows/setup/action.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
name: Setup

inputs:
target:
default: x86_64-unknown-linux-gnu

runs:
using: composite
steps:
Expand All @@ -7,6 +12,8 @@ runs:
profile: minimal
toolchain: stable
components: clippy
target: ${{ inputs.target }}
override: true
- uses: Swatinem/rust-cache@v1
- name: Install cargo-make
uses: baptiste0928/cargo-install@v2
Expand All @@ -15,17 +22,6 @@ runs:
- name: Install Depot
run: curl https://raw.githubusercontent.com/cognitive-engineering-lab/depot/main/scripts/install.sh | sh
shell: bash
# Note: we have to build before test so the build script is executed
- name: Initialize TS bindings
run: cargo make init-bindings
shell: bash
- name: Test Rust package
run: cargo test --locked
shell: bash
- name: Lint Rust package
run: cargo clippy --locked -- -D warnings
shell: bash
- name: Test JS package
run: depot test
working-directory: js
shell: bash
54 changes: 52 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 9 additions & 12 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ skip_core_tasks = true
default_to_workspace = false


# Precommit
[tasks.precommit-cargo]
script = "cargo fmt && cargo clippy"

Expand All @@ -13,20 +12,10 @@ script = "cd js && depot fmt"
[tasks.precommit.run_task]
name = ["precommit-js", "precommit-cargo"]

[tasks.init-bindings]
script = """
cargo test -p mdbook-quiz-schema --locked export_bindings
mkdir -p js/packages/quiz/src/bindings
cp crates/mdbook-quiz-schema/bindings/* js/packages/quiz/src/bindings
"""

# Watch
[tasks.watch]
script = "cargo watch -x 'install --path crates/mdbook-quiz --debug --offline --features rust-editor --features source-map' -w src -w js/packages/quiz-embed/dist --ignore-nothing"
script = "cargo watch -x 'install --path crates/mdbook-quiz --debug --offline --features rust-editor --features source-map' -w crates -w js/packages/quiz-embed/dist --ignore-nothing"

[tasks.watch.run_task]
name = ["watch-cargo"]
parallel = true

[tasks.clean]
script = """
Expand All @@ -35,6 +24,14 @@ cd js && depot clean && cd ..
rm -rf js/packages/quiz/src/bindings crates/mdbook-quiz-schema/bindings
"""


[tasks.init-bindings]
script = """
cargo test -p mdbook-quiz-schema --locked export_bindings
mkdir -p js/packages/quiz/src/bindings
cp crates/mdbook-quiz-schema/bindings/* js/packages/quiz/src/bindings
"""

[tasks.install]
dependencies = ["init-bindings"]
script = """
Expand Down
7 changes: 6 additions & 1 deletion crates/mdbook-quiz-schema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ license = "MIT OR Apache-2.0"
edition = "2021"
repository = "https://github.com/cognitive-engineering-lab/mdbook-quiz"

[features]
json-schema = ["dep:schemars", "dep:serde_json"]

[dependencies]
serde = {version = "1.0.188", features = ["derive"]}
ts-rs = "7.0.0"
schemars = {version = "0.8.15", optional = true}
serde_json = {version = "1.0.107", optional = true}

[dev-dependencies]
toml = { workspace = true }
toml = { workspace = true }
15 changes: 15 additions & 0 deletions crates/mdbook-quiz-schema/src/bin/gen-json-schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
fn main() {
#[cfg(feature = "json-schema")]
{
use mdbook_quiz_schema::Quiz;
use schemars::schema_for;

let schema = schema_for!(Quiz);
println!("{}", serde_json::to_string_pretty(&schema).unwrap());
}

#[cfg(not(feature = "json-schema"))]
{
panic!("Must run with --feature json-schema")
}
}
Loading

0 comments on commit c6f7823

Please sign in to comment.