From e26d1a0b3ef870e3a394c62f46fe85389058a54b Mon Sep 17 00:00:00 2001
From: Max Inden <mail@max-inden.de>
Date: Mon, 11 Nov 2019 14:49:15 +0100
Subject: [PATCH] [WIP] .gitlab-ci.yml: Fix a check for polkadot to work on
 forked repos v2 (#4078)

* Fix a check for polkadot to work on forked repos.

* .gitlab-ci.yml: Add `git diff` for CI debugging

* More future proof and less redundant.

* .gitlab-ci.yml: Improve comments and refactor sed command

* .gitlab-ci.yml: Remove two commas in a row

* .gitlab-ci.yml: Ensure to match branch statements at the end

* .gitlab-ci.yml: Reference concrete commit

When one does not specify the concrete commit, cargo-update tries to
checkout 'master' in the Substrate repository.

* .gitlab-ci.yml: Remove 'git diff' debug line
---
 substrate/.gitlab-ci.yml | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/substrate/.gitlab-ci.yml b/substrate/.gitlab-ci.yml
index baf875fd0fb..c8c5abddce9 100644
--- a/substrate/.gitlab-ci.yml
+++ b/substrate/.gitlab-ci.yml
@@ -289,7 +289,7 @@ build-linux-subkey:
   script:
     - cd ./subkey
     - BUILD_DUMMY_WASM_BINARY=1 time cargo build --release --verbose
-    - cd ..
+    - cd -
     - sccache -s
     - mkdir -p ./artifacts/subkey
     - mv ./target/release/subkey ./artifacts/subkey/.
@@ -338,6 +338,7 @@ check_warnings:
       fi
   allow_failure:                   true
 
+# Check whether Polkadot 'master' branch builds using this Substrate commit.
 check_polkadot:
   stage:                           build
   <<:                              *docker-env
@@ -345,13 +346,25 @@ check_polkadot:
   dependencies:
     - test-linux-stable
   script:
-    - git clone --depth 1 https://github.com/paritytech/polkadot.git
     - COMMIT_HASH=$(git rev-parse HEAD)
+    - SUBSTRATE_PATH=$(pwd)
+    # Clone the current Polkadot master branch into ./polkadot.
+    - git clone --depth 1 https://gitlab.parity.io/parity/polkadot.git
     - cd polkadot
-    - git grep -l "polkadot-master" | grep toml | xargs sed -i "s/branch.*=.*\"polkadot-master\"/rev = \"$COMMIT_HASH\"/"
-    - cargo update -p sr-io --precise $COMMIT_HASH
+    # Within Polkadot 'master' alter each Cargo.toml that references the
+    # Substrate 'polkadot-master' branch:
+    # 1. Replace the 'branch = "polkadot-master"' statements with the rev of our
+    #    commit.
+    # 2. Replace 'git = "https://.*"' with 'git = "file://.*"' (the local
+    #    checked out Substrate repository one folder above).
+    # 3. Remove any trailing commas.
+    - git grep -l "polkadot-master" | grep toml | xargs sed -i "s/branch.*=.*\"polkadot-master\"/rev = \"$COMMIT_HASH\"/; s~https://github.com/paritytech/substrate~file://$SUBSTRATE_PATH~; s/,\s*}/ }/"
+    # Make sure 'Cargo.lock' matches 'Cargo.toml'. It's enough to update one
+    # package, others are updated along the way.
+    - cargo update -p sr-io
+    # Check whether Polkadot 'master' branch builds with this Substrate commit.
     - time cargo check
-    - cd ..
+    - cd -
     - sccache -s
 
 #### stage:                        publish
-- 
GitLab