From ad72cd8d481008ddc38bdd67a3ca3434901dd795 Mon Sep 17 00:00:00 2001
From: Alexander Samusev <41779041+alvicsam@users.noreply.github.com>
Date: Fri, 3 May 2024 12:43:24 +0200
Subject: [PATCH] [WIP][CI] Add more GHA jobs (#4270)

cc https://github.com/paritytech/ci_cd/issues/939
---
 .github/env                               |  1 +
 .github/workflows/quick-checks.yml        | 81 +++++++++++++++++++++++
 .github/workflows/test-github-actions.yml | 27 +++++---
 3 files changed, 101 insertions(+), 8 deletions(-)
 create mode 100644 .github/env
 create mode 100644 .github/workflows/quick-checks.yml

diff --git a/.github/env b/.github/env
new file mode 100644
index 00000000000..162ce8af7c0
--- /dev/null
+++ b/.github/env
@@ -0,0 +1 @@
+IMAGE="docker.io/paritytech/ci-unified:bullseye-1.77.0-2024-04-10-v20240408"
\ No newline at end of file
diff --git a/.github/workflows/quick-checks.yml b/.github/workflows/quick-checks.yml
new file mode 100644
index 00000000000..7bf1983a1f6
--- /dev/null
+++ b/.github/workflows/quick-checks.yml
@@ -0,0 +1,81 @@
+# Checks that doesn't require heavy lifting, like formatting, linting, etc.
+name: quick-checks
+
+on:
+  pull_request:
+    types: [opened, synchronize, reopened, ready_for_review]
+  merge_group:
+concurrency:
+  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
+  cancel-in-progress: true
+
+jobs:
+  set-image:
+    # GitHub Actions allows using 'env' in a container context.
+    # However, env variables don't work for forks: https://github.com/orgs/community/discussions/44322
+    # This workaround sets the container image for each job using 'set-image' job output.
+    runs-on: arc-runners-polkadot-sdk-default
+    timeout-minutes: 10
+    outputs:
+      IMAGE: ${{ steps.set_image.outputs.IMAGE }}
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v4
+      - id: set_image
+        run: cat .github/env >> $GITHUB_OUTPUT
+  fmt:
+    runs-on: arc-runners-polkadot-sdk-default
+    timeout-minutes: 10
+    needs: [set-image]
+    container:
+      image: ${{ needs.set-image.outputs.IMAGE }}
+    steps:
+      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
+      - name: Cargo fmt
+        run: cargo +nightly fmt --all -- --check
+  check-dependency-rules:
+    runs-on: arc-runners-polkadot-sdk-default
+    timeout-minutes: 10
+    needs: [set-image]
+    container:
+      image: ${{ needs.set-image.outputs.IMAGE }}
+    steps:
+      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
+      - name: check dependency rules
+        run: |
+          cd substrate/
+          ../.gitlab/ensure-deps.sh
+  check-rust-feature-propagation:
+    runs-on: arc-runners-polkadot-sdk-default
+    # runs-on: ubuntu-latest
+    timeout-minutes: 10
+    needs: [set-image]
+    container:
+      image: ${{ needs.set-image.outputs.IMAGE }}
+    steps:
+      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
+      - name: run zepter
+        run: zepter run check
+  test-rust-features:
+    runs-on: arc-runners-polkadot-sdk-default
+    # runs-on: ubuntu-latest
+    timeout-minutes: 10
+    needs: [set-image]
+    container:
+      image: ${{ needs.set-image.outputs.IMAGE }}
+    steps:
+      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
+      - name: run rust features
+        run: bash .gitlab/rust-features.sh .
+  check-toml-format:
+    runs-on: arc-runners-polkadot-sdk-default
+    timeout-minutes: 10
+    needs: [set-image]
+    container:
+      image: ${{ needs.set-image.outputs.IMAGE }}
+    steps:
+      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
+      - name: check toml format
+        run: |
+          taplo format --check --config .config/taplo.toml
+          echo "Please run `taplo format --config .config/taplo.toml` to fix any toml formatting issues"
diff --git a/.github/workflows/test-github-actions.yml b/.github/workflows/test-github-actions.yml
index c8ce49cb462..e35ee099486 100644
--- a/.github/workflows/test-github-actions.yml
+++ b/.github/workflows/test-github-actions.yml
@@ -8,15 +8,25 @@ concurrency:
   group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
   cancel-in-progress: true
 
-env:
-  CARGO_NET_GIT_FETCH_WITH_CLI: true
-
 jobs:
+  set-image:
+    # GitHub Actions allows using 'env' in a container context.
+    # However, env variables don't work for forks: https://github.com/orgs/community/discussions/44322
+    # 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:
+      - name: Checkout
+        uses: actions/checkout@v4
+      - id: set_image
+        run: cat .github/env >> $GITHUB_OUTPUT
   test-linux-stable-int:
-    runs-on: arc-runners-polkadot-sdk
+    runs-on: arc-runners-polkadot-sdk-beefy
     timeout-minutes: 30
+    needs: [set-image]
     container:
-      image: "docker.io/paritytech/ci-unified:bullseye-1.77.0-2024-04-10-v20240408"
+      image: ${{ needs.set-image.outputs.IMAGE }}
     env:
       RUSTFLAGS: "-C debug-assertions -D warnings"
       RUST_BACKTRACE: 1
@@ -30,10 +40,11 @@ jobs:
       - name: script
         run: WASM_BUILD_NO_COLOR=1 time cargo test -p staging-node-cli --release --locked -- --ignored
   quick-benchmarks:
-    runs-on: arc-runners-polkadot-sdk
+    runs-on: arc-runners-polkadot-sdk-beefy
     timeout-minutes: 30
+    needs: [set-image]
     container:
-      image: "docker.io/paritytech/ci-unified:bullseye-1.77.0-2024-04-10-v20240408"
+      image: ${{ needs.set-image.outputs.IMAGE }}
     env:
       RUSTFLAGS: "-C debug-assertions -D warnings"
       RUST_BACKTRACE: "full"
@@ -43,4 +54,4 @@ jobs:
       - name: Checkout
         uses: actions/checkout@v4
       - name: script
-        run: time cargo run --locked --release -p staging-node-cli --bin substrate-node --features runtime-benchmarks --quiet -- benchmark pallet --chain dev --pallet "*" --extrinsic "*" --steps 2 --repeat 1 --quiet
+        run: time cargo run --locked --release -p staging-node-cli --bin substrate-node --features runtime-benchmarks -- benchmark pallet --chain dev --pallet "*" --extrinsic "*" --steps 2 --repeat 1 --quiet
-- 
GitLab