From 761c104eae87f63cda0fed60d1b5d60a8f534713 Mon Sep 17 00:00:00 2001 From: Alexander Gonzalez Date: Thu, 14 Mar 2024 16:23:16 +0100 Subject: [PATCH] feat(ci): add workflows & repo templates --- .github/ISSUE_TEMPLATE/bug_report.yml | 41 +++++++ .github/ISSUE_TEMPLATE/config.yml | 4 + .github/ISSUE_TEMPLATE/feature_request.yml | 24 ++++ .github/codecov.yml | 22 ++++ .github/dependabot.yml | 15 +++ .github/pull_request_template.md | 18 +++ .github/workflows/check.yml | 100 +++++++++++++++++ .github/workflows/nostd.yml | 32 ++++++ .github/workflows/test.yml | 122 +++++++++++++++++++++ Cargo.toml | 23 ++-- 10 files changed, 391 insertions(+), 10 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/feature_request.yml create mode 100644 .github/codecov.yml create mode 100644 .github/dependabot.yml create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/check.yml create mode 100644 .github/workflows/nostd.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 000000000..6dc3559fc --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,41 @@ +name: 🐞 Bug report +description: Create a report to help us improve +title: "🐞 [Bug]: " +labels: ["bug"] +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to fill out this bug report! Briefly describe the issue you're experiencing. Tell us what you were trying to do and what happened instead. Remember, this is not a place to ask for help debugging code. For that, we welcome you in the OpenZeppelin Community Forum: https://forum.openzeppelin.com/. + - type: textarea + id: what-happened + attributes: + label: What happened? + description: if you want, you can include screenshots as well :) + validations: + required: true + - type: checkboxes + id: platform + attributes: + label: platform + description: On which operating system did this bug emerge? + options: + - label: linux + required: false + - label: windows + required: false + - label: macos + required: false + - type: textarea + id: expected + attributes: + label: Expected behavior + description: What should have happened instead? + - type: checkboxes + id: terms + attributes: + label: Contribution Guidelines + description: By submitting this issue, you agree to follow our [Contribution Guidelines](https://github.com/OpenZeppelin/rust-contracts-stylus/blob/main/CONTRIBUTING.md) + options: + - label: I agree to follow this project's Contribution Guidelines + required: true diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 000000000..c599e37c8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,4 @@ +contact_links: + - name: Questions & Support Requests + url: https://forum.openzeppelin.com/c/support/17 + about: Ask in the OpenZeppelin Forum diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 000000000..031dda4f8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,24 @@ +name: 🎁 Feature Request +description: Suggest an idea for this project ⚡️ +title: "🎁 [Feature Request]: " +labels: ["enhancement"] +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to fill this feature request! + - type: textarea + id: feature + attributes: + label: What is the feature you would like to see? + description: Is your feature request related to a specific problem? Is it just a crazy idea? Tell us about it! + validations: + required: true + - type: checkboxes + id: terms + attributes: + label: Contribution Guidelines + description: By submitting this issue, you agree to follow our [Contribution Guidelines](https://github.com/OpenZeppelin/rust-contracts-stylus/blob/main/CONTRIBUTING.md) + options: + - label: I agree to follow this project's Contribution Guidelines + required: true diff --git a/.github/codecov.yml b/.github/codecov.yml new file mode 100644 index 000000000..c4f7a20bd --- /dev/null +++ b/.github/codecov.yml @@ -0,0 +1,22 @@ +# ref: https://docs.codecov.com/docs/codecovyml-reference +coverage: + # Hold ourselves to a high bar. + range: 95..100 + round: down + precision: 1 + status: + # ref: https://docs.codecov.com/docs/commit-status + project: + default: + # Avoid false negatives. + threshold: 1% +# Test files aren't important for coverage. +ignore: + - "tests" + - "docs" +# Make comments less noisy. +comment: + layout: "files" + require_changes: true +github_checks: + annotations: false diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..4649a6e9b --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,15 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: daily + - package-ecosystem: cargo + directory: / + schedule: + interval: daily + ignore: + - dependency-name: "*" + update-types: + - "version-update:semver-patch" + - "version-update:semver-minor" diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 000000000..422b7fd08 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,18 @@ + + + + + +Fixes #??? + + + + +#### PR Checklist + + + + + +- [ ] Tests +- [ ] Documentation diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 000000000..fb45991e4 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,100 @@ +name: check +# This workflow runs whenever a PR is opened or updated, or a commit is pushed +# to main. It runs several checks: +# - fmt: checks that the code is formatted according to `rustfmt`. +# - clippy: checks that the code does not contain any `clippy` warnings. +# - doc: checks that the code can be documented without errors. +# - hack: check combinations of feature flags. +permissions: + contents: read +# This configuration allows maintainers of this repo to create a branch and +# pull request based on the new branch. Restricting the push trigger to the +# main branch ensures that the PR only gets built once. +on: + push: + branches: [main] + pull_request: +# If new code is pushed to a PR branch, then cancel in progress workflows for +# that PR. Ensures that we don't waste CI time, and returns results quicker +# https://github.com/jonhoo/rust-ci-conf/pull/5 +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true +env: + CARGO_TERM_COLOR: always +jobs: + fmt: + runs-on: ubuntu-latest + name: nightly / fmt + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - name: Install stable + # We run in nightly to make use of some features only available there. + # Check out `rustfmt.toml` to see which ones. + uses: dtolnay/rust-toolchain@nightly + with: + components: rustfmt + - name: cargo fmt --all --check + run: cargo fmt --all --check + clippy: + runs-on: ubuntu-latest + name: ${{ matrix.toolchain }} / clippy + permissions: + contents: read + checks: write + strategy: + fail-fast: false + matrix: + # Get early warning of new lints which are regularly introduced in beta + # channels. + toolchain: [stable, beta] + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - name: Install ${{ matrix.toolchain }} + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.toolchain }} + components: clippy + - name: cargo clippy + uses: giraffate/clippy-action@v1 + with: + reporter: 'github-pr-check' + github_token: ${{ secrets.GITHUB_TOKEN }} + doc: + # Run docs generation on nightly rather than stable. This enables features + # like https://doc.rust-lang.org/beta/unstable-book/language-features/doc-cfg.html + # which allows an API be documented as only available in some specific + # platforms. + runs-on: ubuntu-latest + name: nightly / doc + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - name: Install nightly + uses: dtolnay/rust-toolchain@nightly + - name: cargo doc + run: cargo doc --no-deps --all-features + env: + RUSTDOCFLAGS: --cfg docsrs + hack: + # `cargo-hack` checks combinations of feature flags to ensure that features + # are all additive which is required for feature unification. + runs-on: ubuntu-latest + name: ubuntu / stable / features + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - name: Install stable + uses: dtolnay/rust-toolchain@stable + - name: cargo install cargo-hack + uses: taiki-e/install-action@cargo-hack + # Intentionally no target specifier; see https://github.com/jonhoo/rust-ci-conf/pull/4 + # --feature-powerset runs for every combination of features + - name: cargo hack + run: cargo hack --feature-powerset check diff --git a/.github/workflows/nostd.yml b/.github/workflows/nostd.yml new file mode 100644 index 000000000..57096ecdf --- /dev/null +++ b/.github/workflows/nostd.yml @@ -0,0 +1,32 @@ +name: no-std +# This workflow checks whether the library is able to run without the std +# library. See `check.yml` for information about how the concurrency +# cancellation and workflow triggering works. +permissions: + contents: read +on: + push: + branches: [main] + pull_request: +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true +env: + CARGO_TERM_COLOR: always +jobs: + nostd: + runs-on: ubuntu-latest + name: ${{ matrix.target }} + strategy: + matrix: + target: [wasm32-unknown-unknown, thumbv7m-none-eabi, aarch64-unknown-none] + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - name: Install stable + uses: dtolnay/rust-toolchain@stable + - name: rustup target add ${{ matrix.target }} + run: rustup target add ${{ matrix.target }} + - name: cargo check + run: cargo check --target ${{ matrix.target }} --no-default-features diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..e122115d1 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,122 @@ +name: test +# This is the main CI workflow that runs the test suite on all pushes to main +# and all pull requests. It runs the following jobs: +# - required: runs the test suite on ubuntu with stable and beta rust +# toolchains. +# - minimal: runs the test suite with the minimal versions of the dependencies +# that satisfy the requirements of this crate, and its dependencies. +# - os-check: runs the test suite on mac and windows. +# - coverage: runs the test suite and collects coverage information. +# See `check.yml` for information about how the concurrency cancellation and +# workflow triggering works. +permissions: + contents: read +on: + push: + branches: [main] + paths-ignore: + - "**.md" + - "**.adoc" + pull_request: + paths-ignore: + - "**.md" + - "**.adoc" +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true +env: + CARGO_TERM_COLOR: always +jobs: + required: + runs-on: ubuntu-latest + name: ubuntu / ${{ matrix.toolchain }} + strategy: + matrix: + # Run on stable and beta to ensure that tests won't break on the next + # version of the rust toolchain. + toolchain: [stable, beta] + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - name: Install ${{ matrix.toolchain }} + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.toolchain }} + - name: cargo generate-lockfile + # Enable this ci template to run regardless of whether the lockfile is + # checked in or not. + if: hashFiles('Cargo.lock') == '' + run: cargo generate-lockfile + # https://twitter.com/jonhoo/status/1571290371124260865 + - name: cargo test --locked + run: cargo test --locked --all-features --all-targets + # https://github.com/rust-lang/cargo/issues/6669 + - name: cargo test --doc + run: cargo test --locked --all-features --doc + os-check: + # Run cargo test on MacOS and Windows. + runs-on: ${{ matrix.os }} + name: ${{ matrix.os }} / stable + strategy: + fail-fast: false + matrix: + os: [macos-latest, windows-latest] + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - name: Install stable + uses: dtolnay/rust-toolchain@stable + - name: cargo generate-lockfile + if: hashFiles('Cargo.lock') == '' + run: cargo generate-lockfile + - name: cargo test + run: cargo test --locked --all-features --all-targets + coverage: + # Use llvm-cov to build and collect coverage and outputs in a format that + # is compatible with codecov.io. + # + # Note that codecov as of v4 requires that CODECOV_TOKEN from + # + # https://app.codecov.io/gh///settings + # + # is set in two places on your repo: + # + # - https://github.com/jonhoo/guardian/settings/secrets/actions + # - https://github.com/jonhoo/guardian/settings/secrets/dependabot + # + # (the former is needed for codecov uploads to work with Dependabot PRs) + # + # PRs coming from forks of your repo will not have access to the token, but + # for those, codecov allows uploading coverage reports without a token. + # it's all a little weird and inconvenient. see + # + # https://github.com/codecov/feedback/issues/112 + # + # for lots of more discussion. + runs-on: ubuntu-latest + name: ubuntu / stable / coverage + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - name: Install stable + uses: dtolnay/rust-toolchain@stable + with: + components: llvm-tools-preview + - name: cargo install cargo-llvm-cov + uses: taiki-e/install-action@cargo-llvm-cov + - name: cargo generate-lockfile + if: hashFiles('Cargo.lock') == '' + run: cargo generate-lockfile + - name: cargo llvm-cov + run: cargo llvm-cov --locked --all-features --lcov --output-path lcov.info + - name: Record Rust version + run: echo "RUST=$(rustc --version)" >> "$GITHUB_ENV" + - name: Upload to codecov.io + uses: codecov/codecov-action@v4 + with: + fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} + env_vars: OS,RUST diff --git a/Cargo.toml b/Cargo.toml index e7ceec672..4103e324a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,23 +1,26 @@ [workspace] members = ["contracts/token/erc20", "lib/crypto"] -# Explicitly set the resolver to version 2, which is the default for packages with edition >= 2021 +# Explicitly set the resolver to version 2, which is the default for packages +# with edition >= 2021. # https://doc.rust-lang.org/edition-guide/rust-2021/default-cargo-resolver.html resolver = "2" [workspace.package] +authors = ["OpenZeppelin"] edition = "2021" license = "MIT" keywords = ["arbitrum", "ethereum", "stylus"] +repository = "https://github.com/OpenZeppelin/rust-contracts-stylus" [profile.release] -codegen-units = 1 -panic = "abort" -opt-level = "z" -strip = true -lto = true -debug = false -rpath = false -debug-assertions = false -incremental = false +codegen-units = 1 +panic = "abort" +opt-level = "z" +strip = true +lto = true +debug = false +rpath = false +debug-assertions = false +incremental = false