github.com/ConsenSys/Quorum@v20.10.0+incompatible/.github/workflows/build.yml (about)

     1  name: Build Check
     2  on:
     3    push:
     4      paths-ignore:
     5        - 'docs/**'
     6        - '**.md'
     7        - 'mkdocs.yml'
     8        - '.gitignore'
     9      branches:
    10        - master
    11  env:
    12    GO_VERSION: 1.13
    13    GOPATH: ${{ github.workspace }}/go
    14    WORKING_DIR: ${{ github.workspace }}/go/src/github.com/ethereum/go-ethereum
    15  jobs:
    16    build:
    17      name: 'Run tests and build on ${{ matrix.os }}'
    18      strategy:
    19        fail-fast: false
    20        matrix:
    21          # Not enable for macos as there's a consistent failure:
    22          # --- FAIL: TestUPNP_DDWRT (2.20s)
    23          # ###[error]    natupnp_test.go:165: not discovered
    24          # must be sommething with Github Actions VM networking setup.
    25          # Event Ubuntu requires a workaround
    26          os: ["ubuntu-latest"]
    27      env:
    28        QUORUM_IGNORE_TEST_PACKAGES: github.com/ethereum/go-ethereum/les,github.com/ethereum/go-ethereum/les/flowcontrol,github.com/ethereum/go-ethereum/mobile
    29      runs-on: ${{ matrix.os }}
    30      steps:
    31        - name: 'Setup Go ${{ env.GO_VERSION }}'
    32          uses: actions/setup-go@v1
    33          with:
    34            go-version: ${{ env.GO_VERSION }}
    35        - name: 'Check out project files'
    36          uses: actions/checkout@574281d
    37          with:
    38            submodules: recursive
    39            path: ${{ env.WORKING_DIR }}
    40        - name: 'Apply workaround to fix networking in Linux'
    41          if: runner.os == 'Linux'
    42          run: |
    43            # https://github.com/actions/virtual-environments/issues/798
    44            sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
    45        - name: 'Prepare environment'
    46          run: |
    47            echo "::add-path::$(go env GOPATH)/bin"
    48        - name: 'Run tests and build all'
    49          working-directory: ${{ env.WORKING_DIR }}
    50          run: |
    51            make test all
    52    publish-docker:
    53      name: Publish Docker Image
    54      needs:
    55        - build
    56      runs-on: ubuntu-latest
    57      steps:
    58        - name: 'Checkout'
    59          uses: actions/checkout@v2
    60        - name: 'Build and publish to Docker Hub'
    61          uses: docker/build-push-action@v1
    62          with:
    63            username: ${{ secrets.DOCKER_USERNAME }}
    64            password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
    65            repository: ${{ secrets.DOCKER_REPO }}
    66            tag_with_ref: true
    67            add_git_labels: true
    68    notify:
    69      if: always()
    70      name: Notify
    71      needs:
    72        - build
    73        - publish-docker
    74      runs-on: ubuntu-latest
    75      steps:
    76        - name: 'Setup metadata'
    77          id: setup
    78          run: |
    79            gitref_path="${{ github.ref }}"
    80            gitref_path=${gitref_path/refs\/heads/tree} # for refs/heads/my-branch
    81            gitref_path=${gitref_path/refs\/tags/tree}  # for refs/tags/v1.0.0
    82            gitref_path=${gitref_path#refs\/}           # for refs/pull/123/merge
    83            gitref_path=${gitref_path%/merge}           # for refs/pull/123/merge
    84            echo "::set-output name=gitref-path::$gitref_path"
    85        - name: 'Prepare Slack message with full info'
    86          id: status
    87          uses: actions/github-script@0.8.0
    88          with:
    89            script: |
    90              var gitref_path = "${{ steps.setup.outputs.gitref-path }}"
    91              ////////////////////////////////////
    92              // retrieve workflow run data
    93              ////////////////////////////////////
    94              console.log("get workflow run")
    95              const wf_run = await github.actions.getWorkflowRun({
    96                  owner: context.repo.owner,
    97                  repo: context.repo.repo,
    98                  run_id: ${{ github.run_id }}
    99              })
   100              console.log(wf_run.data)
   101              console.log("get jobs for workflow run:", wf_run.data.jobs_url)
   102              const jobs_response = await github.request(wf_run.data.jobs_url)
   103              ////////////////////////////////////
   104              // build slack notification message
   105              ////////////////////////////////////
   106              // some utility functions
   107              var date_diff_func = function(start, end) {
   108                  var duration = end - start
   109                  // format the duration
   110                  var delta = duration / 1000
   111                  var days = Math.floor(delta / 86400)
   112                  delta -= days * 86400
   113                  var hours = Math.floor(delta / 3600) % 24
   114                  delta -= hours * 3600
   115                  var minutes = Math.floor(delta / 60) % 60
   116                  delta -= minutes * 60
   117                  var seconds = Math.floor(delta % 60)
   118                  var format_func = function(v, text, check) {
   119                      if (v <= 0 && check) {
   120                          return ""
   121                      } else {
   122                          return v + text
   123                      }
   124                  }
   125                  return format_func(days, "d", true) + format_func(hours, "h", true) + format_func(minutes, "m", true) + format_func(seconds, "s", false)
   126              }
   127              var status_icon_func = function(s) {
   128                  switch (s) {
   129                  case "w_success":
   130                      return ":white_check_mark:"
   131                  case "w_failure":
   132                      return ":no_entry:"
   133                  case "w_cancelled":
   134                      return ":warning:"
   135                  case "success":
   136                      return "\u2713"
   137                  case "failure":
   138                      return "\u2717"
   139                  default:
   140                      return "\u20e0"
   141                  }
   142              }
   143              // build the message
   144              var job_blocks = []
   145              var is_wf_success = true
   146              var is_wf_failure = false
   147              for (j of jobs_response.data.jobs) {
   148                  console.log(j.name, ":", j.status, j.conclusion, j.started_at, j.completed_at)
   149                  // ignore the current job running this script
   150                  if (j.status != "completed") {
   151                      continue
   152                  }
   153                  if (j.conclusion != "success") {
   154                    is_wf_success = false
   155                  }
   156                  if (j.conclusion == "failure") {
   157                    is_wf_failure = true
   158                  }
   159                  job_blocks.push({
   160                      type: "section",
   161                      text: {
   162                        type: "mrkdwn",
   163                        text: `${status_icon_func(j.conclusion)} <${j.html_url}|${j.name}> took ${date_diff_func(new Date(j.started_at), new Date(j.completed_at))}`
   164                      }
   165                  })
   166              }
   167              var workflow_status = "w_cancelled"
   168              if (is_wf_success) {
   169                workflow_status = "w_success"
   170              } else if (is_wf_failure) {
   171                workflow_status = "w_failure"
   172              }
   173              var context_elements = [
   174                {
   175                    "type": "mrkdwn",
   176                    "text": "*Repo:* <https://github.com/${{ github.repository }}|${{ github.repository }}>"
   177                },
   178                {
   179                    "type": "mrkdwn",
   180                    "text": `*Branch:* <https://github.com/${{ github.repository }}/${gitref_path}|${{ github.ref }}>`
   181                },
   182                {
   183                    "type": "mrkdwn",
   184                    "text": `*Event:* ${wf_run.data.event}`
   185                },
   186                {
   187                    "type": "mrkdwn",
   188                    "text": `*Commit:* <https://github.com/${{ github.repository }}/commit/${wf_run.data.head_commit.id}|${wf_run.data.head_commit.id.substr(0, 8)}>`
   189                },
   190                {
   191                    "type": "mrkdwn",
   192                    "text": `*Author:* ${wf_run.data.head_commit.author.name}`
   193                }
   194              ]
   195              var header_blocks = [
   196                  {
   197                      type: "section",
   198                      text: {
   199                          type: "mrkdwn",
   200                          text: `${status_icon_func(workflow_status)} *${{ github.workflow }}* <${wf_run.data.html_url}|#${{ github.run_number }}> took ${date_diff_func(new Date(wf_run.data.created_at), new Date(wf_run.data.updated_at))}`
   201                      }
   202                  },
   203                  {
   204                      type: "context",
   205                      elements: context_elements,
   206                  },
   207                  {
   208                      type: "divider"
   209                  }
   210              ]
   211              var slack_msg = {
   212                  blocks: [].concat(header_blocks, job_blocks)
   213              }
   214              return slack_msg
   215        - name: 'Prepare Slack message with partial info'
   216          id: short_status
   217          if: failure()
   218          uses: actions/github-script@0.8.0
   219          with:
   220            script: |
   221              ////////////////////////////////////
   222              // retrieve workflow run data
   223              ////////////////////////////////////
   224              const wf_run = await github.actions.getWorkflowRun({
   225                  owner: context.repo.owner,
   226                  repo: context.repo.repo,
   227                  run_id: ${{ github.run_id }}
   228              })
   229              var date_diff_func = function(start, end) {
   230                  var duration = end - start
   231                  // format the duration
   232                  var delta = duration / 1000
   233                  var days = Math.floor(delta / 86400)
   234                  delta -= days * 86400
   235                  var hours = Math.floor(delta / 3600) % 24
   236                  delta -= hours * 3600
   237                  var minutes = Math.floor(delta / 60) % 60
   238                  delta -= minutes * 60
   239                  var seconds = Math.floor(delta % 60)
   240                  var format_func = function(v, text, check) {
   241                      if (v <= 0 && check) {
   242                          return ""
   243                      } else {
   244                          return v + text
   245                      }
   246                  }
   247                  return format_func(days, "d", true) + format_func(hours, "h", true) + format_func(minutes, "m", true) + format_func(seconds, "s", false)
   248              }
   249              var slack_msg = {
   250                  blocks: [
   251                    {
   252                        type: "section",
   253                        text: {
   254                            type: "mrkdwn",
   255                            text: `:skull_and_crossbones: *${{ github.workflow }}* <${wf_run.data.html_url}|#${{ github.run_number }}> (took ${date_diff_func(new Date(wf_run.data.created_at), new Date(wf_run.data.updated_at))})`
   256                        }
   257                    }
   258                  ]
   259              }
   260              return slack_msg
   261        - name: 'Send to Slack'
   262          if: always()
   263          run: |
   264            cat <<JSON > long_message.json
   265            ${{ steps.status.outputs.result }}
   266            JSON
   267            cat <<JSON > short_message.json
   268            ${{ steps.short_status.outputs.result }}
   269            JSON
   270            _post() {
   271              curl -X POST ${{ secrets.SLACK_WEBHOOK_URL }} -H "Content-type: application/json" --data "@${1}"
   272            }
   273            _post "long_message.json" || _post "short_message.json"