Skip to content

Commit

Permalink
Merge branch 'main' into API-46
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-hoang committed Sep 19, 2022
2 parents cdf93f5 + 053629a commit 6391190
Show file tree
Hide file tree
Showing 89 changed files with 1,543 additions and 171 deletions.
40 changes: 40 additions & 0 deletions .codecov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# See http://docs.codecov.io/docs/coverage-configuration
coverage:
precision: 2 # 2 = xx.xx%, 0 = xx%
round: down
# For example: 20...60 would result in any coverage less than 20%
# would have a red background. The color would gradually change to
# green approaching 60%. Any coverage over 60% would result in a
# solid green color.
range: "20...60"

status:
# project will give us the diff in the total code coverage between a commit
# and its parent
project: yes
# Patch gives just the coverage of the patch
patch: yes
# changes tells us if there are unexpected code coverage changes in other files
# which were not changed by the diff
changes: yes

# See http://docs.codecov.io/docs/ignoring-paths
ignore:
- "assets/*"
- "build/*"
- "deploy/*"
- "hack/*"
- "manifests/*"
- "openshift-ci/*"
- "vendor/*"
- "Makefile"
- ".travis.yml"

# See http://docs.codecov.io/docs/pull-request-comments-1
comment:
layout: "diff, files"
behavior: ""
# default = posts once then update, posts new if delete
# once = post once then updates
# new = delete old, post new
# spammy = post new
21 changes: 21 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Code Coverage Report
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2.3.1
with:
persist-credentials: false
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Run tests
run: make test
- name: Codecov
uses: codecov/codecov-action@v2.1.0
23 changes: 16 additions & 7 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup Go environment
uses: actions/setup-go@v2.1.3
with:
go-version: 1.15
go-version: 1.16
id: go

- name: Check out code into the Go module directory
Expand All @@ -43,11 +43,20 @@ jobs:
exit 1
fi
- name: Check license
run: |
go get github.com/google/addlicense@latest
git reset HEAD --hard
make check_license
if [[ $? != 0 ]]
then
echo "not well formatted sources are found:"
git --no-pager diff
exit 1
fi
- name: Run Go Tests
run: make test

- name: Upload Test Coverage results
uses: actions/upload-artifact@v2
with:
name: lib-test-coverage-html
path: tests/v2/lib-test-coverage.html

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2.1.0
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ This document is a new contributor guide, which outlines the requirements for co

To get an overview of the project, read the [README](README.md). For more information on devfiles, check the official [devfile docs](https://devfile.io/docs/devfile/2.1.0/user-guide/).

## Certificate of Origin

By contributing to this project you agree to the Developer Certificate of
Origin (DCO). This document was created by the Linux Kernel community and is a
simple statement that you, as a contributor, have the legal right to make the
contribution. See the [DCO](./DCO) file for details.

## Prerequisites

The following are required to work on devfile library:
Expand Down
37 changes: 37 additions & 0 deletions DCO
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or

(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or

(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.

(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
23 changes: 21 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,29 @@ bin:

.PHONY: test
test:
go test -coverprofile tests/v2/lib-test-coverage.out -v ./...
go tool cover -html=tests/v2/lib-test-coverage.out -o tests/v2/lib-test-coverage.html
go test -coverprofile cover.out -v ./...

.PHONY: clean
clean:
@rm -rf $(FILES)

### fmt_license: ensure license header is set on all files
fmt_license:
ifneq ($(shell command -v addlicense 2> /dev/null),)
@echo 'addlicense -v -f license_header.txt **/*.go'
@addlicense -v -f license_header.txt $$(find . -name '*.go')
else
$(error addlicense must be installed for this rule: go get -u github.com/google/addlicense)
endif

### check_fmt: Checks for missing licenses on files in repo
check_license:
ifeq ($(shell command -v addlicense 2> /dev/null),)
$(error "error addlicense must be installed for this rule: go get -u github.com/google/addlicense")
endif

if ! addlicense -check -f license_header.txt $$(find . -not -path '*/\.*' -name '*.go'); then \
echo "Licenses are not formatted; run 'make fmt_license'"; exit 1 ;\
fi \


39 changes: 28 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,33 @@ The function documentation can be accessed via [pkg.go.dev](https://pkg.go.dev/g
```go
// ParserArgs is the struct to pass into parser functions which contains required info for parsing devfile.
parserArgs := parser.ParserArgs{
Path: path,
FlattenedDevfile: &flattenedDevfile,
RegistryURLs: registryURLs,
DefaultNamespace: defaultNamespace,
Context: context,
K8sClient: client,
Path: path,
FlattenedDevfile: &flattenedDevfile,
ConvertKubernetesContentInUri: &convertKubernetesContentInUri
RegistryURLs: registryURLs,
DefaultNamespace: defaultNamespace,
Context: context,
K8sClient: client,
ExternalVariables: externalVariables,
}

// Parses the devfile and validates the devfile data
// if top-level variables are not substituted successfully, the warnings can be logged by parsing variableWarning
devfile, variableWarning, err := devfilePkg.ParseDevfileAndValidate(parserArgs)
```


2. To override the HTTP request and response timeouts for a devfile with a parent reference from a registry URL, specify the HTTPTimeout value in the parser arguments
```go
// specify the timeout in seconds
httpTimeout := 20
parserArgs := parser.ParserArgs{
HTTPTimeout: &httpTimeout
}
```


2. To get specific content from devfile
3. To get specific content from devfile
```go
// To get all the components from the devfile
components, err := devfile.Data.GetComponents(DevfileOptions{})
Expand Down Expand Up @@ -65,7 +78,7 @@ The function documentation can be accessed via [pkg.go.dev](https://pkg.go.dev/g
})
```

3. To get the Kubernetes objects from the devfile, visit [generators.go source file](pkg/devfile/generator/generators.go)
4. To get the Kubernetes objects from the devfile, visit [generators.go source file](pkg/devfile/generator/generators.go)
```go
// To get a slice of Kubernetes containers of type corev1.Container from the devfile component containers
containers, err := generator.GetContainers(devfile)
Expand All @@ -82,7 +95,7 @@ The function documentation can be accessed via [pkg.go.dev](https://pkg.go.dev/g
deployment := generator.GetDeployment(deployParams)
```

4. To update devfile content
5. To update devfile content
```go
// To update an existing component in devfile object
err := devfile.Data.UpdateComponent(v1.Component{
Expand Down Expand Up @@ -114,7 +127,7 @@ The function documentation can be accessed via [pkg.go.dev](https://pkg.go.dev/g
err := devfile.Data.DeleteComponent(componentName)
```

5. To write to a devfile, visit [writer.go source file](pkg/devfile/parser/writer.go)
6. To write to a devfile, visit [writer.go source file](pkg/devfile/parser/writer.go)
```go
// If the devfile object has been created with devfile path already set, can simply call WriteYamlDevfile to writes the devfile
err := devfile.WriteYamlDevfile()
Expand Down Expand Up @@ -145,7 +158,7 @@ The function documentation can be accessed via [pkg.go.dev](https://pkg.go.dev/g
// write to the devfile on disk
err = devfile.WriteYamlDevfile()
```
6. To parse the outerloop Kubernetes/OpenShift component's uri or inline content, call the read and parse functions
7. To parse the outerloop Kubernetes/OpenShift component's uri or inline content, call the read and parse functions
```go
// Read the YAML content
values, err := ReadKubernetesYaml(src, fs)
Expand All @@ -154,6 +167,7 @@ The function documentation can be accessed via [pkg.go.dev](https://pkg.go.dev/g
resources, err := ParseKubernetesYaml(values)
```


## Projects using devfile/library

The following projects are consuming this library as a Golang dependency
Expand All @@ -176,3 +190,6 @@ Issues are tracked in the [devfile/api](https://github.com/devfile/api) repo wit

For devfile/library releases, please check the release [page](https://github.com/devfile/library/releases).

## Contributing

Please see our [contributing.md](./CONTRIBUTING.md).
Loading

0 comments on commit 6391190

Please sign in to comment.