Skip to content

Commit

Permalink
Add buildCommand
Browse files Browse the repository at this point in the history
And show how to run tests

Signed-off-by: Chmouel Boudjnah <[email protected]>
  • Loading branch information
chmouel committed Apr 26, 2024
1 parent b7abed0 commit a999c2b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ spec:
emptyDir: {}
```

- you can as well redefine the `buildCommand` which by default do a `go build
-v ./` with the `buildCommand` parameter, for example if you want instead to
run the tests on a repo with caching:

```shell
tkn pipeline start pipeline-go --param repo_url=https://github.com/chmouel/gosmee \
--param revision=main --param registry=docker.io/username \
--param=buildCommand="make test" -w name=source,emptyDir=
```

## License

[Apache License 2.0](./LICENSE)
19 changes: 14 additions & 5 deletions examples/pipeline-go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,23 @@ spec:
type: string
- name: registry
type: string
- name: buildCommand
type: string
default: go build -v .
workspaces:
- name: source
tasks:
- displayName: Build go application
name: noop-task
name: build-task
workspaces:
- name: source
workspace: source
taskSpec:
workspaces:
- name: source
params:
- name: buildCommand
default: $(params.buildCommand)
steps:
- name: create-repo
image: cgr.dev/chainguard/go
Expand All @@ -41,7 +47,7 @@ spec:
value: $(params.repo_url)
- name: revision
value: $(params.revision)
- name: cache-fetch
- name: fetch-cache
ref:
resolver: http
params:
Expand All @@ -61,12 +67,15 @@ spec:
- image: cgr.dev/chainguard/go
workingDir: $(workspaces.source.path)/repo
name: noop-task
env:
- name: GOCACHE
value: $(workspaces.source.path)/cache/gocache
- name: GOMODCACHE
value: $(workspaces.source.path)/cache/gomodcache
script: |
set -x
git config --global --add safe.directory $(workspaces.source.path)/repo
export GOCACHE=$(workspaces.source.path)/cache/gocache
export GOMODCACHE=$(workspaces.source.path)/cache/gomodcache
go build -v .
$(params.buildCommand)
du -shk $GOPATH
du -shk $GOMODCACHE
- name: cache-upload
Expand Down

0 comments on commit a999c2b

Please sign in to comment.