diff --git a/azure-pipelines.yml b/azure-pipelines.yml index dccd0d05e75fc..835948b0314c5 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -44,14 +44,23 @@ jobs: - task: NodeTool@0 inputs: - versionSpec: '8.x' - displayName: 'Install node.js 8.x' + # versionSpec: '8.x' + versionSpec: '13.x' + # rerunFailedTests: True # Optional + # rerunMaxAttempts: '10' # Optional + # displayName: 'Install node.js 8.x' + displayName: 'Install node.js 13.x v3' + # workaround flaky test https://github.com/nim-lang/Nim/issues/13477 + continueOnError: 'true' + # CHECKME + condition: eq(variables['Agent.OS'], 'Windows_NT') - bash: | sudo apt-fast update -qq DEBIAN_FRONTEND='noninteractive' \ sudo apt-fast install --no-install-recommends -yq \ libcurl4-openssl-dev libgc-dev libsdl1.2-dev libsfml-dev valgrind libc6-dbg + displayName: 'Install dependencies (amd64 Linux)' condition: and(eq(variables['Agent.OS'], 'Linux'), eq(variables['CPU'], 'amd64')) @@ -98,7 +107,8 @@ jobs: displayName: 'Install dependencies (i386 Linux)' condition: and(eq(variables['Agent.OS'], 'Linux'), eq(variables['CPU'], 'i386')) - - bash: brew install boehmgc make sfml + - bash: brew install --display-times boehmgc make sfml + displayName: 'Install dependencies (OSX)' condition: eq(variables['Agent.OS'], 'Darwin') @@ -152,4 +162,28 @@ jobs: ./koch runCI || echo '##vso[task.complete result=Failed]' displayName: 'Run CI' env: + # see https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml SYSTEM_ACCESSTOKEN: $(System.AccessToken) + + NIM_CI_PR_SourceRepositoryURI: $(System.PullRequest.SourceRepositoryURI) + NIM_CI_PR_PullRequestNumber: $(System.PullRequest.PullRequestNumber) + + NIM_CI_TeamProject: $(System.TeamProject) + NIM_CI_JobAttempt: $(System.JobAttempt) + + NIM_CI_Build_ArtifactStagingDirectory: $(Build.ArtifactStagingDirectory) + NIM_CI_Build_BuildId: $(Build.BuildId) + NIM_CI_Build_BuildNumber: $(Build.BuildNumber) + NIM_CI_Build_BuildUri: $(Build.BuildUri) + NIM_CI_Build_BinariesDirectory: $(Build.BinariesDirectory) + NIM_CI_Build_DefinitionName: $(Build.DefinitionName) + NIM_CI_Build_Repository_ID: $(Build.Repository.ID) + NIM_CI_Build_Repository_Name: $(Build.Repository.Name) + NIM_CI_Build_Repository_Provider: $(Build.Repository.Provider) + NIM_CI_Build_Repository_Uri: $(Build.Repository.Uri) + NIM_CI_Build_SourceBranch: $(Build.SourceBranch) + NIM_CI_Build_SourceBranchName: $(Build.SourceBranchName) + NIM_CI_Build_SourcesDirectory: $(Build.SourcesDirectory) + NIM_CI_Build_SourceVersion: $(Build.SourceVersion) + NIM_CI_Build_SourceVersionMessage: $(Build.SourceVersionMessage) + NIM_CI_Build_Reason: $(Build.Reason) diff --git a/koch.nim b/koch.nim index 75d5047586a22..72032bb196598 100644 --- a/koch.nim +++ b/koch.nim @@ -26,7 +26,9 @@ when defined(i386) and defined(windows) and defined(vcc): import os, strutils, parseopt, osproc -import tools / kochdocs +import tools/kochdocs +import tools/continuous_integration + # we could make this conditional on whether we're in CI const VersionAsString = system.NimVersion @@ -472,14 +474,12 @@ proc xtemp(cmd: string) = finally: copyExe(d / "bin" / "nim_backup".exe, d / "bin" / "nim".exe) -proc hostInfo(): string = - "hostOS: $1, hostCPU: $2, int: $3, float: $4, cpuEndian: $5, cwd: $6" % - [hostOS, hostCPU, $int.sizeof, $float.sizeof, $cpuEndian, getCurrentDir()] - proc runCI(cmd: string) = doAssert cmd.len == 0, cmd # avoid silently ignoring echo "runCI:", cmd echo hostInfo() + installNode() + # note(@araq): Do not replace these commands with direct calls (eg boot()) # as that would weaken our testing efforts. when defined(posix): # appveyor (on windows) didn't run this diff --git a/tools/continuous_integration.nim b/tools/continuous_integration.nim new file mode 100644 index 0000000000000..348d86d0edb72 --- /dev/null +++ b/tools/continuous_integration.nim @@ -0,0 +1,97 @@ +import os, osproc, strutils, strformat + +proc isAzureCI*(): bool = + getEnv("NIM_CI_Build_SourceBranchName").len > 0 + +import macros + +macro fun(ret: var string, body): untyped = + result = newStmtList() + for a in body: + let a2 = a.strVal + result.add quote do: + `ret`.add `a2` & ": " & getEnv(`a2`) & "\n" + +proc isPullRequest*(): bool = + ## returns true if CI build is triggered via a PR + ## else, it corresponds to a direct push to the repository by owners + assert isAzureCI() + getEnv("NIM_CI_Build_Reason") == "PullRequest" + +proc runCmd(cmd: string) = + echo "runCmd: " & cmd + let status = execShellCmd(cmd) + doAssert status == 0, $status + +proc tryRunCmd(cmd: string): bool = + echo "tryRunCmd: " & cmd + execShellCmd(cmd) == 0 + +proc installNode*() = + echo "installNode" + when defined(osx): + if not tryRunCmd "brew install node > /dev/null": + echo " ok to ignore this: Error: The `brew link` step did not complete successfully" + runCmd "brew link --overwrite node" + elif defined(linux): + # https://linuxize.com/post/how-to-install-node-js-on-ubuntu-18.04/ + runCmd "curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -" + runCmd "sudo apt install -yq nodejs" + runCmd "nodejs --version" + # node: v12.16.0 + # nodejs: v10.19.0 + + elif defined(windows): + # should've be installed via azure-pipelines.yml, but could do it here too + # via https://nodejs.org/en/download/ + discard + + runCmd "node --version" + +proc hostInfo*(): string = + echo "D20200301T212950.v5" + result = "hostOS: $1, hostCPU: $2, nproc: $3, int: $4, float: $5, cpuEndian: $6, cwd: $7" % + [hostOS, hostCPU, $countProcessors(), + $int.sizeof, $float.sizeof, $cpuEndian, getCurrentDir()] + if not isAzureCI(): return + let mode = if existsEnv("NIM_COMPILE_TO_CPP"): "cpp" else: "c" + + var url = getEnv("NIM_CI_Build_Repository_Uri") + let isPR = isPullRequest() + let commit = getEnv("NIM_CI_Build_SourceVersion") + if isPR: + url = "$1/pull/$2" % [url, getEnv("NIM_CI_PR_PullRequestNumber")] + else: + url = "$1/commit/$2" % [url, commit] + + let branch = getEnv("NIM_CI_Build_SourceBranchName") + let msg = getEnv("NIM_CI_Build_SourceVersionMessage").quoteShell + let attempt = getEnv("NIM_CI_JobAttempt") + let buildNum = getEnv("NIM_CI_Build_BuildNumber") + # getEnv("NIM_CI_TeamProject") + result.add """isPR:{isPR}, url: {url}, branch: {branch}, commit: {commit}, msg: {msg}, mode: {mode}, buildNum: {buildNum}""" + result.add "\n" + + fun(result): + NIM_CI_PR_SourceRepositoryURI + NIM_CI_PR_PullRequestNumber + NIM_CI_TeamProject + NIM_CI_JobAttempt + NIM_CI_Build_ArtifactStagingDirectory + NIM_CI_Build_BuildId + NIM_CI_Build_BuildNumber + NIM_CI_Build_BuildUri + NIM_CI_Build_BinariesDirectory + NIM_CI_Build_DefinitionName + NIM_CI_Build_Repository_ID + NIM_CI_Build_Repository_Name + NIM_CI_Build_Repository_Provider + NIM_CI_Build_Repository_Uri + NIM_CI_Build_SourceBranch + NIM_CI_Build_SourceBranchName + NIM_CI_Build_SourcesDirectory + NIM_CI_Build_SourceVersion + NIM_CI_Build_SourceVersionMessage + NIM_CI_Build_Reason + + result.add "\n"