diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..573ce99f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,206 @@ +name: Rust CI/CD + +on: + push: + branches: + - master + pull_request: + +env: + IMAGE: paritytech/ci-unified:bullseye-1.73.0 +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true +jobs: + set-image: + # GitHub Actions does not allow using 'env' in a container context. + # This workaround sets the container image for each job using 'set-image' job output. + runs-on: ubuntu-latest + outputs: + IMAGE: ${{ steps.set_image.outputs.IMAGE }} + steps: + - id: set_image + run: echo "IMAGE=${{ env.IMAGE }}" >> $GITHUB_OUTPUT + +# Checks + clippy: + runs-on: ubuntu-latest + needs: [set-image] + container: ${{ needs.set-image.outputs.IMAGE }} + steps: + - name: Checkout code/. + uses: actions/checkout@v4 + + - name: Show Rust version + run: | + cargo -vV + rustc -vV + rustup show + + - name: Cache Rust dependencies + uses: swatinem/rust-cache@v2 + with: + key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} + + - name: Run Clippy + run: | + cargo +stable clippy --locked -- -Dwarnings + cargo +stable clippy --locked -p parity-scale-codec-derive -- -Dwarnings + cargo +stable clippy --locked --test clippy -- -Dwarnings + + checks: + runs-on: ubuntu-latest + needs: [set-image] + container: ${{ needs.set-image.outputs.IMAGE }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Show Rust version + run: | + cargo -vV + rustc -vV + rustup show + + - name: Cache Rust dependencies + uses: swatinem/rust-cache@v2 + with: + key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} + + - name: Check Rust Stable (no_derive_no_std) + run: time cargo +stable check --verbose --no-default-features --features bit-vec,bytes,generic-array + + - name: Check Rust Stable (no_std-chain-error) + run: | + export RUSTFLAGS='-Cdebug-assertions=y -Dwarnings' + time cargo +stable check --verbose --no-default-features --features chain-error + + - name: check-rust-stable-no_derive + run: | + export RUSTFLAGS='-Cdebug-assertions=y -Dwarnings' + time cargo +stable check --verbose --features bit-vec,bytes,generic-array + + - name: check-rust-stable-only_mel + run: | + export RUSTFLAGS='-Cdebug-assertions=y -Dwarnings' + time cargo +stable check --verbose --features max-encoded-len + +# Tests + tests: + runs-on: ubuntu-latest + needs: [set-image] + container: ${{ needs.set-image.outputs.IMAGE }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Show Rust version + run: | + cargo -vV + rustc -vV + rustup show + + - name: Cache Rust dependencies + uses: swatinem/rust-cache@v2 + with: + key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} + + - name: Test Rust Stable + run: | + export RUSTFLAGS='-Cdebug-assertions=y -Dwarnings' + time cargo +stable test --verbose --all --features bit-vec,bytes,generic-array,derive,max-encoded-len + + - name: Test Rust Stable (no_derive) + run: | + export RUSTFLAGS='-Cdebug-assertions=y -Dwarnings' + time cargo +stable test --verbose --features bit-vec,bytes,generic-array + + - name: Test Rust Stable (only_mel) + run: | + export RUSTFLAGS='-Cdebug-assertions=y -Dwarnings' + time cargo +stable test --verbose --features max-encoded-len + + - name: Test Rust Stable (only_mel-no_default_std) + run: | + export RUSTFLAGS='-Cdebug-assertions=y -Dwarnings' + time cargo +stable test --verbose --features max-encoded-len,std --no-default-features + +# Benches + bench-rust-nightly: + runs-on: ubuntu-latest + needs: [set-image] + strategy: + matrix: + feature: [bit-vec,bytes,generic-array,derive,max-encoded-len] + container: ${{ needs.set-image.outputs.IMAGE }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Cache Rust dependencies + uses: swatinem/rust-cache@v2 + with: + key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} + + - name: Bench Rust Nightly + run: | + export RUSTFLAGS='-Cdebug-assertions=y -Dwarnings' + time cargo +nightly bench --features ${{ matrix.feature }} + + miri: + runs-on: ubuntu-latest + needs: [set-image] + strategy: + matrix: + feature: [bit-vec,bytes,generic-array,arbitrary] + container: ${{ needs.set-image.outputs.IMAGE }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Cache Rust dependencies + uses: swatinem/rust-cache@v2 + with: + key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} + + - name: Run Miri + run: | + export RUST_BACKTRACE=1 + export RUSTFLAGS='-Cdebug-assertions=y -Dwarnings' + export MIRIFLAGS='-Zmiri-disable-isolation' + time cargo +nightly miri test --features ${{ matrix.feature }} --release + +# Build + + build-linux-ubuntu-amd64: + runs-on: ubuntu-latest + needs: [set-image, clippy, checks, tests] + container: ${{ needs.set-image.outputs.IMAGE }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Cache Rust dependencies + uses: swatinem/rust-cache@v2 + with: + key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} + + - name: Build for Linux (Ubuntu, AMD64) + run: cargo build --verbose --release --features bit-vec,bytes,generic-array,derive + + publish-dry-run: + runs-on: ubuntu-latest + needs: [set-image, build-linux-ubuntu-amd64] + container: ${{ needs.set-image.outputs.IMAGE }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Cache Rust dependencies + uses: swatinem/rust-cache@v2 + with: + key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} + + - name: Dry Run Publish + if: github.event_name == 'pull_request' + run: cargo publish -p parity-scale-codec --dry-run diff --git a/.github/workflows/gitspiegel-trigger.yml b/.github/workflows/gitspiegel-trigger.yml deleted file mode 100644 index dce3aaf2..00000000 --- a/.github/workflows/gitspiegel-trigger.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: gitspiegel sync - -# This workflow doesn't do anything, it's only use is to trigger "workflow_run" -# webhook, that'll be consumed by gitspiegel -# This way, gitspiegel won't do mirroring, unless this workflow runs, -# and running the workflow is protected by GitHub - -on: - pull_request: - types: - - opened - - synchronize - - unlocked - - ready_for_review - - reopened - -jobs: - sync: - runs-on: ubuntu-latest - steps: - - name: Do nothing - run: echo "let's go" diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..2e9f3322 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,23 @@ +name: Publish release to crates.io + +on: + release: + types: + - published + +jobs: + publish-crate: + runs-on: ubuntu-latest + environment: release + container: paritytech/ci-unified:bullseye-1.73.0 + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Cache Rust dependencies + uses: swatinem/rust-cache@v2 + with: + key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} + + - name: Publish Crate + run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }} -p parity-scale-codec diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index cc6b587f..00000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,201 +0,0 @@ -# .gitlab-ci.yml -# - -include: - - project: parity/infrastructure/ci_cd/shared - ref: main - file: /common/ci-unified.yml - -stages: - - check - - test - - build - - publish - -variables: - GIT_STRATEGY: fetch - GIT_DEPTH: "100" - CARGO_INCREMENTAL: 0 - CI_IMAGE: !reference [.ci-unified, variables, CI_IMAGE] - -default: - cache: {} - interruptible: true - retry: - max: 2 - when: - - runner_system_failure - - unknown_failure - - api_failure - -.kubernetes-env: - image: $CI_IMAGE - tags: - - kubernetes-parity-build - -.docker-env: - image: $CI_IMAGE - before_script: - - cargo -vV - - rustc -vV - - rustup show - - bash --version - rules: - - if: $CI_PIPELINE_SOURCE == "trigger" - - if: $CI_PIPELINE_SOURCE == "web" - - if: $CI_PIPELINE_SOURCE == "schedule" - - if: $CI_COMMIT_REF_NAME == "master" - - if: $CI_COMMIT_REF_NAME == "tags" - - if: $CI_COMMIT_REF_NAME =~ /^[0-9]+$/ # PRs - - if: $CI_COMMIT_REF_NAME =~ /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1 - tags: - - linux-docker - -#### stage: check - -check-clippy: - stage: check - extends: .docker-env - script: - - rustup component add clippy --toolchain stable-x86_64-unknown-linux-gnu - - time cargo +stable clippy --locked -- -Dwarnings - - time cargo +stable clippy --locked -p parity-scale-codec-derive -- -Dwarnings - - time cargo +stable clippy --locked --test clippy -- -Dwarnings - -check-rust-stable-no_derive_no_std: - stage: check - extends: .docker-env - variables: - RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings" - script: - - time cargo +stable check --verbose --no-default-features --features bit-vec,bytes,generic-array - -check-rust-stable-no_std-chain-error: - stage: check - extends: .docker-env - variables: - RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings" - script: - - time cargo +stable check --verbose --no-default-features --features chain-error - -check-rust-stable-no_derive: - stage: check - extends: .docker-env - variables: - RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings" - script: - - time cargo +stable check --verbose --features bit-vec,bytes,generic-array - -check-rust-stable-only_mel: - stage: check - extends: .docker-env - variables: - RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings" - script: - - time cargo +stable check --verbose --features max-encoded-len - -#### stage: test - -test-rust-stable: - stage: test - extends: .docker-env - variables: - RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings" - script: - - time cargo +stable test --verbose --all --features bit-vec,bytes,generic-array,derive,max-encoded-len - -test-rust-stable-no_derive: - stage: test - extends: .docker-env - variables: - RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings" - script: - - time cargo +stable test --verbose --features bit-vec,bytes,generic-array - -test-rust-stable-only_mel: - stage: test - extends: .docker-env - variables: - RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings" - script: - - time cargo +stable test --verbose --features max-encoded-len - -test-rust-stable-only_mel-no_default_std: - stage: test - extends: .docker-env - variables: - RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings" - script: - - time cargo +stable test --verbose --features max-encoded-len,std --no-default-features - -bench-rust-nightly: - stage: test - extends: .docker-env - script: - - time cargo +nightly bench --features bit-vec,bytes,generic-array,derive - -miri: - stage: test - extends: .docker-env - variables: - RUST_BACKTRACE: 1 - MIRIFLAGS: "-Zmiri-disable-isolation" - script: - - time cargo +nightly miri test --features bit-vec,bytes,generic-array,arbitrary --release - -# check that build is no_std compatible -# more info: https://github.com/paritytech/parity-scale-codec/pull/389 -build-no-std: - stage: test - extends: .docker-env - variables: - RUST_BACKTRACE: 1 - script: - # this target doesn't support std envs; it should flag any unexpected uses of std - - rustup target add thumbv6m-none-eabi - - time cargo build --target thumbv6m-none-eabi --no-default-features - -build-no-atomic-ptrs: - stage: test - extends: .docker-env - variables: - RUST_BACKTRACE: 1 - script: - # this target doesn't have atomic ptrs. Some parts of alloc are not available there - # we want to make sure that this crate still works on those targets - - cargo +nightly check --target bpfel-unknown-none -Zbuild-std="core,alloc" --no-default-features --features generic-array,derive,max-encoded-len,chain-error - -#### stage: build - -build-linux-ubuntu-amd64: - stage: build - extends: .docker-env - rules: - - if: $CI_PIPELINE_SOURCE == "web" - - if: $CI_PIPELINE_SOURCE == "schedule" - - if: $CI_COMMIT_REF_NAME == "master" - - if: $CI_COMMIT_REF_NAME == "tags" - script: - - cargo build --verbose --release --features bit-vec,bytes,generic-array,derive - -#### stage: publish - -publish-dry-run: - stage: publish - extends: .kubernetes-env - # artificial dependency in order not to wait miri job - needs: - - job: check-clippy - artifacts: false - rules: - - if: $CI_COMMIT_REF_NAME =~ /^[0-9]+$/ # PRs - script: - - cargo publish -p parity-scale-codec --dry-run - -publish-crate: - stage: publish - extends: .kubernetes-env - rules: - - if: $CI_COMMIT_REF_NAME =~ /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1 - script: - - cargo publish -p parity-scale-codec