-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskfile.yaml
245 lines (219 loc) · 7.35 KB
/
Taskfile.yaml
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
---
version: 3
vars:
PROJECT_NAME:
sh: echo ${PWD##*/}
REPOSITORY_NAME: stuttgart-things
MODULE: github.com/{{ .REPOSITORY_NAME }}/{{ .PROJECT_NAME }}
REGISTRY: ghcr.io #eu.gcr.io
RELEASE_REGISTRY: eu.gcr.io
RELEASE_REPOSITORY: "{{ .REPOSITORY_NAME }}"
IMAGE_REPO: "{{ .REGISTRY }}/{{ .REPOSITORY_NAME }}"
GIT_COMMIT:
sh: git log -n 1 --format=%h
DATE:
sh: date +"%Y.%m%d.%H%M"
BRANCH:
sh: if [ $(git rev-parse --abbrev-ref HEAD) != "main" ]; then echo $(git rev-parse --abbrev-ref HEAD); else echo main ; fi
COBRA_VERSION: 1.3.0
CMD: version
PARAMETERS: ""
DAGGER_GO_MODULE: github.com/stuttgart-things/dagger/go
DAGGER_GO_MODULE_VERSION: v0.0.4
VERSION:
sh: |
[ "$(git branch --show-current)" != "main" ] && echo "previewPost-$(git describe --tags --abbrev=0)" || echo $(git describe --tags --abbrev=0)
dotenv: ['.env', '{{.HOME}}/.env']
# PRECONDITION TO CHECK IF TOKENS SET OR UNSET FOR RELEASE
token-precondition: &release
- sh: "[[ -n \"${GITHUB_TOKEN}\" ]]"
msg: "Error: GITHUB_TOKEN is not set. Please set the environment variable and try again."
- sh: "[[ -z \"${GITLAB_TOKEN}\" ]]"
msg: "Error: GITLAB_TOKEN is set. Please unset the environment variable and try again."
- sh: "[[ $(git rev-parse --abbrev-ref HEAD) != 'main' ]]"
msg: "Error: You are on the 'main' branch. Please switch to a different branch and try again."
tasks:
test-run:
desc: "Build Bin & Test Run Command"
deps:
- run
cmds:
- $GOPATH/bin/machineshop run --source local --profile profiles/run.yaml --scripts hello --variables="name=horst"
check:
desc: "Run pre-commit hooks"
cmds:
- pre-commit run -a
dagger-ko:
desc: Build image w/ ko
cmds:
- dagger call -m {{ .DAGGER_GO_MODULE }}@{{ .DAGGER_GO_MODULE_VERSION }} ko-build --src ./ --token=env:GITHUB_TOKEN --repo "{{ .KO_REPO }}" --progress plain
vars:
KO_REPO: "{{ .REGISTRY }}/{{ .REPOSITORY_NAME }}/{{ .PROJECT_NAME }}"
test-version:
desc: Test version cmd
cmds:
- dagger call -m ./{{ .MODULE }} test-version --progress plain
vars:
MODULE: ci
test-install:
desc: Test crossplame modules
cmds:
- dagger call -m ./{{ .MODULE }} test-install --progress plain
vars:
MODULE: ci
run:
desc: Run
deps: [install]
cmds:
- "$GOPATH/bin/machineshop {{ .CMD }} {{ .PARAMETERS }}"
install-cobra:
cmds:
- "go install github.com/spf13/cobra-cli@v{{ .COBRA_VERSION }}"
tests:
desc: Built cli tests
deps:
- build
cmds:
- machineShop render --source local --template tests/template.yaml --defaults tests/default.yaml
build-ko:
desc: Build image w/ KO
deps: [lint, test, commit]
env:
KO_REPO: "{{ .MODULE }}"
KO_DOCKER_REPO: "{{ .IMAGE_REPO }}" #scr.cd43.sthings-pve.labul.sva.de/machineshop
cmds:
- |
BUILD_IMAGE=$(ko build --preserve-import-paths --image-label org.opencontainers.image.source={{ .KO_REPO }} --tags {{ .VERSION }} --push)
echo BUILD_IMAGE=${BUILD_IMAGE} >> .env
release-image:
desc: Release image
deps:
- build-ko
cmds:
- skopeo copy --src-tls-verify=false --dest-tls-verify=false docker://{{ .BUILD_IMAGE }} docker://{{ .RELEASE_IMAGE }}
vars:
RELEASE_IMAGE: "{{ .RELEASE_REGISTRY }}/{{ .RELEASE_REPOSITORY }}/{{ .PROJECT_NAME }}:{{ .VERSION }}"
build:
desc: Build code
deps: [lint, test]
cmds:
- go mod tidy
- go install
install:
desc: Install
deps: [lint, test]
cmds:
- go install -ldflags="-X {{ .MODULE }}/cmd.version={{ .VERSION }} -X {{ .MODULE }}/cmd.date={{ .DATE }} -X {{ .MODULE }}/cmd.commit={{ .GIT_COMMIT }}"
build-image:
desc: Build container image
deps: [install]
cmds:
- sudo nerdctl build -t {{ .REGISTRY }}/{{ .REPOSITORY_NAME }}/{{ lower (.PROJECT_NAME) }}:{{ .VERSION }} --build-arg VERSION={{ .VERSION }} --build-arg BUILD_DATE={{ .DATE }} --build-arg COMMIT={{ .GIT_COMMIT }} .
- sudo nerdctl push {{ .REGISTRY }}/{{ .REPOSITORY_NAME }}/{{ lower (.PROJECT_NAME) }}:{{ .VERSION }}
add-cmd:
deps: [install-cobra]
cmds:
- |
echo "Enter to be created cli cmd name:"
read CLI_CMD_NAME;
cobra-cli add ${CLI_CMD_NAME}
lint:
desc: Lint
cmds:
- cmd: golangci-lint run
ignore_error: true
test:
desc: Test
cmds:
- go mod tidy
- go test -v
tag:
desc: Commit, push & tag the module
deps: [lint, test]
cmds:
- rm -rf dist
- task: commit
- go mod tidy
- git pull --tags
- git tag -a {{ .TAG }} -m 'updated for stuttgart-things {{ .DATE }} for tag version {{ .TAG }}'
- git push origin --tags
release:
desc: Release
preconditions: *release
deps:
- run
cmds:
- task: commit
- sleep 20s
- |
RUN_ID=$(gh run list | grep {{ .BRANCH }} | head -1 | awk '{for (i=1; i<=NF; i++) if ($i ~ /^[0-9]+$/) print $i}')
gh run watch ${RUN_ID} --exit-status
- task: pr
- git checkout main && git pull
- npx semantic-release --dry-run
- npx semantic-release --debug --no-ci
- task: goreleaser
- task: build-ko
goreleaser:
desc: Release bins w/ goreleaser
cmds:
- rm -rf ./dist
- goreleaser healthcheck
- goreleaser check
- goreleaser release --skip=publish --snapshot --clean
- goreleaser release --clean
- rm -rf ./dist
branch:
desc: Create branch from main
cmds:
- git checkout main
- git branch
- git pull
- |
echo "Enter to be created (remote) branch:"
read BRANCH_NAME;
git checkout -b ${BRANCH_NAME}
git push origin ${BRANCH_NAME}
- git branch
- git branch --set-upstream-to=origin/main ${BRANCH_NAME}
pr:
desc: Create pull request into main
deps: [lint]
cmds:
- task: commit
#- unset GITHUB_TOKEN && gh auth login --hostname GitHub.com -p https --web
- gh pr create -t "{{ .BRANCH }}" -b "{{ .BRANCH }} branch into main"
- sleep 20s
- gh pr checks $(gh pr list | grep "^[^#;]" | grep '{{ .BRANCH }}' | awk '{print $1}') --watch
- gh pr merge $(gh pr list | grep "^[^#;]" | grep '{{ .BRANCH }}' | awk '{print $1}') --auto --rebase --delete-branch
commit:
desc: Commit + push code into branch
cmds:
- rm -rf dist/
- git branch --set-upstream-to=origin/{{ .BRANCH }}
- git pull
- |
git add *
if [[ -n $(git status --porcelain) ]]; then
echo "committing changes"
echo "ENTER COMMIT MESSAGE"
COMMIT_MESSAGE=$(echo $(gum choose "feat: {{ .BRANCH }}" "fix: {{ .BRANCH }}" "BREAKING CHANGE: {{ .BRANCH }}" "ENTER CUSTOM COMMIT MESSAGE"))
if [ "$COMMIT_MESSAGE" == "ENTER CUSTOM COMMIT MESSAGE" ]; then
COMMIT_MESSAGE=$(echo $(gum input --placeholder "scope" --value "commit to {{ .BRANCH }}"))
fi
git commit --allow-empty -a -m "$(echo ${COMMIT_MESSAGE})"
else
echo "no changes"
fi
git push origin -u {{ .BRANCH }}
delete-branch:
desc: Delete branch from origin
cmds:
- git checkout main
- git branch
- git pull
- |
echo "Enter to be deleted (remote) branch:"
read BRANCH_NAME;
git branch -d ${BRANCH_NAME}
git push origin -d ${BRANCH_NAME}