diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 838bff94..88a675f1 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -134,7 +134,7 @@ jobs: with: name: ${{ env.PROJECT_NAME }} template: templates/credential-registry - other: "-d description=myProject -d restorable=${{ matrix.restorable }} -d revocable_by_others=${{ matrix.revocable_by_others }}" + other: "-d description=myProject -d template_type=custom -d restorable=${{ matrix.restorable }} -d revocable_by_others=${{ matrix.revocable_by_others }}" - name: Install toolchain uses: actions-rs/toolchain@v1 @@ -181,7 +181,57 @@ jobs: with: name: ${{ env.PROJECT_NAME }} template: ${{ matrix.crates }} - other: "-d description=myProject -d tokenMetadataBaseURL=https://some.example/token/ -d restorable=true -d revocable_by_others=true" + other: "-d description=myProject -d tokenMetadataBaseURL=https://some.example/token/ -d template_type=default" + + - name: Install toolchain with clippy available + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ env.RUST_VERSION }} + target: ${{ matrix.target }} + override: true + components: clippy + + # we need to move the generated project to a temp folder, away from the template project + # otherwise `cargo` runs would fail + # see https://github.com/rust-lang/cargo/issues/9922 + - name: Run clippy with build-schema + run: | + mv $PROJECT_NAME ${{ runner.temp }}/ + cd ${{ runner.temp }}/$PROJECT_NAME + rustup target add wasm32-unknown-unknown + cargo clippy --manifest-path ./Cargo.toml --target=${{ matrix.target }} --features concordium-std/build-schema -- -D warnings + + # The credential registry template used to generate code for all combinations of parameters + # with the `cargo-generate` command and it is checked that the schemas can be built as part + # of the 'clippy' command. + clippy-credential-registry-template: + name: Clippy on smart contract templates + runs-on: ubuntu-latest + needs: rustfmt + strategy: + matrix: + target: + - wasm32-unknown-unknown + + restorable: ["true", "false"] + revocable_by_others: ["true", "false"] + + env: + PROJECT_NAME: my-project + + steps: + - name: Checkout sources + uses: actions/checkout@v2 + with: + submodules: true + + - name: Run cargo-generate + uses: cargo-generate/cargo-generate-action@v0.16.0 + with: + name: ${{ env.PROJECT_NAME }} + template: templates/credential-registry + other: "-d description=myProject -d template_type=custom -d restorable=${{ matrix.restorable }} -d revocable_by_others=${{ matrix.revocable_by_others }}" - name: Install toolchain with clippy available uses: actions-rs/toolchain@v1 @@ -269,7 +319,7 @@ jobs: with: name: ${{ env.PROJECT_NAME }} template: ${{ matrix.crates }} - other: "-d description=Example-credential-registry -d restorable=true -d revocable_by_others=true" + other: "-d description=Example-credential-registry -d template-type=default" - name: Install toolchain uses: actions-rs/toolchain@v1 diff --git a/examples/credential-registry/src/lib.rs b/examples/credential-registry/src/lib.rs index 1b75aa39..4c3646ef 100644 --- a/examples/credential-registry/src/lib.rs +++ b/examples/credential-registry/src/lib.rs @@ -16,9 +16,9 @@ //! //! ## Issuer's functionality //! +//! - register/remove revocation authority keys; //! - register a new credential; //! - revoke a credential; -//! - register/remove revocation authority keys; //! - update the issuer's metadata; //! - update the credential metadata; //! - update credential schema reference; diff --git a/templates/credential-registry/cargo-generate.toml b/templates/credential-registry/cargo-generate.toml index d9426e18..6a3fba53 100644 --- a/templates/credential-registry/cargo-generate.toml +++ b/templates/credential-registry/cargo-generate.toml @@ -1,7 +1,17 @@ [template] cargo_generate_version = ">= 0.16.0, < 0.19.0" +[hooks] +pre = ["pre-script.rhai"] # a script for setting default values for the variables when `template_type = default` + [placeholders] -description = { type="string", prompt="Description for the project?" } -revocable_by_others = { type="bool", prompt="Can credentials be revoked by someone other than the issuer or the holder?", default=true } -restorable = { type="bool", prompt="Can revocation be reverted?", default=false } +description = { type = "string", prompt = "Description for the project?" } +template_type = { type = "string", prompt = "Select template type ('default' recommended for first-time users)", choices = ["default", "custom"], default = "default"} + +[values] +revocable_by_others = true +restorable = true + +[conditional.'template_type == "custom"'.placeholders] +revocable_by_others = { type = "bool", prompt = "Can credentials be revoked by someone other than the issuer or the holder?", default = true } +restorable = { type = "bool", prompt = "Can revocation be reverted?", default = false } diff --git a/templates/credential-registry/pre-script.rhai b/templates/credential-registry/pre-script.rhai new file mode 100644 index 00000000..8fcd25b7 --- /dev/null +++ b/templates/credential-registry/pre-script.rhai @@ -0,0 +1,5 @@ +let template_type = variable::get("template_type"); +if template_type == "default" { + variable::set("revocable_by_others", true); + variable::set("restorable", true); +} \ No newline at end of file diff --git a/templates/credential-registry/src/lib.rs b/templates/credential-registry/src/lib.rs index 1064f093..c475827a 100644 --- a/templates/credential-registry/src/lib.rs +++ b/templates/credential-registry/src/lib.rs @@ -16,9 +16,9 @@ //! //! ## Issuer's functionality //! +{% if revocable_by_others %}//! - register/remove revocation authority keys;{% else %}//!{% endif %} //! - register a new credential; //! - revoke a credential; -//! - register/remove revocation authority keys; //! - update the issuer's metadata; //! - update the credential metadata; {% if restorable %}//! - update credential schema reference;