diff --git a/.github/actions/ci-golang-lint/action.yml b/.github/actions/ci-golang-lint/action.yml new file mode 100644 index 00000000000..95913fdf462 --- /dev/null +++ b/.github/actions/ci-golang-lint/action.yml @@ -0,0 +1,74 @@ +name: CI lint for Golang +description: Runs CI lint for Golang +inputs: + # general inputs + name: + description: Name of the lint action + default: lint + working-directory: + description: Directory to run commands from + default: "." + # setup-go inputs + only-modules: + description: Set to 'true' to only cache modules + default: "false" + cache-version: + description: Set this to cache bust + default: "1" + go-version-file: + description: Set where the go version file is located at + default: "go.mod" + go-module-file: + description: Set where the go module file is located at + default: "go.sum" + # grafana cloud inputs + gc-host: + description: "grafana cloud hostname" + gc-basic-auth: + description: "grafana cloud basic auth" + +runs: + using: composite + steps: + - uses: actions/checkout@v4 + - name: Setup Go + uses: ./.github/actions/setup-go + with: + working-directory: ${{ inputs.working-directory }} + only-modules: ${{ inputs.only-modules }} + cache-version: ${{ inputs.cache-version }} + go-version-file: ${{ inputs.go-version-file }} + go-module-file: ${{ inputs.go-module-file }} + - name: Touching core/web/assets/index.html + run: mkdir -p core/web/assets && touch core/web/assets/index.html + - name: Build binary + if: ${{ inputs.working-directory == '.' }} + run: go build ./... + - name: Build binary + if: ${{ inputs.working-directory != '.' }} + working-directory: ${{ inputs.working-directory }} + run: go build + - name: golangci-lint + uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0 + with: + version: v1.54.2 + # 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 + with: + name: golangci-lint-report + path: ${{ inputs.working-directory }}/golangci-lint-report.xml + - name: Collect Metrics + if: always() + uses: smartcontractkit/push-gha-metrics-action@d2c2b7bdc9012651230b2608a1bcb0c48538b6ec + with: + basic-auth: ${{ inputs.gc-basic-auth }} + hostname: ${{ inputs.gc-host }} + this-job-name: ${{ inputs.name }} + continue-on-error: true diff --git a/.github/actions/setup-go/action.yml b/.github/actions/setup-go/action.yml index 996fb4ac507..d14eaaec6b9 100644 --- a/.github/actions/setup-go/action.yml +++ b/.github/actions/setup-go/action.yml @@ -1,53 +1,67 @@ name: Setup Go -description: Setup Golang with efficient caching +description: Setup Golang with efficient caching inputs: only-modules: description: Set to 'true' to only cache modules - default: 'false' + default: "false" cache-version: description: Set this to cache bust default: "1" + working-directory: + description: Set the working directory to run commands from + default: "." + go-version-file: + description: Set where the go version file is located at + default: "go.mod" + go-module-file: + description: Set where the go module file is located at + default: "go.sum" runs: using: composite steps: - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version-file: "go.mod" - cache: false + - name: Set up Go + uses: actions/setup-go@v4 + with: + working-directory: ${{ inputs.working-directory }} + go-version-file: ${{ inputs.go-version-file }} + cache: false - - name: Get branch name - if: ${{ inputs.only-modules == 'false' }} - id: branch-name - uses: tj-actions/branch-names@2e5354c6733793113f416314375826df030ada23 #v6.5 + - name: Get branch name + if: ${{ inputs.only-modules == 'false' }} + id: branch-name + uses: tj-actions/branch-names@2e5354c6733793113f416314375826df030ada23 #v6.5 - - name: Set go cache keys - shell: bash - id: go-cache-dir - run: | - echo "gomodcache=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT - echo "gobuildcache=$(go env GOCACHE)" >> $GITHUB_OUTPUT + - name: Set go cache keys + shell: bash + id: go-cache-dir + run: | + echo "gomodcache=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT + echo "gobuildcache=$(go env GOCACHE)" >> $GITHUB_OUTPUT - - uses: actions/cache@v3 - name: Cache Go Modules - with: - path: | - ${{ steps.go-cache-dir.outputs.gomodcache }} - # The lifetime of go modules is much higher than the build outputs, so we increase cache efficiency - # here by not having the primary key contain the branch name - key: ${{ runner.os }}-gomod-${{ inputs.cache-version }}-${{ hashFiles('./go.sum') }} - restore-keys: | - ${{ runner.os }}-gomod-${{ inputs.cache-version }}- + - name: Set go module path + id: go-module-path + run: echo "path=./${{ inputs.go-module-file }}" >> $GITHUB_OUTPUT - - uses: actions/cache@v3 - if: ${{ inputs.only-modules == 'false' }} - name: Cache Go Build Outputs - with: - path: | - ${{ steps.go-cache-dir.outputs.gobuildcache }} - # The lifetime of go build outputs is pretty short, so we make our primary cache key be the branch name - key: ${{ runner.os }}-gobuild-${{ inputs.cache-version }}-${{ hashFiles('./go.sum') }}-${{ steps.branch-name.outputs.current_branch }} - restore-keys: | - ${{ runner.os }}-gobuild-${{ inputs.cache-version }}-${{ hashFiles('./go.sum') }}- - ${{ runner.os }}-gobuild-${{ inputs.cache-version }}- + - uses: actions/cache@v3 + name: Cache Go Modules + with: + path: | + ${{ steps.go-cache-dir.outputs.gomodcache }} + # The lifetime of go modules is much higher than the build outputs, so we increase cache efficiency + # here by not having the primary key contain the branch name + key: ${{ runner.os }}-gomod-${{ inputs.cache-version }}-${{ hashFiles(steps.go-module-file.output.path) }} + restore-keys: | + ${{ runner.os }}-gomod-${{ inputs.cache-version }}- + + - uses: actions/cache@v3 + if: ${{ inputs.only-modules == 'false' }} + name: Cache Go Build Outputs + with: + path: | + ${{ steps.go-cache-dir.outputs.gobuildcache }} + # The lifetime of go build outputs is pretty short, so we make our primary cache key be the branch name + key: ${{ runner.os }}-gobuild-${{ inputs.cache-version }}-${{ hashFiles(steps.go-module-file.output.path) }}-${{ steps.branch-name.outputs.current_branch }} + restore-keys: | + ${{ runner.os }}-gobuild-${{ inputs.cache-version }}-${{ hashFiles(steps.go-module-file.output.path) }}- + ${{ runner.os }}-gobuild-${{ inputs.cache-version }}- diff --git a/.github/workflows/ci-chaincli.yml b/.github/workflows/ci-chaincli.yml index 2d03ed4104f..7c526893118 100644 --- a/.github/workflows/ci-chaincli.yml +++ b/.github/workflows/ci-chaincli.yml @@ -10,42 +10,16 @@ on: jobs: golangci: + if: ${{ github.event_name == 'pull_request' || github.event_name == 'schedule' }} name: chaincli-lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Setup Go - uses: actions/setup-go@v4 + - name: Golang Lint + uses: ./.github/actions/ci-golang-lint with: - go-version-file: "core/scripts/go.mod" - cache: true - - name: Touching core/web/assets/index.html - run: mkdir -p core/web/assets && touch core/web/assets/index.html - - name: Build binary for chaincli - working-directory: core/scripts/chaincli - run: go build - - name: golangci-lint - uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0 - with: - version: v1.54.2 + name: chaincli-lint working-directory: core/scripts/chaincli - # 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 - with: - name: golangci-lint-report - path: core/scripts/chaincli/golangci-lint-report.xml - - name: Collect Metrics - if: always() - uses: smartcontractkit/push-gha-metrics-action@d2c2b7bdc9012651230b2608a1bcb0c48538b6ec - with: - basic-auth: ${{ secrets.GRAFANA_CLOUD_BASIC_AUTH }} - hostname: ${{ secrets.GRAFANA_CLOUD_HOST }} - this-job-name: chaincli-lint - continue-on-error: true + go-version-file: core/scripts/go.mod + go-module-file: core/scripts/go.sum + gc-basic-auth: ${{ secrets.GRAFANA_CLOUD_BASIC_AUTH }} + gc-host: ${{ secrets.GRAFANA_CLOUD_HOST }}