From da15b173a1e0ea4cf07b0eec91802fded6502808 Mon Sep 17 00:00:00 2001 From: sbp-bvanb Date: Mon, 28 Oct 2024 08:25:58 +0100 Subject: [PATCH] fix: [#100] Prevent code duplication by using a Taskfile --- Taskfile.yml | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ action.yml | 17 +++++++++++-- 2 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 Taskfile.yml diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..abe72bd --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,67 @@ +# TASK_X_REMOTE_TASKFILES=1 task remote:lint +# cmd: steps that will be run sequentially +# deps: tasks that will be run in parallel +--- +version: "3" + +vars: + GCI_VERSION: 0.13.5 + GOLANGCI_LINT_VERSION: 1.61.0 + +tasks: + gci-install: + silent: true + cmds: + - | + if ! ~/go/bin/gci --version | grep -q "gci version {{.GCI_VERSION}}"; then + go install github.com/daixiang0/gci@v{{.GCI_VERSION}} + fi + gci: + silent: true + cmds: + - task: gci-install + - | + if ~/go/bin/gci list --skip-generated . | grep "\.go$"; then + echo "One or more golang files detected with: 'incorrect import order':" + echo " * Observe: '~/go/bin/gci diff --skip-generated .'" + echo " * Resolve: '~/go/bin/gci write --skip-generated .'" + exit 1 + fi + gci-write: + silent: true + cmds: + - task: gci-install + - ~/go/bin/gci write --skip-generated -s standard -s default . + golangci-lint-install: + silent: true + cmds: + - | + if ! golangci-lint --version | grep -q "has version {{.GOLANGCI_LINT_VERSION}}"; then + curl \ + -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh |\ + sh -s -- -b $(go env GOPATH)/bin v{{.GOLANGCI_LINT_VERSION}} + fi + golangci-lint-run: + silent: true + cmds: + - | + golangci-lint run \ + --build-tags component,e2e,integration \ + --timeout 2m30s \ + -v + golangci-lint: + silent: true + cmds: + - task: golangci-lint-install + - task: golangci-lint-run + golangci-lint-without-cache: + silent: true + cmds: + - task: golangci-lint-install + - golangci-lint cache clean + - task: golangci-lint-run + lint: + silent: true + deps: + - task: gci + - task: golangci-lint diff --git a/action.yml b/action.yml index e4a6226..ec1b461 100644 --- a/action.yml +++ b/action.yml @@ -22,6 +22,10 @@ inputs: golang-number-of-tests-in-parallel: description: | Number of test in parallel. + task-version: + default: v3.39.2 + description: | + The Task version that has to be installed and used. testing-type: description: | The testing type, e.g. integration, unit or some other. @@ -50,14 +54,23 @@ runs: if: inputs.testing-type == 'lint' shell: bash # - # Install the golang version that has been defined in the go.mod file. + # Install task and the golang version that has been defined in the go.mod + # file. # # yamllint disable rule:line-length - uses: actions/setup-go@v5.1.0 - if: inputs.testing-type == 'component' || inputs.testing-type == 'coverage' || inputs.testing-type == 'integration' || inputs.testing-type == 'unit' + if: inputs.testing-type == 'component' || inputs.testing-type == 'coverage' || inputs.testing-type == 'integration' || inputs.testing-type == 'lint' || inputs.testing-type == 'unit' with: go-version-file: "go.mod" cache: false + - name: install task + if: inputs.testing-type == 'component' || inputs.testing-type == 'coverage' || inputs.testing-type == 'integration' || inputs.testing-type == 'lint' || inputs.testing-type == 'unit' + shell: bash + run: | + if ! ~/go/bin/task --version | grep "Task version: ${{ inputs.task-version }}"; then + major_version=$(echo "${{ inputs.task-version }}" | sed -E 's/^v([0-9]+).*/\1/') + go install github.com/go-task/task/v${major_version}/cmd/task@${{ inputs.task-version }} + fi # yamllint enable rule:line-length # # Verify downloaded dependencies.