-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from opendevstack/feature/step-action
WIP: Implement step action
- Loading branch information
Showing
8 changed files
with
211 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/bin/bash | ||
set -eu | ||
|
||
build_extra_inputs="" | ||
build_reused_from_location_path="" | ||
build_script="/usr/local/bin/go-build-script" | ||
cache_build="true" | ||
enable_cgo="false" | ||
go_os="linux" | ||
go_arch="amd64" | ||
output_dir="docker" | ||
working_dir="." | ||
pre_test_script="" | ||
debug="false" | ||
|
||
while [[ "$#" -gt 0 ]]; do | ||
case $1 in | ||
-build-extra-inputs=*) build_extra_inputs="${1#*=}";; | ||
-build-reused-from-location-path=*) build_reused_from_location_path="${1#*=}";; | ||
-build-script=*) build_script="${1#*=}";; | ||
-cache-build=*) cache_build="${1#*=}";; | ||
-debug=*) debug="${1#*=}";; | ||
-enable-cgo=*) enable_cgo="${1#*=}";; | ||
-go-os=*) go_os="${1#*=}";; | ||
-go-arch=*) go_arch="${1#*=}";; | ||
-output-dir=*) output_dir="${1#*=}";; | ||
-pre-test-script=*) pre_test_script="${1#*=}";; | ||
-working-dir=*) working_dir="${1#*=}";; | ||
*) echo "Unknown parameter passed: $1"; exit 1;; | ||
esac; shift; done | ||
|
||
echo -n "" > "${build_reused_from_location_path}" | ||
cache_build_key="go-${go_os}-${go_arch}" | ||
if copy-build-if-cached \ | ||
--cache-build="${cache_build}" \ | ||
--cache-build-key="${cache_build_key}" \ | ||
--build-extra-inputs="${build_extra_inputs}" \ | ||
--cached-outputs="${output_dir}" \ | ||
--cache-location-used-path="${build_reused_from_location_path}" \ | ||
--working-dir="${working_dir}" \ | ||
--debug="${debug}" ; then | ||
exit 0 | ||
fi | ||
set +e | ||
"${build_script}" \ | ||
--working-dir="${working_dir}" \ | ||
--enable-cgo="${enable_cgo}" \ | ||
--go-os="${go_os}" \ | ||
--go-arch="${go_arch}" \ | ||
--pre-test-script="${pre_test_script}" \ | ||
--output-dir="${output_dir}" \ | ||
--debug="${debug}" | ||
build_exit=$? | ||
set -e | ||
copy-artifacts --debug="${debug}" | ||
if [ $build_exit -ne 0 ]; then | ||
exit $build_exit | ||
fi | ||
cache-build \ | ||
--cache-build="${cache_build}" \ | ||
--cache-build-key="${cache_build_key}" \ | ||
--build-extra-inputs="${build_extra_inputs}" \ | ||
--cached-outputs="${output_dir}" \ | ||
--cache-location-used-path="${build_reused_from_location_path}" \ | ||
--working-dir="${working_dir}" \ | ||
--debug="${debug}" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# File is generated; DO NOT EDIT. | ||
apiVersion: tekton.dev/v1alpha1 | ||
kind: StepAction | ||
metadata: | ||
name: ods-pipeline-go-build | ||
spec: | ||
params: | ||
- name: working-dir | ||
description: | | ||
Working directory. The path must be relative to the root of the repository, | ||
without leading `./` and trailing `/`. | ||
type: string | ||
default: "." | ||
- name: enable-cgo | ||
description: Whether to enable CGO. When not enabled the build will set `CGO_ENABLED=0`. | ||
type: string | ||
default: "false" | ||
- name: go-os | ||
description: "`GOOS` variable (the execution operating system such as `linux`, `windows`)." | ||
type: string | ||
default: "linux" | ||
- name: go-arch | ||
description: "`GOARCH` variable (the execution architecture such as `arm`, `amd64`)." | ||
type: string | ||
default: "amd64" | ||
- name: output-dir | ||
description: >- | ||
Path to the directory into which the resulting Go binary should be copied, relative to `working-dir`. | ||
This directory may then later be used as Docker context for example. | ||
type: string | ||
default: docker | ||
- name: cache-build | ||
description: >- | ||
If enabled tasks uses or populates cache with the output dir contents (and artifacts) so that | ||
a build can be skipped if the `working-dir` contents did not change. | ||
You must set this to `"false"` if the build can be affected by files outside `working-dir`. See ADR caching-build-tasks for more details and workarounds. | ||
type: string | ||
default: "true" | ||
- name: build-extra-inputs | ||
description: >- | ||
List of build source directories (as colon separated string) which in addition working-dir influence the build. | ||
These directories are relative to the repository root. | ||
If the contents in these directories change the cache is invalidated so that the build task will rebuild from scratch. | ||
type: string | ||
default: "" | ||
- name: build-script | ||
description: >- | ||
Build script to execute. The | ||
link:https://github.com/opendevstack/ods-pipeline-go/blob/main/build/images/scripts/go-build.sh[default script] | ||
is located in the container image. If you specify a relative path | ||
instead, it will be resolved from the workspace. See the task definition | ||
for details how the build script is invoked. | ||
type: string | ||
default: "/usr/local/bin/go-build" | ||
- name: pre-test-script | ||
description: Script to execute before running tests, relative to the working directory. | ||
type: string | ||
default: "" | ||
- name: private-cert | ||
description: Volume mount name | ||
type: string | ||
- name: debug | ||
description: Whether to turn on debug mode | ||
type: string | ||
default: "false" | ||
- name: source | ||
description: Path to source workspace | ||
type: string | ||
results: | ||
- description: The cache location that the build task used. If caching is not enabled this will be an empty string. | ||
name: build-reused-from-location | ||
# Image is built from build/images/Dockerfile.go-toolset. | ||
image: 'ghcr.io/opendevstack/ods-pipeline-go/go-toolset:0.3.0' | ||
env: | ||
- name: HOME | ||
value: '/tekton/home' | ||
- name: CI | ||
value: "true" | ||
command: [ "go-build-action" ] | ||
args: [ | ||
"-build-extra-inputs=$(params.build-extra-inputs)", | ||
"-build-reused-from-location-path=$(params.build-reused-from-location-path)", | ||
"-build-script=$(params.build-script)", | ||
"-cache-build=$(params.cache-build)", | ||
"-debug=$(params.debug)", | ||
"-enable-cgo=$(params.enable-cgo)", | ||
"-go-os=$(params.go-os)", | ||
"-go-arch=$(params.go-arch)", | ||
"-output-dir=$(params.output-dir)", | ||
"-pre-test-script=$(params.pre-test-script)", | ||
"-working-dir=$(params.working-dir)", | ||
] | ||
volumeMounts: | ||
- mountPath: /etc/ssl/certs/private-cert.pem | ||
name: $(params.private-cert) | ||
readOnly: true | ||
subPath: tls.crt | ||
workingDir: $(params.source) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters