about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPietro Albini <pietro@pietroalbini.org>2019-11-11 14:31:32 +0100
committerPietro Albini <pietro@pietroalbini.org>2019-11-22 15:36:37 +0100
commit262ce313d065a40561e0da9a65ec6b5d35641560 (patch)
tree3d125e9439e4a8368f40482380dd1d593cfa0c2a /src
parentf50d6ea348c2dd7c2f76e35ecde6560d87bb98ec (diff)
ci: add support for GitHub Actions in the CI scripts
Diffstat (limited to 'src')
-rw-r--r--src/bootstrap/util.rs4
-rw-r--r--src/ci/azure-pipelines/steps/run.yml31
-rwxr-xr-xsrc/ci/docker/run.sh2
-rwxr-xr-xsrc/ci/run.sh4
-rwxr-xr-xsrc/ci/scripts/install-mingw.sh2
-rwxr-xr-xsrc/ci/scripts/install-msys2.sh6
-rw-r--r--src/ci/shared.sh71
7 files changed, 73 insertions, 47 deletions
diff --git a/src/bootstrap/util.rs b/src/bootstrap/util.rs
index 98ae7b692bb..6f8a6308745 100644
--- a/src/bootstrap/util.rs
+++ b/src/bootstrap/util.rs
@@ -262,6 +262,8 @@ pub enum CiEnv {
     None,
     /// The Azure Pipelines environment, for Linux (including Docker), Windows, and macOS builds.
     AzurePipelines,
+    /// The GitHub Actions environment, for Linux (including Docker), Windows and macOS builds.
+    GitHubActions,
 }
 
 impl CiEnv {
@@ -269,6 +271,8 @@ impl CiEnv {
     pub fn current() -> CiEnv {
         if env::var("TF_BUILD").ok().map_or(false, |e| &*e == "True") {
             CiEnv::AzurePipelines
+        } else if env::var("GITHUB_ACTIONS").ok().map_or(false, |e| &*e == "true") {
+            CiEnv::GitHubActions
         } else {
             CiEnv::None
         }
diff --git a/src/ci/azure-pipelines/steps/run.yml b/src/ci/azure-pipelines/steps/run.yml
index 214c11fd690..698aa5f2cf1 100644
--- a/src/ci/azure-pipelines/steps/run.yml
+++ b/src/ci/azure-pipelines/steps/run.yml
@@ -38,38 +38,26 @@ steps:
   displayName: Show the current environment
 
 - bash: src/ci/scripts/install-sccache.sh
-  env:
-    AGENT_OS: $(Agent.OS)
   displayName: Install sccache
   condition: and(succeeded(), not(variables.SKIP_JOB))
 
 - bash: src/ci/scripts/install-clang.sh
-  env:
-    AGENT_OS: $(Agent.OS)
   displayName: Install clang
   condition: and(succeeded(), not(variables.SKIP_JOB))
 
 - bash: src/ci/scripts/switch-xcode.sh
-  env:
-    AGENT_OS: $(Agent.OS)
   displayName: Switch to Xcode 9.3
   condition: and(succeeded(), not(variables.SKIP_JOB))
 
 - bash: src/ci/scripts/install-wix.sh
-  env:
-    AGENT_OS: $(Agent.OS)
   displayName: Install wix
   condition: and(succeeded(), not(variables.SKIP_JOB))
 
 - bash: src/ci/scripts/install-innosetup.sh
-  env:
-    AGENT_OS: $(Agent.OS)
   displayName: Install InnoSetup
   condition: and(succeeded(), not(variables.SKIP_JOB))
 
 - bash: src/ci/scripts/windows-symlink-build-dir.sh
-  env:
-    AGENT_OS: $(Agent.OS)
   displayName: Ensure the build happens on C:\ instead of D:\
   condition: and(succeeded(), not(variables.SKIP_JOB))
 
@@ -78,35 +66,22 @@ steps:
   condition: and(succeeded(), not(variables.SKIP_JOB))
 
 - bash: src/ci/scripts/install-msys2.sh
-  env:
-    AGENT_OS: $(Agent.OS)
-    SYSTEM_WORKFOLDER: $(System.Workfolder)
   displayName: Install msys2
   condition: and(succeeded(), not(variables.SKIP_JOB))
 
 - bash: src/ci/scripts/install-msys2-packages.sh
-  env:
-    AGENT_OS: $(Agent.OS)
-    SYSTEM_WORKFOLDER: $(System.Workfolder)
   displayName: Install msys2 packages
   condition: and(succeeded(), not(variables.SKIP_JOB))
 
 - bash: src/ci/scripts/install-mingw.sh
-  env:
-    AGENT_OS: $(Agent.OS)
-    SYSTEM_WORKFOLDER: $(System.Workfolder)
   displayName: Install MinGW
   condition: and(succeeded(), not(variables.SKIP_JOB))
 
 - bash: src/ci/scripts/install-ninja.sh
-  env:
-    AGENT_OS: $(Agent.OS)
   displayName: Install ninja
   condition: and(succeeded(), not(variables.SKIP_JOB))
 
 - bash: src/ci/scripts/enable-docker-ipv6.sh
-  env:
-    AGENT_OS: $(Agent.OS)
   displayName: Enable IPv6 on Docker
   condition: and(succeeded(), not(variables.SKIP_JOB))
 
@@ -120,22 +95,16 @@ steps:
   condition: and(succeeded(), not(variables.SKIP_JOB))
 
 - bash: src/ci/scripts/checkout-submodules.sh
-  env:
-    AGENT_OS: $(Agent.OS)
   displayName: Checkout submodules
   condition: and(succeeded(), not(variables.SKIP_JOB))
 
 - bash: src/ci/scripts/verify-line-endings.sh
-  env:
-    AGENT_OS: $(Agent.OS)
   displayName: Verify line endings
   condition: and(succeeded(), not(variables.SKIP_JOB))
 
 # Ensure the `aws` CLI is installed so we can deploy later on, cache docker
 # images, etc.
 - bash: src/ci/scripts/install-awscli.sh
-  env:
-    AGENT_OS: $(Agent.OS)
   condition: and(succeeded(), not(variables.SKIP_JOB))
   displayName: Install awscli
 
diff --git a/src/ci/docker/run.sh b/src/ci/docker/run.sh
index cdafcbadc9e..f29f9f3bf1c 100755
--- a/src/ci/docker/run.sh
+++ b/src/ci/docker/run.sh
@@ -172,6 +172,8 @@ docker \
   --env CI \
   --env TF_BUILD \
   --env BUILD_SOURCEBRANCHNAME \
+  --env GITHUB_ACTIONS \
+  --env GITHUB_REF \
   --env TOOLSTATE_REPO_ACCESS_TOKEN \
   --env TOOLSTATE_REPO \
   --env TOOLSTATE_PUBLISH \
diff --git a/src/ci/run.sh b/src/ci/run.sh
index bce35670c8d..ae5b22493ab 100755
--- a/src/ci/run.sh
+++ b/src/ci/run.sh
@@ -23,9 +23,7 @@ fi
 ci_dir=`cd $(dirname $0) && pwd`
 source "$ci_dir/shared.sh"
 
-branch_name=$(getCIBranch)
-
-if [ ! isCI ] || [ "$branch_name" = "auto" ] || [ "$branch_name" = "try" ]; then
+if [ ! isCI ] || isCiBranch auto || isCiBranch beta; then
     RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set build.print-step-timings --enable-verbose-tests"
 fi
 
diff --git a/src/ci/scripts/install-mingw.sh b/src/ci/scripts/install-mingw.sh
index 8b579587b9e..98373df7fce 100755
--- a/src/ci/scripts/install-mingw.sh
+++ b/src/ci/scripts/install-mingw.sh
@@ -52,7 +52,7 @@ if isWindows; then
     if [[ "${CUSTOM_MINGW-0}" -ne 1 ]]; then
         pacman -S --noconfirm --needed mingw-w64-$arch-toolchain mingw-w64-$arch-cmake \
             mingw-w64-$arch-gcc mingw-w64-$arch-python2
-        ciCommandAddPath "${SYSTEM_WORKFOLDER}/msys2/mingw${bits}/bin"
+        ciCommandAddPath "$(ciCheckoutPath)/msys2/mingw${bits}/bin"
     else
         mingw_dir="mingw${bits}"
 
diff --git a/src/ci/scripts/install-msys2.sh b/src/ci/scripts/install-msys2.sh
index ce37c3b1469..c9fafc7fe6b 100755
--- a/src/ci/scripts/install-msys2.sh
+++ b/src/ci/scripts/install-msys2.sh
@@ -12,8 +12,8 @@ IFS=$'\n\t'
 source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"
 
 if isWindows; then
-    choco install msys2 --params="/InstallDir:${SYSTEM_WORKFOLDER}/msys2 /NoPath" -y --no-progress
-    mkdir -p "${SYSTEM_WORKFOLDER}/msys2/home/${USERNAME}"
+    choco install msys2 --params="/InstallDir:$(ciCheckoutPath)/msys2 /NoPath" -y --no-progress
+    mkdir -p "$(ciCheckoutPath)/msys2/home/${USERNAME}"
 
-    ciCommandAddPath "${SYSTEM_WORKFOLDER}/msys2/usr/bin"
+    ciCommandAddPath "$(ciCheckoutPath)/msys2/usr/bin"
 fi
diff --git a/src/ci/shared.sh b/src/ci/shared.sh
index 862ded0d5db..98120f5dff9 100644
--- a/src/ci/shared.sh
+++ b/src/ci/shared.sh
@@ -27,27 +27,66 @@ function retry {
 }
 
 function isCI {
-  [ "$CI" = "true" ] || [ "$TF_BUILD" = "True" ]
+    [[ "${CI-false}" = "true" ]] || isAzurePipelines || isGitHubActions
+}
+
+function isAzurePipelines {
+    [[ "${TF_BUILD-False}" = "True" ]]
+}
+
+function isGitHubActions {
+    [[ "${GITHUB_ACTIONS-false}" = "true" ]]
 }
 
 function isMacOS {
-  [ "$AGENT_OS" = "Darwin" ]
+    [[ "${OSTYPE}" = "darwin"* ]]
 }
 
 function isWindows {
-  [ "$AGENT_OS" = "Windows_NT" ]
+    [[ "${OSTYPE}" = "cygwin" ]] || [[ "${OSTYPE}" = "msys" ]]
 }
 
 function isLinux {
-  [ "$AGENT_OS" = "Linux" ]
+    [[ "${OSTYPE}" = "linux-gnu" ]]
 }
 
-function getCIBranch {
-  echo "$BUILD_SOURCEBRANCHNAME"
+function isCiBranch {
+    if [[ $# -ne 1 ]]; then
+        echo "usage: $0 <branch-name>"
+        exit 1
+    fi
+    name="$1"
+
+    if isAzurePipelines; then
+        [[ "${BUILD_SOURCEBRANCHNAME}" = "${name}" ]]
+    elif isGitHubActions; then
+        [[ "${GITHUB_REF}" = "refs/heads/${name}" ]]
+    else
+        echo "isCiBranch only works inside CI!"
+        exit 1
+    fi
 }
 
 function ciCommit {
-  echo "${BUILD_SOURCEVERSION}"
+    if isAzurePipelines; then
+        echo "${BUILD_SOURCEVERSION}"
+    elif isGitHubActions; then
+        echo "${GITHUB_SHA}"
+    else
+        echo "ciCommit only works inside CI!"
+        exit 1
+    fi
+}
+
+function ciCheckoutPath {
+    if isAzurePipelines; then
+        echo "${SYSTEM_WORKFOLDER}"
+    elif isGitHubActions; then
+        echo "${GITHUB_WORKSPACE}"
+    else
+        echo "ciCheckoutPath only works inside CI!"
+        exit 1
+    fi
 }
 
 function ciCommandAddPath {
@@ -57,7 +96,14 @@ function ciCommandAddPath {
     fi
     path="$1"
 
-    echo "##vso[task.prependpath]${path}"
+    if isAzurePipelines; then
+        echo "##vso[task.prependpath]${path}"
+    elif isGitHubActions; then
+        echo "::add-path::${value}"
+    else
+        echo "ciCommandAddPath only works inside CI!"
+        exit 1
+    fi
 }
 
 function ciCommandSetEnv {
@@ -68,5 +114,12 @@ function ciCommandSetEnv {
     name="$1"
     value="$2"
 
-    echo "##vso[task.setvariable variable=${name}]${value}"
+    if isAzurePipelines; then
+        echo "##vso[task.setvariable variable=${name}]${value}"
+    elif isGitHubActions; then
+        echo "::set-env name=${name}::${value}"
+    else
+        echo "ciCommandSetEnv only works inside CI!"
+        exit 1
+    fi
 }