Skip to content

Commit

Permalink
fix nim-lang#13477 (flaky nodejs install); faster CI; CI logs now sho…
Browse files Browse the repository at this point in the history
…w PR url + other info
  • Loading branch information
timotheecour committed Mar 2, 2020
1 parent 22d1ba4 commit d68f900
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 9 deletions.
44 changes: 41 additions & 3 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -152,4 +162,32 @@ 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)
# Build.Reason
# PullRequest: The build was triggered by a Git branch policy that requires a build.
10 changes: 5 additions & 5 deletions koch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion testament/important_packages.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pkg "ast_pattern_matching", "nim c -r --oldgensym:on tests/test1.nim"
pkg "asyncmysql", "", true
pkg "bigints"
pkg "binaryheap", "nim c -r binaryheap.nim"
pkg "blscurve", "", true
# pkg "blscurve", "", true # pending https://github.com/status-im/nim-blscurve/issues/39
pkg "bncurve", "", true
pkg "c2nim", "nim c testsuite/tester.nim"
pkg "cascade"
Expand Down
99 changes: 99 additions & 0 deletions tools/continuous_integration.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
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 from a PR (contributors sending a PR)
## else, it corresponds to a direct push to the repository
assert isAzureCI()
# azure will expand System.PullRequest.PullRequestNumber to a PR number or
# keep it as following expression depending on whether build came from a PR.
getEnv("NIM_CI_PR_PullRequestNumber") != "$(System.PullRequest.PullRequestNumber)"

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"

0 comments on commit d68f900

Please sign in to comment.