Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to customise gci sections #132

Merged
merged 3 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ If you are new to Task, you may want to check out the following resources:
- Instructions to [configure completions](https://taskfile.dev/installation/#setup-completions)
- [Integrations](https://taskfile.dev/integrations/) with e.g. Visual Studio Code, Sublime and IntelliJ.

### Configuration

The `Taskfile.yml` in this project defines a number of variables. Some of these
can be overridden when including this Taskfile in your project. See the example
below, where the `GCI_SECTIONS` variable is overridden, for how to do this.

The following variables can be overridden:

| Variable | Description |
| :------------------- | :------------------------------------------------------------------------------------------------------------------------------ |
| `GCI_SECTION` | Define how `gci` processes inputs (see the [gci README](https://github.com/daixiang0/gci?tab=readme-ov-file#usage) for details) | |

## Usage

### Locally
Expand Down Expand Up @@ -79,6 +91,19 @@ Alternatively, if you have [configured
completions](https://taskfile.dev/installation/#setup-completions) in your
shell, you can tab to get a list of available tasks.

If you want to override one of the variables in our Taskfile, you'll have adjust the `includes` sections like this:

```yml
---
...

includes:
remote:
taskfile: {{.REMOTE_URL}}/{{.REMOTE_URL_REPO}}/{{.REMOTE_URL_REF}}/Taskfile.yml
vars:
GCI_SECTIONS: '-s standard -s default -s alias'
```

### GitHub

Create a `.github/workflows/golang.yml` file with the following content:
Expand Down
5 changes: 3 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ vars:
BUILD_TAGS: component,e2e,integration
COVERPROFILE: profile.cov
GCI_VERSION: 0.13.5
GCI_SECTIONS: '{{.GCI_SECTIONS | default "-s standard -s default"}}'
GOLANGCI_LINT_VERSION: 1.61.0
GOLANG_PARALLEL_TESTS:
sh: |
Expand Down Expand Up @@ -105,7 +106,7 @@ tasks:
cmds:
- task: gci-install
- |
if ~/go/bin/gci list --skip-generated . | grep "\.go$"; then
if ~/go/bin/gci list --skip-generated {{.GCI_SECTIONS}} . | 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 .'"
Expand All @@ -116,7 +117,7 @@ tasks:
silent: true
cmds:
- task: gci-install
- ~/go/bin/gci write --skip-generated -s standard -s default .
- ~/go/bin/gci write --skip-generated {{.GCI_SECTIONS}} .
golangci-lint-install:
silent: true
cmds:
Expand Down