Skip to content

Commit

Permalink
Change credential registry template flow: default and custom; run cli…
Browse files Browse the repository at this point in the history
…ppy on all combinations of parameters
  • Loading branch information
annenkov committed Aug 31, 2023
1 parent 588a2a9 commit d800085
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 8 deletions.
56 changes: 53 additions & 3 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/[email protected]
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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/credential-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 13 additions & 3 deletions templates/credential-registry/cargo-generate.toml
Original file line number Diff line number Diff line change
@@ -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 }
5 changes: 5 additions & 0 deletions templates/credential-registry/pre-script.rhai
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 1 addition & 1 deletion templates/credential-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d800085

Please sign in to comment.