From 05abc1a38a27658732fce8798c5d251d898bae11 Mon Sep 17 00:00:00 2001 From: Alexander Samusev <41779041+alvicsam@users.noreply.github.com> Date: Wed, 24 Aug 2022 15:54:40 +0200 Subject: [PATCH] [ci] add auto cargo-fmt (#1562) * [WIP][ci] add auto cargo-fmt * [ci] Apply cargo-fmt * use fmt nightly * [ci] Apply cargo-fmt * add comment to cargo-fmt and remove fmt gha Co-authored-by: paritytech-ci --- .github/workflows/quick-check.yml | 40 ------------------------------- .gitlab-ci.yml | 36 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 40 deletions(-) delete mode 100644 .github/workflows/quick-check.yml diff --git a/.github/workflows/quick-check.yml b/.github/workflows/quick-check.yml deleted file mode 100644 index 5026aeaf091..00000000000 --- a/.github/workflows/quick-check.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Quick check Formatting - -on: - push: - branches: - - "*" - pull_request: - types: [opened, synchronize, reopened, ready_for_review] - -jobs: - quick_check: - strategy: - matrix: - os: ["ubuntu-latest"] - runs-on: ${{ matrix.os }} - steps: - - name: Install Rust nightly toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true - components: clippy, rustfmt - - - name: Cache Dependencies & Build Outputs - uses: actions/cache@v3 - with: - path: | - ~/.cargo/registry - ~/.cargo/git - target - key: ${{ runner.os }}-${{ matrix.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - - uses: actions/checkout@v3 - - - name: Cargo fmt - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 78a189fbce5..c4d0ad28ed4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -69,6 +69,11 @@ variables: - if: $CI_COMMIT_REF_NAME =~ /^release-parachains-v[0-9].*$/ # i.e. release-parachains-v1.0, release-parachains-v2.1rc1, release-parachains-v3000 - if: $CI_COMMIT_REF_NAME =~ /^polkadot-v[0-9]+\.[0-9]+.*$/ # i.e. polkadot-v1.0.99, polkadot-v2.1rc1 +.pr-refs: &pr-refs + # these jobs run always* + rules: + - if: $CI_COMMIT_REF_NAME =~ /^[0-9]+$/ # PRs + .publish-refs: &publish-refs rules: - if: $CI_COMMIT_REF_NAME == "master" @@ -107,6 +112,23 @@ variables: tags: - kubernetes-parity-build +#### stage: .pre + +# checks code format and fails if formatting is required +# the code will be formatted automatically and the pipeline will be restarted +cargo-fmt: + stage: .pre + <<: *pr-refs + <<: *kubernetes-env + before_script: + - echo PROJECT_NAME=$CI_PROJECT_NAME > fmt.env + - echo PR_BRANCH_NAME=$(curl -s https://api.github.com/repos/paritytech/${CI_PROJECT_NAME}/pulls/${CI_COMMIT_REF_NAME} | jq -r ".head.ref") >> fmt.env + script: + - cargo +nightly fmt --check + artifacts: + reports: + dotenv: fmt.env + #### stage: test test-linux-stable: @@ -601,3 +623,17 @@ cancel-pipeline: project: "parity/infrastructure/ci_cd/pipeline-stopper" # remove branch, when pipeline-stopper for substrate and polakdot is updated to the same branch branch: "as-improve" + +# this job will automatically format code and rerun pipeline if cargo-fmt job fails +auto-fmt: + stage: .post + rules: + - if: $CI_COMMIT_REF_NAME =~ /^[0-9]+$/ # PRs + when: on_failure + needs: + - job: cargo-fmt + variables: + PROJECT_NAME: "${CI_PROJECT_NAME}" + PR_BRANCH_NAME: "${PR_BRANCH_NAME}" + trigger: + project: "parity/infrastructure/ci_cd/auto-fmt"