forked from algolia/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskfile.yml
123 lines (123 loc) · 4.17 KB
/
Taskfile.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
version: 3
output: prefixed
vars:
# The URL to the "old" Algolia docs repo
docs_remote: https://github.com/algolia/doc.git
# The temporary folder for the generated YML files
docs_local: docs
cli_ref_path: app_data/cli/commands
yml_folder: tmp
tasks:
build:
desc: Build the binary
deps: [generate]
cmd: go build -ldflags "-s -w -X=github.com/algolia/cli/pkg/version.Version={{ .VERSION }}" -o algolia cmd/algolia/main.go
vars:
VERSION: '{{ .VERSION | default "main" }}'
test:
desc: Run unit tests
run: always
cmd: go test ./...
e2e:
desc: Run end-to-end tests
summary: |
Run tests that mimic how user enters commands and flags.
These tests make real requests to the Algolia API.
To run them, create a `.env` file with the `ALGOLIA_APPLICATION_ID`
and `ALGOLIA_API_KEY` credentials.
cmd: go test ./e2e -tags=e2e
dotenv: [.env]
lint:
desc: Lint code
cmd: golangci-lint run
format:
desc: Format code
cmds:
- gofumpt -w pkg cmd test internal api e2e
- golines -w pkg cmd test internal api e2e
ci:
desc: Test, lint, and format
aliases:
- default
deps:
- build
- test
- lint
- format
api-specs-pr:
desc: Update the flags for search and settings from the latest Search API spec
summary: |
This task downloads the latest Search API OpenAPI spec from the api-clients-automation repo,
generates the flags, and makes a new PR to the CLI GitHub repo.
deps: [download-spec-file, generate]
preconditions:
- git status --porcelain
cmds:
- |
original="$(git branch --show-current)"
git checkout -B {{ .branch }}
git add .
git commit --message "chore: update search api spec"
git push --force --set-upstream origin {{ .branch }}
gh pr list --base main --head {{ .branch }} | grep -q . || gh pr create --title '{{ .pr-title }}' --description '{{ .pr-description }}'
git switch "${original}"
vars:
branch: feat/api-specs
pr-title: "chore: Update Search API spec"
pr-description: "Update Search API spec"
env:
GIT_COMMITTER_NAME: algolia-ci
GIT_AUTHOR_NAME: algolia-ci
GIT_COMMITTER_EMAIL: [email protected]
GIT_AUTHOR_EMAIL: [email protected]
download-spec-file:
desc: Download the latest Search API spec from GitHub
cmd: curl -fsSL -o {{ .destination }} {{ .source }}
vars:
source: https://raw.githubusercontent.com/algolia/api-clients-automation/main/specs/bundled/search.yml
destination: ./api/specs/search.yml
generate:
desc: Generate command flags
internal: true
cmds:
- go generate ./...
update-docs:
desc: Update the CLI command reference in the Algolia docs
deps:
- clone-docs
- generate-command-reference
cmds:
- task: update-command-reference
- task: cleanup
clone-docs:
desc: Clone the Algolia docs
internal: true
cmd: git clone --depth=1 {{ .docs_remote }} {{ .docs_local }}
generate-command-reference:
desc: Generate updated YML files for the CLI command reference
internal: true
cmd: go run ./cmd/docs --app_data-path {{ .yml_folder }}
update-command-reference:
desc: Add the updated YML files to the docs
summary: |
This task clones the Algolia docs repo,
adds the updated CLI reference yml files to it,
and pushes a new PR to the GitHub repo.
internal: true
cmds:
- |
git -C {{ .docs_local }} checkout -B chore/cli-$(git rev-parse --short HEAD)
git -C {{ .docs_local }} rm "{{ .cli_ref_path }}/*.yml"
mkdir -p {{ .docs_local }}/{{ .cli_ref_path }}
mv {{ .yml_folder }}/*.yml {{ .docs_local }}/{{ .cli_ref_path }}/
git -C {{ .docs_local }} add "{{ .cli_ref_path }}/*.yml"
git -C {{ .docs_local }} commit --message 'chore: Update CLI command reference'
env:
GIT_COMMITTER_NAME: algolia-ci
GIT_AUTHOR_NAME: algolia-ci
GIT_COMMITTER_EMAIL: [email protected]
GIT_AUTHOR_EMAIL: [email protected]
cleanup:
desc: Cleanup the docs files
internal: true
cmd: rm -rf {{ .docs_local }} {{ .yml_folder }} || true