From 645a6f38bfb9dada7ea6da1ce819d254bcda7a65 Mon Sep 17 00:00:00 2001 From: HenryNguyen5 <6404866+HenryNguyen5@users.noreply.github.com> Date: Tue, 12 Sep 2023 14:21:22 -0400 Subject: [PATCH] Fix golangci-lint (#10555) * Cleanup linter * Remove unused github actions related bash scripts * Remove irrelevant branch filters * Run linter only on PRs and scheduled runs --- .github/scripts/bash/.shellspec | 12 -- .github/scripts/bash/README.md | 10 -- .github/scripts/bash/ontriggerlint.sh | 41 ------- .../scripts/bash/spec/ontriggerlint_spec.sh | 106 ------------------ .github/scripts/bash/spec/spec_helper.sh | 24 ---- .github/workflows/bash-cicd-scripts.yml | 61 ---------- .github/workflows/ci-core.yml | 82 +++----------- .github/workflows/codeql-analysis.yml | 3 - .tool-versions | 1 - 9 files changed, 17 insertions(+), 323 deletions(-) delete mode 100644 .github/scripts/bash/.shellspec delete mode 100644 .github/scripts/bash/README.md delete mode 100755 .github/scripts/bash/ontriggerlint.sh delete mode 100644 .github/scripts/bash/spec/ontriggerlint_spec.sh delete mode 100644 .github/scripts/bash/spec/spec_helper.sh delete mode 100644 .github/workflows/bash-cicd-scripts.yml diff --git a/.github/scripts/bash/.shellspec b/.github/scripts/bash/.shellspec deleted file mode 100644 index d567ecf976a..00000000000 --- a/.github/scripts/bash/.shellspec +++ /dev/null @@ -1,12 +0,0 @@ ---require spec_helper - -## Default kcov (coverage) options -# --kcov-options "--include-path=. --path-strip-level=1" -# --kcov-options "--include-pattern=.sh" -# --kcov-options "--exclude-pattern=/.shellspec,/spec/,/coverage/,/report/" - -## Example: Include script "myprog" with no extension -# --kcov-options "--include-pattern=.sh,myprog" - -## Example: Only specified files/directories -# --kcov-options "--include-pattern=myprog,/lib/" diff --git a/.github/scripts/bash/README.md b/.github/scripts/bash/README.md deleted file mode 100644 index ed23cd863b7..00000000000 --- a/.github/scripts/bash/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# bash scripts - -These are bash helper scripts for the CI/CD pipelines. - -## Testing - -For each bash script, create a corresponding *_spec.sh file in the `./spec/` directory. - -1. [Install ShellSpec](https://github.com/shellspec/shellspec#installation) using ASDF (see the .tool-versions file at the root of repo for version). -2. From this directory run `shellspec` \ No newline at end of file diff --git a/.github/scripts/bash/ontriggerlint.sh b/.github/scripts/bash/ontriggerlint.sh deleted file mode 100755 index a38a5e2a203..00000000000 --- a/.github/scripts/bash/ontriggerlint.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -## -# Execute tests via: ./ontriggerlint_test.sh -# -# For the GitHub contexts that should be passed in as args, see: -# https://docs.github.com/en/actions/learn-github-actions/contexts -# -# Trigger golangci-lint job steps when event is one of: -# 1. on a schedule (GITHUB_EVENT_NAME) -# 2. on PR's where the target branch (GITHUB_BASE_REF) is not prefixed with 'release/*' -# and where the relevant source code (SRC_CHANGED) has changed -# 3. on pushes to these branches (GITHUB_REF): staging, trying, rollup and where the -# relevant source code (SRC_CHANGED) has changed -# -# env vars: -# GITHUB_EVENT_NAME GitHub's event name, ex: schedule|pull_request|push (GitHub context: github.event_name) -# GITHUB_BASE_REF GitHub's base ref - target branch of pull request (GitHub context: github.base_ref) -# GITHUB_REF GitHub's ref - branch or tag that triggered run (GitHub context: github.ref) -# SRC_CHANGED Specific source paths that we want to trigger on were modified. One of: true|false -## - -if [[ -z "${GITHUB_REF:-}" ]]; then GITHUB_REF=""; fi - -# Strip out /refs/heads/ from GITHUB_REF leaving just the abbreviated name -ABBREV_GITHUB_REF="${GITHUB_REF#refs\/heads\/}" - -ON_TRIGGER=false -if [[ "${GITHUB_EVENT_NAME:-}" = "schedule" ]]; then - # Trigger on scheduled runs - ON_TRIGGER=true -elif [[ "${SRC_CHANGED:-}" = "true" && "${GITHUB_EVENT_NAME:-}" = "pull_request" && "${GITHUB_BASE_REF:-}" != release/* ]]; then - # Trigger if it's from a pull request targetting any branch EXCEPT the release branch - ON_TRIGGER=true -elif [[ "${SRC_CHANGED:-}" = "true" && "${GITHUB_EVENT_NAME:-}" = "push" && "${ABBREV_GITHUB_REF}" =~ ^(staging|trying|rollup)$ ]]; then - # Trigger if it's a push to specific branches - ON_TRIGGER=true -fi - -echo "on_trigger=${ON_TRIGGER}" diff --git a/.github/scripts/bash/spec/ontriggerlint_spec.sh b/.github/scripts/bash/spec/ontriggerlint_spec.sh deleted file mode 100644 index 212de847cac..00000000000 --- a/.github/scripts/bash/spec/ontriggerlint_spec.sh +++ /dev/null @@ -1,106 +0,0 @@ -# shellcheck shell=sh - -Describe 'Scheduled' - It 'Trigger on schedule when source changed' - export SRC_CHANGED=true - export GITHUB_EVENT_NAME=schedule - When run ./ontriggerlint.sh - The status should eq 0 - The stdout should equal 'on_trigger=true' - End - - It 'Trigger on schedule when source unchanged' - export SRC_CHANGED=false - export GITHUB_EVENT_NAME=schedule - When run ./ontriggerlint.sh - The status should eq 0 - The stdout should equal 'on_trigger=true' - End -End - - -Describe 'Pull Request' - It 'Trigger on pull_request for non release branches when source changed' - export SRC_CHANGED=true - export GITHUB_EVENT_NAME=pull_request - export GITHUB_BASE_REF=develop - When run ./ontriggerlint.sh - The status should eq 0 - The stdout should equal 'on_trigger=true' - End - - It 'No trigger on pull_request for non release branches when source unchanged' - export SRC_CHANGED=false - export GITHUB_EVENT_NAME=pull_request - export GITHUB_BASE_REF=develop - When run ./ontriggerlint.sh - The status should eq 0 - The stdout should equal 'on_trigger=false' - End - - It 'No trigger on pull_request for release branches when source changed' - export SRC_CHANGED=true - export GITHUB_EVENT_NAME=pull_request - export GITHUB_BASE_REF=release/1.2.3 - When run ./ontriggerlint.sh - The status should eq 0 - The stdout should equal 'on_trigger=false' - End -End - -Describe 'Push' - It 'Trigger on push to the staging branch when source changed' - export SRC_CHANGED=true - export GITHUB_EVENT_NAME=push - export GITHUB_REF=staging - When run ./ontriggerlint.sh - The status should eq 0 - The stdout should equal 'on_trigger=true' - End - - It 'No trigger on push to the staging branch when source unchanged' - export SRC_CHANGED=false - export GITHUB_EVENT_NAME=push - export GITHUB_REF=staging - When run ./ontriggerlint.sh - The status should eq 0 - The stdout should equal 'on_trigger=false' - End - - It 'Trigger on push to the trying branch when source changed' - export SRC_CHANGED=true - export GITHUB_EVENT_NAME=push - export GITHUB_REF=trying - When run ./ontriggerlint.sh - The status should eq 0 - The stdout should equal 'on_trigger=true' - End - - It 'Trigger on push to the rollup branch when source changed' - export SRC_CHANGED=true - export GITHUB_EVENT_NAME=push - export GITHUB_REF=rollup - When run ./ontriggerlint.sh - The status should eq 0 - The stdout should equal 'on_trigger=true' - End - - It 'No trigger on push to the develop branch when source changed' - export SRC_CHANGED=true - export GITHUB_EVENT_NAME=push - export GITHUB_REF=develop - When run ./ontriggerlint.sh - The status should eq 0 - The stdout should equal 'on_trigger=false' - End -End - -Describe 'Misc' - It 'No trigger on invalid event name when source changed' - export SRC_CHANGED=true - export GITHUB_EVENT_NAME=invalid_event_name - When run ./ontriggerlint.sh - The status should eq 0 - The stdout should equal 'on_trigger=false' - End -End diff --git a/.github/scripts/bash/spec/spec_helper.sh b/.github/scripts/bash/spec/spec_helper.sh deleted file mode 100644 index 93f19083cd2..00000000000 --- a/.github/scripts/bash/spec/spec_helper.sh +++ /dev/null @@ -1,24 +0,0 @@ -# shellcheck shell=sh - -# Defining variables and functions here will affect all specfiles. -# Change shell options inside a function may cause different behavior, -# so it is better to set them here. -# set -eu - -# This callback function will be invoked only once before loading specfiles. -spec_helper_precheck() { - # Available functions: info, warn, error, abort, setenv, unsetenv - # Available variables: VERSION, SHELL_TYPE, SHELL_VERSION - : minimum_version "0.28.1" -} - -# This callback function will be invoked after a specfile has been loaded. -spec_helper_loaded() { - : -} - -# This callback function will be invoked after core modules has been loaded. -spec_helper_configure() { - # Available functions: import, before_each, after_each, before_all, after_all - : import 'support/custom_matcher' -} diff --git a/.github/workflows/bash-cicd-scripts.yml b/.github/workflows/bash-cicd-scripts.yml deleted file mode 100644 index 21a884a4384..00000000000 --- a/.github/workflows/bash-cicd-scripts.yml +++ /dev/null @@ -1,61 +0,0 @@ -name: Bash CICD Scripts - -on: - pull_request: - -jobs: - changes: - name: detect changes - runs-on: ubuntu-latest - outputs: - bash-cicd-scripts-src: ${{ steps.bash-cicd-scripts.outputs.src }} - steps: - - name: Checkout the repo - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 - - uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1 - id: bash-cicd-scripts - with: - filters: | - src: - - '.github/scripts/bash/**' - - '.github/workflows/bash-cicd-scripts.yml' - shellcheck: - name: ShellCheck Lint - runs-on: ubuntu-latest - needs: [changes] - steps: - - name: Checkout the repo - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 - - name: Run ShellCheck - if: needs.changes.outputs.bash-cicd-scripts-src == 'true' - uses: ludeeus/action-shellcheck@00cae500b08a931fb5698e11e79bfbd38e612a38 # v2.0.0 - with: - scandir: './.github/scripts/bash' - shellspec: - name: ShellSpec Tests - runs-on: ubuntu-latest - needs: [changes] - defaults: - run: - shell: bash - steps: - - name: Checkout the repo - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 - - name: Install shellspec - if: needs.changes.outputs.bash-cicd-scripts-src == 'true' - env: - VERSION: 0.28.1 - VERSION_SHA256SUM: 350d3de04ba61505c54eda31a3c2ee912700f1758b1a80a284bc08fd8b6c5992 - GZ_TAR_FILE: shellspec-dist.tar.gz - run: | - curl -sSfL "https://github.com/shellspec/shellspec/releases/download/${VERSION}/shellspec-dist.tar.gz" \ - --output "${GZ_TAR_FILE}" - echo "Checking sha256sum of ShellSpec released archive." - echo "${VERSION_SHA256SUM} ${GZ_TAR_FILE}" | sha256sum --check - tar -xzf "${GZ_TAR_FILE}" -C "${HOME}/.local" - ln -s "${HOME}/.local/shellspec/shellspec" /usr/local/bin/shellspec - shellspec --version - - name: Run shellspec tests - if: needs.changes.outputs.bash-cicd-scripts-src == 'true' - working-directory: ./.github/scripts/bash - run: shellspec diff --git a/.github/workflows/ci-core.yml b/.github/workflows/ci-core.yml index db867f70c4d..b346cb9f4c3 100644 --- a/.github/workflows/ci-core.yml +++ b/.github/workflows/ci-core.yml @@ -10,82 +10,35 @@ on: branches: - master - develop - - 'release/*' - - staging - - trying - - rollup + - "release/*" merge_group: pull_request: schedule: - cron: "0 0 * * *" jobs: - golangci-changes: - name: detect changes for lint - runs-on: ubuntu-latest - outputs: - src: ${{ steps.golangci-changes.outputs.src }} - steps: - - name: Checkout the repo - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 - - uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1 - id: golangci-changes - with: - filters: | - src: - - '**/*.go' - - '**/go.mod' - - '**/go.sum' - - '.golangci.yml' - - '.github/workflows/ci-core.yml' - init: - name: initialize - runs-on: ubuntu-latest - needs: [golangci-changes] - defaults: - run: - shell: bash - outputs: - # Determine if `on` event should trigger linting to run - on_trigger_lint: ${{ steps.golangci-lint.outputs.on_trigger }} - steps: - - name: Checkout the repo - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 - - name: Check if event should trigger lint - id: golangci-lint - env: - GITHUB_EVENT_NAME: ${{ github.event_name }} - GITHUB_BASE_REF: ${{ github.base_ref }} - GITHUB_REF: ${{ github.ref }} - SRC_CHANGED: ${{ needs.golangci-changes.outputs.src }} - run: ./.github/scripts/bash/ontriggerlint.sh | tee -a $GITHUB_OUTPUT - golangci: + if: ${{ github.event_name == 'pull_request' || github.event_name == 'schedule' }} name: lint - runs-on: ubuntu-latest - needs: [init] + runs-on: ubuntu20.04-8cores-32GB steps: - - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 - with: - fetch-depth: 0 - - uses: actions/setup-go@v4 - if: needs.init.outputs.on_trigger_lint == 'true' - with: - go-version-file: 'go.mod' - # If cache is set to true (default), the "prepare environment" will - # silently fail with these errors: - # Error: /usr/bin/tar: <...>: Cannot open: File exists - cache: false + - uses: actions/checkout@v4 + - name: Setup Go + uses: ./.github/actions/setup-go + - name: Touching core/web/assets/index.html + run: mkdir -p core/web/assets && touch core/web/assets/index.html + - name: Build binary + run: go build ./... - name: golangci-lint - if: needs.init.outputs.on_trigger_lint == 'true' uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0 with: version: v1.54.2 - only-new-issues: ${{ github.event.schedule == '' }} # show only new issues, unless it's a scheduled run - args: --out-format checkstyle:golangci-lint-report.xml - - name: Print lint report artifact - if: always() - run: test -f golangci-lint-report.xml && cat golangci-lint-report.xml || true + # We already cache these directories in setup-go + skip-pkg-cache: true + skip-build-cache: true + # only-new-issues is only applicable to PRs, otherwise it is always set to false + only-new-issues: true + args: --out-format colored-line-number,checkstyle:golangci-lint-report.xml - name: Store lint report artifact if: always() uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0 @@ -94,7 +47,6 @@ jobs: path: golangci-lint-report.xml - name: Collect Metrics if: always() - id: collect-gha-metrics uses: smartcontractkit/push-gha-metrics-action@d2c2b7bdc9012651230b2608a1bcb0c48538b6ec with: basic-auth: ${{ secrets.GRAFANA_CLOUD_BASIC_AUTH }} @@ -231,7 +183,7 @@ jobs: env: SLACK_BOT_TOKEN: ${{ secrets.QA_SLACK_API_KEY }} with: - channel-id: '#topic-data-races' + channel-id: "#topic-data-races" slack-message: "Race tests failed: ${{ job.html_url }}\n${{ format('https://github.com/smartcontractkit/chainlink/actions/runs/{0}', github.run_id) }}" - name: Collect Metrics if: always() diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 8d1fe137f67..58b38015a63 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -4,9 +4,6 @@ on: push: branches: - develop - - staging - - trying - - rollup pull_request: # The branches below must be a subset of the branches above branches: [develop] diff --git a/.tool-versions b/.tool-versions index f7934265340..1916a350289 100644 --- a/.tool-versions +++ b/.tool-versions @@ -5,4 +5,3 @@ postgres 13.3 helm 3.10.3 zig 0.10.1 golangci-lint 1.54.2 -shellspec 0.28.1