From 2a7aceffed4fd0a9ac8e809e855b2c68aa0a12e8 Mon Sep 17 00:00:00 2001
From: Cheng Shao <terrorjack@type.dance>
Date: Thu, 5 Dec 2024 20:21:59 +0000
Subject: [PATCH] ci: multi-project pipeline for wasm

(cherry picked from commit 3655c3fd295cde9a78c15aa0ac002cf94bb813be)
(cherry picked from commit b6d5cce5e29c47623961fdf643f3f24759d3ca8c)
(cherry picked from commit 48eeb1fa4c2bf169d038c0747332b05efd7c6946)
---
 .gitlab-ci.yml | 135 ++++++++++++++-----------------------------------
 .gitlab/ci.sh  |   7 +++
 2 files changed, 44 insertions(+), 98 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index a6e87db8399..2af6534c91d 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -2,7 +2,7 @@ variables:
   GIT_SSL_NO_VERIFY: "1"
 
   # Commit of ghc/ci-images repository from which to pull Docker images
-  DOCKER_REV: efc1ab81236eb37e20cb287ec77aebb6c6341098
+  DOCKER_REV: eb4d3389fd62e4f7321a0c8799014ec1f4da0708
 
   # Sequential version number of all cached things.
   # Bump to invalidate GitLab CI cache.
@@ -78,6 +78,7 @@ workflow:
     - if: '$CI_COMMIT_BRANCH == "master"'
     - if: '$CI_COMMIT_BRANCH =~ /ghc-[0-9]+\.[0-9]+/'
     - if: '$CI_PIPELINE_SOURCE == "web"'
+    - if: $CI_PIPELINE_SOURCE == "pipeline"
 
 # which versions of GHC to allow bootstrap with
 .bootstrap_matrix : &bootstrap_matrix
@@ -203,30 +204,6 @@ ghc-linters:
     - if: $CI_MERGE_REQUEST_ID
     - *drafts-can-fail-lint
 
-# Run mypy Python typechecker on linter scripts.
-lint-linters:
-  image: "registry.gitlab.haskell.org/ghc/ci-images/linters:$DOCKER_REV"
-  extends: .lint
-  script:
-    - mypy testsuite/tests/linters/regex-linters/*.py
-  dependencies: []
-
-# Check that .T files all parse by listing broken tests.
-lint-testsuite:
-  image: "registry.gitlab.haskell.org/ghc/ci-images/x86_64-linux-deb9:$DOCKER_REV"
-  extends: .lint
-  script:
-    - make -Ctestsuite list_broken TEST_HC=$GHC
-  dependencies: []
-
-# Run mypy Python typechecker on testsuite driver
-typecheck-testsuite:
-  image: "registry.gitlab.haskell.org/ghc/ci-images/linters:$DOCKER_REV"
-  extends: .lint
-  script:
-    - mypy testsuite/driver/runtests.py
-  dependencies: []
-
 # We allow the submodule checker to fail when run on merge requests (to
 # accommodate, e.g., haddock changes not yet upstream) but not on `master` or
 # Marge jobs.
@@ -263,49 +240,6 @@ lint-author:
     - if: $CI_MERGE_REQUEST_ID
     - *drafts-can-fail-lint
 
-lint-ci-config:
-  image: nixos/nix:2.12.0
-  extends: .lint
-  # We don't need history/submodules in this job
-  variables:
-    GIT_DEPTH: 1
-    GIT_SUBMODULE_STRATEGY: none
-  before_script:
-    - echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf
-    - nix-channel --update
-  script:
-    - .gitlab/generate_jobs
-    # 1 if .gitlab/generate_jobs changed the output of the generated config
-    - nix shell nixpkgs#git -c git diff --exit-code
-  dependencies: []
-
-lint-submods:
-  extends: .lint-submods
-  # Allow failure on merge requests since any necessary submodule patches may
-  # not be upstreamed yet.
-  rules:
-    - if: '$CI_MERGE_REQUEST_LABELS =~ /.*marge_bot_batch_merge_job.*/'
-      allow_failure: false
-    # Don't run on nightly because the program needs a base commit to check.
-    - if: $NIGHTLY
-      when: never
-    - allow_failure: true
-
-lint-submods-branch:
-  extends: .lint-submods
-  variables:
-    BUILD_FLAVOUR: default
-  script:
-    - .gitlab/ci.sh configure
-    - .gitlab/ci.sh run_hadrian stage0:exe:lint-submodule-refs
-    - "echo Linting submodule changes between $CI_COMMIT_BEFORE_SHA..$CI_COMMIT_SHA"
-    - git submodule foreach git remote update
-    - _build/stageBoot/bin/lint-submodule-refs . $(git rev-list $CI_COMMIT_BEFORE_SHA..$CI_COMMIT_SHA)
-  rules:
-    - if: '$CI_COMMIT_BRANCH == "master"'
-    - if: '$CI_COMMIT_BRANCH =~ /ghc-[0.9]+\.[0-9]+/'
-    - *drafts-can-fail-lint
-
 ############################################################
 # GHC source code linting
 ############################################################
@@ -329,17 +263,6 @@ lint-submods-branch:
     paths:
       - cabal-cache
 
-hlint-ghc-and-base:
-  extends: .lint-params
-  image: "registry.gitlab.haskell.org/ghc/ci-images/linters:$DOCKER_REV"
-  variables:
-    BUILD_FLAVOUR: default
-  script:
-    - .gitlab/ci.sh setup
-    - .gitlab/ci.sh configure
-    - .gitlab/ci.sh run_hadrian lint:base
-    - .gitlab/ci.sh run_hadrian lint:compiler
-
 ############################################################
 # GHC-in-GHCi (Hadrian)
 ############################################################
@@ -347,10 +270,8 @@ hlint-ghc-and-base:
 hadrian-ghc-in-ghci:
   stage: quick-build
   needs:
-    - job: lint-linters
-    - job: lint-submods
-      optional: true
-  image: "registry.gitlab.haskell.org/ghc/ci-images/x86_64-linux-deb10:$DOCKER_REV"
+    - only-wasm
+  image: "registry.gitlab.haskell.org/ghc/ci-images/x86_64-linux-deb12:$DOCKER_REV"
   before_script:
     # workaround for docker permissions
     - sudo chown ghc:ghc -R .
@@ -425,21 +346,6 @@ hadrian-multi:
     paths:
       - cabal-cache
 
-############################################################
-# stack-hadrian-build
-############################################################
-
-# Verify that Hadrian builds with stack. Note that we don't actually perform a
-# build of GHC itself; we merely test that the Hadrian executable builds and
-# works (by invoking `hadrian --version`).
-stack-hadrian-build:
-  extends: hadrian-ghc-in-ghci
-  stage: quick-build
-  script:
-    - .gitlab/ci.sh setup
-    - .gitlab/ci.sh configure
-    - hadrian/build-stack --version
-
 ####################################
 # Testing reinstallable ghc codepath
 ####################################
@@ -1089,3 +995,36 @@ ghcup-metadata-testing-release:
   rules:
     - if: '$RELEASE_JOB == "yes"'
   when: manual
+
+only-wasm:
+  stage: quick-build
+  image: nixos/nix:2.25.3
+  tags:
+    - x86_64-linux
+  needs: []
+  variables:
+    GIT_STRATEGY: none
+    KEEP_JOB_NAME: x86_64-linux-alpine3_20-wasm-cross_wasm32-wasi-release+host_fully_static
+  before_script:
+    - echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf
+    - echo "cores = $CPUS" >> /etc/nix/nix.conf
+    - echo "max-jobs = $CPUS" >> /etc/nix/nix.conf
+    - nix run nixpkgs#gnused -- -i -e 's/ nixbld//' /etc/nix/nix.conf
+  script:
+    - nix run nixpkgs#deno -- run --allow-env --allow-net https://gist.githubusercontent.com/TerrorJack/e0e886b87b9bfffb6c5fa5b3aeddcecc/raw/09a066e2f9b53c82f1a5bf099cd9375f5ff2cbae/cancel.js
+
+ghc-wasm-meta-ci:
+  stage: testing
+  needs:
+    - job: x86_64-linux-alpine3_20-wasm-cross_wasm32-wasi-release+host_fully_static
+      artifacts: false
+  variables:
+    UPSTREAM_GHC_FLAVOUR: "9.6"
+    UPSTREAM_GHC_PIPELINE_ID: $CI_PIPELINE_ID
+  rules:
+    - if: $UPSTREAM_WASI_SDK_PIPELINE_ID != null
+      variables:
+        UPSTREAM_WASI_SDK_PIPELINE_ID: $UPSTREAM_WASI_SDK_PIPELINE_ID
+  trigger:
+    project: haskell-wasm/ghc-wasm-meta
+    branch: master
diff --git a/.gitlab/ci.sh b/.gitlab/ci.sh
index 6d8a6f31c23..9257782d5f9 100755
--- a/.gitlab/ci.sh
+++ b/.gitlab/ci.sh
@@ -239,6 +239,13 @@ function set_toolchain_paths() {
   export ALEX
 
   if [[ "${CROSS_TARGET:-}" == *"wasm"* ]]; then
+    if [[ ! -f ~/.ghc-wasm/.flag ]]; then
+      pushd "$(mktemp -d)"
+      curl -f -L --retry 5 https://gitlab.haskell.org/haskell-wasm/ghc-wasm-meta/-/archive/master/ghc-wasm-meta-master.tar.gz | tar xz --strip-components=1
+      SKIP_GHC=1 ./setup.sh
+      popd
+      touch ~/.ghc-wasm/.flag
+    fi
     source "/home/ghc/.ghc-wasm/env"
   fi
 }
-- 
GitLab