From 48b56aa1780c23fa579904d01ee2e442c10863d2 Mon Sep 17 00:00:00 2001
From: Alexander Samusev <41779041+alvicsam@users.noreply.github.com>
Date: Wed, 9 Oct 2024 16:37:44 +0200
Subject: [PATCH] [ci] Move test-linux-stable-no-try-runtime to GHA (#5979)

PR moves `test-linux-stable-no-try-runtime` from gitlab to github.
I disabled two tests because our current runners don't have necessary
syscalls enabled. Will continue working on it in
https://github.com/paritytech/ci_cd/issues/1056
Also PR remove `gh cli` installation since it's installed in the
`ci-unified` image.

close https://github.com/paritytech/ci_cd/issues/1023
---
 .github/actions/set-up-gh/action.yml     | 38 ++++++++++--------------
 .github/workflows/check-semver.yml       |  9 +++---
 .github/workflows/tests-linux-stable.yml | 36 ++++++++++++++++++++++
 .gitlab/pipeline/test.yml                | 25 ----------------
 4 files changed, 55 insertions(+), 53 deletions(-)

diff --git a/.github/actions/set-up-gh/action.yml b/.github/actions/set-up-gh/action.yml
index fc16ce0b263..4dc3af4a19f 100644
--- a/.github/actions/set-up-gh/action.yml
+++ b/.github/actions/set-up-gh/action.yml
@@ -1,5 +1,5 @@
-name: 'install gh'
-description: 'Install the gh cli in a debian based distro and switches to the PR branch.'
+name: "install gh"
+description: "Install the gh cli in a debian based distro and switches to the PR branch."
 inputs:
   pr-number:
     description: "Number of the PR"
@@ -9,28 +9,20 @@ inputs:
     required: true
 outputs:
   branch:
-    description: 'Branch name for the PR'
+    description: "Branch name for the PR"
     value: ${{ steps.branch.outputs.branch }}
 runs:
   using: "composite"
   steps:
-      - name: Instal gh cli
-        shell: bash
-        # Here it would get the script from previous step
-        run: |
-          (type -p wget >/dev/null || (apt update && apt-get install wget -y))
-          mkdir -p -m 755 /etc/apt/keyrings
-          wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null 
-          chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg
-          echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null
-          apt update
-          apt install gh -y
-          git config --global --add safe.directory '*'
-      - run: gh pr checkout ${{ inputs.pr-number }}
-        shell: bash
-        env:
-          GITHUB_TOKEN: ${{ inputs.GH_TOKEN }}
-      - name: Export branch name
-        shell: bash
-        run: echo "branch=$(git rev-parse --abbrev-ref HEAD)" >> "$GITHUB_OUTPUT"
-        id: branch
+    - name: Set up git
+      shell: bash
+      # Here it would get the script from previous step
+      run: git config --global --add safe.directory '*'
+    - run: gh pr checkout ${{ inputs.pr-number }}
+      shell: bash
+      env:
+        GITHUB_TOKEN: ${{ inputs.GH_TOKEN }}
+    - name: Export branch name
+      shell: bash
+      run: echo "branch=$(git rev-parse --abbrev-ref HEAD)" >> "$GITHUB_OUTPUT"
+      id: branch
diff --git a/.github/workflows/check-semver.yml b/.github/workflows/check-semver.yml
index b5866e0ce41..811ec4d5558 100644
--- a/.github/workflows/check-semver.yml
+++ b/.github/workflows/check-semver.yml
@@ -13,10 +13,13 @@ env:
   TOOLCHAIN: nightly-2024-06-01
 
 jobs:
+  preflight:
+    uses: ./.github/workflows/reusable-preflight.yml
   check-semver:
     runs-on: ubuntu-latest
+    needs: [preflight]
     container:
-      image: docker.io/paritytech/ci-unified:bullseye-1.77.0-2024-04-10-v20240408
+      image: ${{ needs.preflight.outputs.IMAGE }}
     steps:
       - uses: actions/checkout@6d193bf28034eafb982f37bd894289fe649468fc # v4.1.7
         with:
@@ -36,10 +39,6 @@ jobs:
         run: |
           echo "This is a backport into stable."
 
-          wget -q https://github.com/cli/cli/releases/download/v2.51.0/gh_2.51.0_linux_amd64.tar.gz -O gh.tar.gz && \
-          tar -xzf gh.tar.gz && mv gh_2.51.0_linux_amd64/bin/gh /usr/local/bin/gh && rm gh.tar.gz
-          chmod +x /usr/local/bin/gh
-
             cat > msg.txt <<EOF
             This pull request is amending an existing release. Please proceed with extreme caution,
             as to not impact downstream teams that rely on the stability of it. Some things to consider:
diff --git a/.github/workflows/tests-linux-stable.yml b/.github/workflows/tests-linux-stable.yml
index 599edd8e69a..dd292d55e20 100644
--- a/.github/workflows/tests-linux-stable.yml
+++ b/.github/workflows/tests-linux-stable.yml
@@ -98,6 +98,41 @@ jobs:
         if: ${{ matrix.partition == '1/3' }}
         run: forklift cargo nextest run -p sp-api-test --features enable-staging-api --cargo-quiet
 
+  # some tests do not run with `try-runtime` feature enabled
+  # https://github.com/paritytech/polkadot-sdk/pull/4251#discussion_r1624282143
+  #
+  # all_security_features_work and nonexistent_cache_dir are currently skipped
+  # becuase runners don't have the necessary permissions to run them
+  test-linux-stable-no-try-runtime:
+    needs: [preflight]
+    if: ${{ needs.preflight.outputs.changes_rust }}
+    runs-on: ${{ needs.preflight.outputs.RUNNER }}
+    timeout-minutes: 60
+    container:
+      image: ${{ needs.preflight.outputs.IMAGE }}
+    strategy:
+      fail-fast: false
+      matrix:
+        partition: [1/2, 2/2]
+    env:
+      RUST_TOOLCHAIN: stable
+      # Enable debug assertions since we are running optimized builds for testing
+      # but still want to have debug assertions.
+      RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings"
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v4
+      - name: script
+        run: |
+          forklift cargo nextest run --workspace \
+                   --locked \
+                   --release \
+                   --no-fail-fast \
+                   --cargo-quiet \
+                   --features experimental,riscv,ci-only-tests \
+                   --filter-expr " !test(/all_security_features_work/) - test(/nonexistent_cache_dir/)" \
+                   --partition count:${{ matrix.partition }} \
+
   confirm-required-jobs-passed:
     runs-on: ubuntu-latest
     name: All tests passed
@@ -107,6 +142,7 @@ jobs:
         test-linux-stable-int,
         test-linux-stable-runtime-benchmarks,
         test-linux-stable,
+        test-linux-stable-no-try-runtime,
       ]
     if: always() && !cancelled()
     steps:
diff --git a/.gitlab/pipeline/test.yml b/.gitlab/pipeline/test.yml
index 0252620cd0f..00a0aa2c977 100644
--- a/.gitlab/pipeline/test.yml
+++ b/.gitlab/pipeline/test.yml
@@ -110,31 +110,6 @@ test-linux-stable-codecov:
         codecovcli -v do-upload -f target/coverage/result/report-${CI_NODE_INDEX}.lcov --disable-search -t ${CODECOV_TOKEN} -r paritytech/polkadot-sdk --commit-sha ${CI_COMMIT_SHA} --fail-on-error --git-service github;
       fi
 
-# some tests do not run with `try-runtime` feature enabled
-# https://github.com/paritytech/polkadot-sdk/pull/4251#discussion_r1624282143
-# Move to github after https://github.com/paritytech/ci_cd/issues/1056 is fixed
-test-linux-stable-no-try-runtime:
-  stage: test
-  extends:
-    - .docker-env
-    - .common-refs
-    - .run-immediately
-    - .pipeline-stopper-artifacts
-  variables:
-    RUST_TOOLCHAIN: stable
-    # Enable debug assertions since we are running optimized builds for testing
-    # but still want to have debug assertions.
-    RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings"
-  script:
-    - >
-      time cargo nextest run \
-        --workspace \
-        --locked \
-        --release \
-        --no-fail-fast \
-        --cargo-quiet \
-        --features experimental,riscv,ci-only-tests
-
 test-doc:
   stage: test
   extends:
-- 
GitLab