Skip to content

Commit

Permalink
[CI] Auto download golang tools in pre-commit (ray-project#2917)
Browse files Browse the repository at this point in the history
Signed-off-by: Chi-Sheng Liu <[email protected]>
  • Loading branch information
MortalHappiness authored Feb 5, 2025
1 parent bc2bd71 commit 268a776
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 49 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/test-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@ jobs:
name: Lint (pre-commit)
runs-on: ubuntu-22.04
steps:
- name: Install golangci-lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.60.3
mv ./bin/golangci-lint /usr/local/bin/golangci-lint
shell: bash

- name: Install kubeconform
run: |
curl -L https://github.com/yannh/kubeconform/releases/download/v0.6.7/kubeconform-linux-amd64.tar.gz -o kubeconform.tar.gz
tar -xzf kubeconform.tar.gz
mv kubeconform /usr/local/bin/
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]
Expand Down
43 changes: 10 additions & 33 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,48 +29,25 @@ repos:

- repo: local
hooks:
- id: check-golangci-lint-version
name: golangci-lint version check
entry: bash -c 'version="1.60.3"; [ "$(golangci-lint --version | awk "/version/ {print \$4}" | sed "s/^v//")" = "$version" ] || { echo "golangci-lint version is not $version"; exit 1; }'
language: system
always_run: true
fail_fast: true
pass_filenames: false

- repo: local
hooks:
- id: golangci-lint-ray-operator
name: golangci-lint (ray-operator)
entry: bash -c 'cd ray-operator && golangci-lint run --fix --exclude-files _generated.go --timeout 10m0s; status=$?; cd ..; exit $status'
- id: golangci-lint
name: golangci-lint
entry: ./scripts/lint.sh
types: [ go ]
language: golang
require_serial: true
files: ^ray-operator/

- repo: local
hooks:
- id: golangci-lint-kubectl-plugin
name: golangci-lint (kubectl-plugin)
entry: bash -c 'cd kubectl-plugin && golangci-lint run --fix --timeout 10m0s; status=$?; cd ..; exit $status'
types: [ go ]
language: golang
require_serial: true
files: ^kubectl-plugin/

- repo: local
hooks:
- id: check-kubeconform-version
name: kubeconform version check
entry: bash -c 'version="0.6.7"; [ "$(kubeconform -v | awk -F"v" "{print \$2}")" = "$version" ] || { echo "kubeconform version is not $version"; exit 1; }'
language: system
always_run: true
fail_fast: true
pass_filenames: false
additional_dependencies:
- github.com/golangci/golangci-lint/cmd/[email protected]

- repo: local
hooks:
- id: validate-helm-charts
name: validate helm charts with kubeconform
entry: bash scripts/validate-helm.sh
language: system
language: golang
require_serial: true
always_run: true
pass_filenames: false
additional_dependencies:
- github.com/yannh/kubeconform/cmd/[email protected]
6 changes: 2 additions & 4 deletions ray-operator/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,8 @@ helm uninstall kuberay-operator; helm install kuberay-operator --set image.repos

## pre-commit hooks

1. Install [golangci-lint](https://github.com/golangci/golangci-lint/releases).
2. Install [kubeconform](https://github.com/yannh/kubeconform/releases).
3. Install [pre-commit](https://pre-commit.com/).
4. Run `pre-commit install` to install the pre-commit hooks.
1. Install [pre-commit](https://pre-commit.com/).
2. Run `pre-commit install` to install the pre-commit hooks.
## CI/CD

Expand Down
11 changes: 11 additions & 0 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -euo pipefail

dirs_to_lint="ray-operator kubectl-plugin"

for dir in $dirs_to_lint; do
pushd $dir
golangci-lint run --fix --exclude-files _generated.go --timeout 10m0s
popd
done

0 comments on commit 268a776

Please sign in to comment.