From 84fca2a5ad89f578a86ead6266a76abcd9f2f8e5 Mon Sep 17 00:00:00 2001 From: patrickhuie19 Date: Tue, 12 Dec 2023 09:18:47 -0500 Subject: [PATCH] updating CI workflows --- .github/workflows/ci.yml | 88 +------------------------------- .github/workflows/lint.yml | 33 ++++++++++++ .github/workflows/sonar-scan.yml | 75 +++++++++++++++++++++++++++ sonar-project.properties | 2 +- 4 files changed, 111 insertions(+), 87 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/sonar-scan.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8d2ee8d..7e8804d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,63 +4,12 @@ on: push: jobs: - lint: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version-file: 'go.mod' - - ## - # XXX: change this to the official action once multiple --out-format args are supported. - # See: https://github.com/golangci/golangci-lint-action/issues/612 - ## - - name: golangci-lint - uses: smartcontractkit/golangci-lint-action@54ab6c5f11d66a92d14c3f7cc41ea13f676644bd # feature/multiple-output-formats-backup - with: - # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: v1.52.1 - - # Optional: working directory, useful for monorepos - # working-directory: - - # Optional: golangci-lint command line arguments. - allow-extra-out-format-args: true - args: --timeout=2m0s --out-format checkstyle:golangci-lint-report.xml - - # Optional: show only new issues if it's a pull request. The default value is `false`. - only-new-issues: true - - # Optional: if set to true then the action will use pre-installed Go. - # skip-go-installation: true - - # Optional: if set to true then the action don't cache or restore ~/go/pkg. - # skip-pkg-cache: true - - # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. - # skip-build-cache: true - - - name: Print lint report artifact - if: always() - run: test -f golangci-lint-report.xml && cat golangci-lint-report.xml || true - - - name: Upload lint report artifact - if: always() - uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0 - with: - name: golangci-lint-report - path: golangci-lint-report.xml - ci_test: name: CI Tests runs-on: ubuntu-latest steps: - name: Checkout the repo - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup Go uses: actions/setup-go@v3 @@ -69,7 +18,7 @@ jobs: cache: true - name: Cache dependencies - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: | ~/.cache/go-build @@ -93,36 +42,3 @@ jobs: ./output.txt ./coverage.txt ./race_coverage.txt - - sonar-scan: - name: SonarQube - needs: [lint, ci_test] - runs-on: ubuntu-latest - if: always() - steps: - - name: Checkout the repo - uses: actions/checkout@v3 - with: - fetch-depth: 0 # fetches all history for all tags and branches to provide more metadata for sonar reports - - - name: Download all workflow run artifacts - uses: actions/download-artifact@9782bd6a9848b53b110e712e20e42d89988822b7 # v3.0.1 - - - name: Set SonarQube Report Paths - id: sonarqube_report_paths - shell: bash - run: | - echo "sonarqube_tests_report_paths=$(find -type f -name 'output.txt' -printf "%p,")" >> $GITHUB_OUTPUT - echo "sonarqube_coverage_report_paths=$(find -type f -name '*coverage.txt' -printf "%p,")" >> $GITHUB_OUTPUT - echo "sonarqube_golangci_report_paths=$(find -type f -name 'golangci-lint-report.xml' -printf "%p,")" >> $GITHUB_OUTPUT - - - name: SonarQube Scan - uses: sonarsource/sonarqube-scan-action@a6ba0aafc293e03de5437af7edbc97f7d3ebc91a # v1.2.0 - with: - args: > - -Dsonar.go.tests.reportPaths=${{ steps.sonarqube_report_paths.outputs.sonarqube_tests_report_paths }} - -Dsonar.go.coverage.reportPaths=${{ steps.sonarqube_report_paths.outputs.sonarqube_coverage_report_paths }} - -Dsonar.go.golangci-lint.reportPaths=${{ steps.sonarqube_report_paths.outputs.sonarqube_golangci_report_paths }} - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..adf7ac4 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,33 @@ +name: Golangci-lint + +on: [push] + +jobs: + golangci-lint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.21' + + - name: Install golangci-lint + run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2 + + # go.work makes it necessary to run linter manually + - name: Run golangci-lint + run: find . -name "go.mod" -execdir $(go env GOPATH)/bin/golangci-lint run --enable=gofmt --tests=false --exclude-use-default --timeout=5m0s --out-format checkstyle:golangci-lint-report.xml \; + + - name: Print artifact + run: cat golangci-lint-report.xml + + - name: Upload golangci-lint report + if: always() + uses: actions/upload-artifact@v3 + with: + name: golangci-lint-report + path: | + ./golangci-lint-report.xml \ No newline at end of file diff --git a/.github/workflows/sonar-scan.yml b/.github/workflows/sonar-scan.yml new file mode 100644 index 0000000..50b0618 --- /dev/null +++ b/.github/workflows/sonar-scan.yml @@ -0,0 +1,75 @@ +name: SonarQube Scan + +on: [push] + +jobs: + wait_for_workflows: + name: Wait for workflows + runs-on: ubuntu-latest + if: always() + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha || github.event.merge_group.head_sha }} + + - name: Wait for workflows + uses: smartcontractkit/chainlink-github-actions/utils/wait-for-workflows@main + with: + max-timeout: "900" + polling-interval: "30" + exclude-workflow-names: "" + exclude-workflow-ids: "" + github-token: ${{ secrets.GITHUB_TOKEN }} + env: + DEBUG: "true" + + sonarqube: + name: SonarQube Scan + needs: [wait_for_workflows] + runs-on: ubuntu-latest + if: always() + steps: + - name: Checkout the repo + uses: actions/checkout@v3 + with: + fetch-depth: 0 # fetches all history for all tags and branches to provide more metadata for sonar reports + + - name: Download Golangci-lint report + if: always() + uses: dawidd6/action-download-artifact@v2.27.0 + with: + workflow: golangci_lint.yml + workflow_conclusion: "" + name_is_regexp: true + name: golangci-lint-report + if_no_artifact_found: warn + + - name: Download Go PKG test reports + if: always() + uses: dawidd6/action-download-artifact@v2.27.0 + with: + workflow: pkg.yml + workflow_conclusion: "" + name_is_regexp: true + name: go-test-results + if_no_artifact_found: warn + + - name: Set SonarQube Report Paths + if: always() + id: sonarqube_report_paths + shell: bash + run: | + echo "sonarqube_coverage_report_paths=$(find -type f -name '*coverage.out' -printf "%p,")" >> $GITHUB_OUTPUT + echo "sonarqube_golangci_report_paths=$(find -type f -name 'golangci-lint-report.xml' -printf "%p,")" >> $GITHUB_OUTPUT + + - name: SonarQube Scan + if: always() + uses: sonarsource/sonarqube-scan-action@a6ba0aafc293e03de5437af7edbc97f7d3ebc91a # v1.2.0 + with: + args: > + -Dsonar.go.coverage.reportPaths=${{ steps.sonarqube_report_paths.outputs.sonarqube_coverage_report_paths }} + -Dsonar.go.golangci-lint.reportPaths=${{ steps.sonarqube_report_paths.outputs.sonarqube_golangci_report_paths }} + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} \ No newline at end of file diff --git a/sonar-project.properties b/sonar-project.properties index ff2d4bc..ff2b9d5 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -3,7 +3,7 @@ sonar.projectKey=smartcontractkit_wsrpc sonar.sources=. # Full exclusions from the static analysis -sonar.exclusions=**/protoc-gen-go-wsrpc/protoc-gen-go-wsrpc, **/mocks/**/*, **/testdata/**/*, **/script/**/*, **/generated/**/*, **/fixtures/**/*, **/docs/**/*, **/tools/**/*, **/*.pb.go, **/*report.xml, **/*.txt, **/*.abi, **/*.bin +sonar.exclusions=**/protoc-gen-go-wsrpc/protoc-gen-go-wsrpc, **/mocks/**/*, **/testdata/**/*, **/script/**/*, **/generated/**/*, **/fixtures/**/*, **/docs/**/*, **/tools/**/*, **/*.pb.go, **/*report.xml, **/*.txt, **/*.abi, **/*.bin, **/*.yml # Coverage exclusions sonar.coverage.exclusions=**/*_test.go, **/utils/**/*, **/examples/**/*, **/intgtest/**/*