Skip to content

Commit

Permalink
feat: initial commit to port the code in the organization
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed Dec 15, 2023
0 parents commit ec4953c
Show file tree
Hide file tree
Showing 78 changed files with 7,901 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
on:
push:
branches:
- main
pull_request:

name: Linting
jobs:
lint:
name: Lints
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v3

- name: Use Rust cache
uses: Swatinem/rust-cache@v1
with:
cache-on-failure: true
- name: Install prettier
run: |
yarn global add prettier
- name: Check Markdown format
run: |
prettier --check "**/*.md"
- name: Check Yaml format
run: |
prettier --check "**/*.{yaml,yml}"
- name: Compile contracts
uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.3.1"
- run: |
cd ./contracts && make generate_artifacts && scarb fmt --check
- name: Check Rust format
run: |
cargo fmt --all -- --check
- name: Run Clippy lints
run: |
cargo clippy --all --all-targets --all-features -- -D warnings
119 changes: 119 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
on:
push:
tags:
- "cainome/v*.*.*"
- "cainome-*/v*.*.*"

name: "Release"
jobs:
crate-info:
name: "Extract crate info"
runs-on: "ubuntu-latest"
outputs:
crate: ${{ steps.derive.outputs.crate }}
version: ${{ steps.derive.outputs.version }}

steps:
- id: "derive"
name: "Derive crate info from Git tag"
run: |
FULL_REF="${{ github.ref }}"
REGEX="^refs\/tags\/([a-z\\-]*)\/v(.*)$"
[[ $FULL_REF =~ $REGEX ]];
echo "crate=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
echo "version=${BASH_REMATCH[2]}" >> $GITHUB_OUTPUT
# Just in case we accidentally release something not on main.
commit-branch-check:
name: "Check commit branch"
runs-on: "ubuntu-latest"
needs: ["crate-info"]

steps:
- name: "Checkout source code"
uses: "actions/checkout@v3"
with:
fetch-depth: 0

- name: "Check if commit is on main"
run: |
COMMIT_HASH=$(git log -1 --format=%H ${{ github.ref }})
GREP_OUTPUT=$(git log origin/main --format=%H | grep "$COMMIT_HASH")
if [ -z "$GREP_OUTPUT" ]; then
echo "Cannot release commits not on the main branch"
exit 1
fi
crate-version-check:
name: "Check crate version"
runs-on: "ubuntu-latest"
needs: ["crate-info"]

steps:
- name: "Checkout source code"
uses: "actions/checkout@v3"

- name: "Check against Cargo.toml"
run: |
if [ "cainome" != "${{ needs.crate-info.outputs.crate }}" ]; then
CRATE_NAME="${{ needs.crate-info.outputs.crate }}"
cd ./crates/"${CRATE_NAME#*-}"
fi
GREP_OUTPUT=$(cat Cargo.toml | grep "^version = \"${{ needs.crate-info.outputs.version }}\"$")
if [ -z "$GREP_OUTPUT" ]; then
echo "Crate version mismatch"
exit 1
fi
build:
name: "Build for ${{ matrix.os }}"
runs-on: "${{ matrix.os }}"
needs: ["crate-info"]

strategy:
matrix:
os:
- "ubuntu-latest"
- "windows-latest"
- "macos-latest"

steps:
- name: "Checkout source code"
uses: "actions/checkout@v3"

- name: "Setup stable toolchain"
uses: "actions-rs/toolchain@v1"
with:
toolchain: "stable"
profile: "minimal"
override: true

- name: "Build crate"
run: |
cargo build --package ${{ needs.crate-info.outputs.crate }} --all-targets
# crates-io-release:
# name: "Release to crates.io"
# runs-on: "ubuntu-latest"

# needs:
# - "crate-info"
# - "commit-branch-check"
# - "crate-version-check"
# - "build"

# steps:
# - name: "Checkout source code"
# uses: "actions/checkout@v3"

# - name: "Login to crates.io"
# run: |
# cargo login ${{ secrets.CRATES_IO_API_TOKEN }}

# - name: "Public crate"
# run: |
# cargo publish --package ${{ needs.crate-info.outputs.crate }}
41 changes: 41 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
on:
push:
branches:
- main
pull_request:

name: Tests
jobs:
unix-test:
name: Unix tests
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-11]
toolchain: [stable, nightly]

steps:
- name: Checkout source code
uses: actions/checkout@v3

- name: Compile contracts
uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.3.1"
- run: |
cd ./contracts && make generate_artifacts
- name: Setup toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.toolchain }}
profile: minimal
override: true

- name: Run cargo tests
uses: nick-fields/retry@v2
with:
timeout_minutes: 20
max_attempts: 3
retry_wait_seconds: 30
command: cargo test --workspace --all-features
35 changes: 35 additions & 0 deletions .github/workflows/udeps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
on:
push:
branches:
- main
pull_request:

name: Unused deps
jobs:
udeps:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v3

- name: Setup nightly toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
override: true

- uses: Swatinem/rust-cache@v1
with:
cache-on-failure: true

- name: Install udeps
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-udeps

- name: Run udeps
uses: actions-rs/cargo@v1
with:
command: udeps
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
Loading

0 comments on commit ec4953c

Please sign in to comment.