Skip to content

Commit

Permalink
Merge pull request #1125 from oasisprotocol/matevz/feature/code-snippets
Browse files Browse the repository at this point in the history
examples: Migrate code snippets from .md files to separate sources
  • Loading branch information
matevz committed Oct 3, 2022
2 parents e18a28e + 867b31c commit 7b57df2
Show file tree
Hide file tree
Showing 22 changed files with 868 additions and 616 deletions.
8 changes: 4 additions & 4 deletions .github/actions/lint-rust/action.yml
@@ -1,12 +1,12 @@
name: Lint Rust Worskapce
description: Run lints and format checks on Rust workspace code
inputs:
manfiest_path:
manifest_path:
description: Path to the Cargo.toml manifest of the Rust sources to lint
default: ${{ github.workspace }}/Cargo.toml
required: false
token:
description: GitHub secret token used by cliipy-check action
description: GitHub secret token used by clippy-check action
required: true
runs:
using: composite
Expand All @@ -18,7 +18,7 @@ runs:
args: |
--all-features
--locked
--manifest-path ${{ inputs.manfiest_path }}
--manifest-path ${{ inputs.manifest_path }}
--
-D warnings
-D clippy::dbg_macro
Expand All @@ -28,4 +28,4 @@ runs:
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all --manifest-path ${{ inputs.manfiest_path }} -- --check
args: --all --manifest-path ${{ inputs.manifest_path }} -- --check
4 changes: 2 additions & 2 deletions .github/actions/test-rust/action.yml
@@ -1,7 +1,7 @@
name: Unit Test Rust Worskapce with Coverage
description: Run unit tests on a Rust workspace with coverage and uploads results to codecov
inputs:
manfiest_path:
manifest_path:
description: Path to the Cargo.toml manifest of the Rust sources to build and test
default: ${{ github.workspace }}/Cargo.toml
required: false
Expand All @@ -12,7 +12,7 @@ runs:
uses: actions-rs/tarpaulin@v0.1
with:
version: '0.20.1'
args: '--avoid-cfg-tarpaulin --manifest-path ${{ inputs.manfiest_path }} -- --test-threads 1'
args: '--avoid-cfg-tarpaulin --manifest-path ${{ inputs.manifest_path }} -- --test-threads 1'
env:
# Required as tarpaulin doesn't honor .cargo/config.
RUSTFLAGS: -C target-feature=+aes,+ssse3
Expand Down
119 changes: 119 additions & 0 deletions .github/workflows/ci-examples.yml
@@ -0,0 +1,119 @@
# NOTE: This name appears in GitHub's Checks API and in workflow's status badge.
name: ci-examples

# Trigger the workflow when:
on:
# A push occurs to one of the matched branches.
push:
branches:
- main
- stable/*
# Or when a pull request event occurs for a pull request against one of the
# matched branches.
pull_request:
branches:
- main
- stable/*

# Cancel in-progress jobs on same branch.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint-test-runtime-sdk:
name: lint-test-runtime-sdk
runs-on: ubuntu-latest
strategy:
matrix:
example: [runtime-sdk/minimal-runtime]
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
components: rustfmt, clippy

# Generate Cargo.lock needed for linting.
- name: Generate Cargo.lock
working-directory: examples/${{ matrix.example }}
run: cargo generate-lockfile

- name: Lint ${{ matrix.example }}
uses: ./.github/actions/lint-rust
with:
token: ${{ secrets.GITHUB_TOKEN }}
manifest_path: examples/${{ matrix.example }}/Cargo.toml

- name: Build and test ${{ matrix.example }}
working-directory: examples/${{ matrix.example }}
run: cargo test

lint-test-contract-sdk:
name: lint-test-contract-sdk
runs-on: ubuntu-latest
strategy:
matrix:
example: [contract-sdk/hello-world, contract-sdk/c10l-hello-world]
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
target: wasm32-unknown-unknown
components: rustfmt, clippy

# Generate Cargo.lock needed for linting.
- name: Generate Cargo.lock
working-directory: examples/${{ matrix.example }}
run: cargo generate-lockfile

- name: Lint ${{ matrix.example }}
uses: ./.github/actions/lint-rust
with:
token: ${{ secrets.GITHUB_TOKEN }}
manifest_path: examples/${{ matrix.example }}/Cargo.toml

- name: Build ${{ matrix.example }} for wasm32
working-directory: examples/${{ matrix.example }}
run: cargo build --target wasm32-unknown-unknown --release

- name: Test ${{ matrix.example }}
working-directory: examples/${{ matrix.example }}
run: cargo test

lint-test-client-sdk-go:
name: lint-test-client-sdk-go
runs-on: ubuntu-latest
strategy:
matrix:
example: [client-sdk/go/minimal-runtime-client]
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '1.17.x'

# Generate go.sum needed for linting.
- name: Generate go.sum
working-directory: examples/${{ matrix.example }}
run: go get

# NOTE: "file exists" tar errors can be safely ignored, because go is already installed.
- name: Lint ${{ matrix.example }}
uses: golangci/golangci-lint-action@v3.2.0
with:
# NOTE: The version must be specified without the patch version.
version: v1.40
working-directory: examples/${{ matrix.example }}

- name: Build ${{ matrix.example }}
working-directory: examples/${{ matrix.example }}
run: go build
6 changes: 2 additions & 4 deletions .github/workflows/ci-lint.yml
Expand Up @@ -21,9 +21,7 @@ concurrency:
cancel-in-progress: true

jobs:

lint-rust:
# NOTE: This name appears in GitHub's Checks API.
name: lint-rust
runs-on: ubuntu-latest
steps:
Expand All @@ -44,13 +42,13 @@ jobs:
uses: ./.github/actions/lint-rust
with:
token: ${{ secrets.GITHUB_TOKEN }}
manfiest_path: tests/contracts/hello/Cargo.toml
manifest_path: tests/contracts/hello/Cargo.toml

- name: Lint OAS-20 contract code
uses: ./.github/actions/lint-rust
with:
token: ${{ secrets.GITHUB_TOKEN }}
manfiest_path: contract-sdk/specs/token/oas20/Cargo.toml
manifest_path: contract-sdk/specs/token/oas20/Cargo.toml

lint-go-client-sdk:
name: lint-go-client-sdk
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/ci-test.yaml
Expand Up @@ -21,7 +21,6 @@ concurrency:
cancel-in-progress: true

jobs:

test-rust:
# NOTE: This name appears in GitHub's Checks API.
name: test-rust
Expand All @@ -46,12 +45,12 @@ jobs:
- name: Test Hello contract code
uses: ./.github/actions/test-rust
with:
manfiest_path: tests/contracts/hello/Cargo.toml
manifest_path: tests/contracts/hello/Cargo.toml

- name: Test OAS-20 contract
uses: ./.github/actions/test-rust
with:
manfiest_path: contract-sdk/specs/token/oas20/Cargo.toml
manifest_path: contract-sdk/specs/token/oas20/Cargo.toml

test-rust-sgx:
# NOTE: This name appears in GitHub's Checks API.
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Expand Up @@ -25,5 +25,9 @@ members = [
exclude = [
# Test contracts.
"tests/contracts",
# Example contracts and runtimes.
"examples/contract-sdk/hello-world",
"examples/contract-sdk/c10l-hello-world",
"examples/runtime-sdk/minimal-runtime",
]
resolver = "2"

0 comments on commit 7b57df2

Please sign in to comment.