Skip to content

Commit

Permalink
Merge branch 'master' into improve-error-msg
Browse files Browse the repository at this point in the history
  • Loading branch information
wenovus committed Aug 4, 2023
2 parents 20bbd0b + 41e0b30 commit aa1ed2f
Show file tree
Hide file tree
Showing 41 changed files with 848 additions and 209 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Go

on:
Expand Down
29 changes: 29 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# How to Contribute

We'd love to accept your patches and contributions to this project. There are
just a few small guidelines you need to follow.

## Contributor License Agreement

Contributions to this project must be accompanied by a Contributor License
Agreement (CLA). You (or your employer) retain the copyright to your
contribution; this simply gives us permission to use and redistribute your
contributions as part of the project. Head over to
<https://cla.developers.google.com/> to see your current agreements on file or
to sign a new one.

You generally only need to submit a CLA once, so if you've already submitted one
(even if it was for a different project), you probably don't need to do it
again.

## Code Reviews

All submissions, including submissions by project members, require review. We
use GitHub pull requests for this purpose. Consult
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
information on using pull requests.

## Community Guidelines

This project follows
[Google's Open Source Community Guidelines](https://opensource.google/conduct/).
16 changes: 15 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
FROM gcr.io/cloud-builders/go:debian
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang
SHELL ["/bin/bash", "-c"]

#RUN git clone https://github.com/mbj4668/pyang.git /workspace/results/pyang@head/pyang
Expand Down
5 changes: 3 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down Expand Up @@ -178,15 +179,15 @@
APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright {yyyy} {name of copyright owner}
Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ regexp | Files moved into GOPATH from its folder during CI build
pyang & pyangbind | pip
oc-pyang | git clone
goyang/ygot | go get
yanglint | Debian package periodically uploaded to cloud storage
yanglint | Debian packages (libyang2 and libyang2-tools) periodically uploaded to cloud storage. These are renamed libyang.deb and yanglint.deb respectively in the GCS bucket.

## Setting Up GCB

Expand Down
45 changes: 28 additions & 17 deletions cmd_gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ var (
// GCB script, which together create the running environment for the
// generated validator script.
scriptTemplates = map[string]*scriptSpec{
"pyang": &scriptSpec{
"pyang": {
headerTemplate: mustTemplate("pyang-header", `#!/bin/bash
workdir={{ .ResultsDir }}
mkdir -p "$workdir"
Expand All @@ -138,7 +138,7 @@ script_options=(
function run-dir() {
declare prefix="$workdir"/"$1"=="$2"==
shift 2
echo $cmd "${options[@]}" "$@" > ${prefix}cmd
echo pyang "${options[@]}" "$@" > ${prefix}cmd
if ! $($cmd "${options[@]}" "${script_options[@]}" "$@" &> ${prefix}pass); then
mv ${prefix}pass ${prefix}fail
fi
Expand All @@ -147,25 +147,27 @@ function run-dir() {
perModelTemplate: mustTemplate("pyang", `run-dir "{{ .ModelDirName }}" "{{ .ModelName }}" {{- range $i, $buildFile := .BuildFiles }} {{ $buildFile }} {{- end }} {{- if .Parallel }} & {{- end }}
`),
},
"oc-pyang": &scriptSpec{
"oc-pyang": {
headerTemplate: mustTemplate("oc-pyang-header", `#!/bin/bash
workdir={{ .ResultsDir }}
mkdir -p "$workdir"
`+"{{`"+util.PYANG_MSG_TEMPLATE_STRING+"`}}"+`
cmd="$@"
options=(
-p {{ .ModelRoot }}
-p {{ .RepoRoot }}/third_party/ietf
--openconfig
--ignore-error=OC_RELATIVE_PATH
-p {{ .ModelRoot }}
-p {{ .RepoRoot }}/third_party/ietf
)
script_options=(
--msg-template "$PYANG_MSG_TEMPLATE"
)
function run-dir() {
declare prefix="$workdir"/"$1"=="$2"==
local cmd_display_options=( --plugindir '$OCPYANG_PLUGIN_DIR' "${options[@]}" )
local options=( --plugindir "$OCPYANG_PLUGIN_DIR" "${options[@]}" )
shift 2
echo $cmd "${options[@]}" "$@" > ${prefix}cmd
echo pyang "${cmd_display_options[@]}" "$@" > ${prefix}cmd
if ! $($cmd "${options[@]}" "${script_options[@]}" "$@" &> ${prefix}pass); then
mv ${prefix}pass ${prefix}fail
fi
Expand All @@ -174,34 +176,41 @@ function run-dir() {
perModelTemplate: mustTemplate("oc-pyang", `run-dir "{{ .ModelDirName }}" "{{ .ModelName }}" {{- range $i, $buildFile := .BuildFiles }} {{ $buildFile }} {{- end }} {{- if .Parallel }} & {{- end }}
`),
},
"pyangbind": &scriptSpec{
"pyangbind": {
headerTemplate: mustTemplate("pyangbind-header", `#!/bin/bash
workdir={{ .ResultsDir }}
mkdir -p "$workdir"
`+"{{`"+util.PYANG_MSG_TEMPLATE_STRING+"`}}"+`
cmd="$@"
options=(
-f pybind
-p {{ .ModelRoot }}
-p {{ .RepoRoot }}/third_party/ietf
-f pybind
)
script_options=(
--msg-template "$PYANG_MSG_TEMPLATE"
)
function run-dir() {
declare prefix="$workdir"/"$1"=="$2"==
local options=( -o "$1"."$2".binding.py "${options[@]}" )
local output_file="$1"."$2".binding.py
local cmd_display_options=( --plugindir '$PYANGBIND_PLUGIN_DIR' -o "${output_file}" "${options[@]}" )
local options=( --plugindir "$PYANGBIND_PLUGIN_DIR" -o "${output_file}" "${options[@]}" )
shift 2
echo $cmd "${options[@]}" "$@" > ${prefix}cmd
if ! $($cmd "${options[@]}" "${script_options[@]}" "$@" &> ${prefix}pass); then
echo pyang "${cmd_display_options[@]}" "$@" > ${prefix}cmd
status=0
$cmd "${options[@]}" "${script_options[@]}" "$@" &> ${prefix}pass || status=1
if [[ $status -eq "0" ]]; then
python "${output_file}" &>> ${prefix}pass || status=1
fi
if [[ $status -eq "1" ]]; then
mv ${prefix}pass ${prefix}fail
fi
}
`),
perModelTemplate: mustTemplate("pyangbind", `run-dir "{{ .ModelDirName }}" "{{ .ModelName }}" {{- range $i, $buildFile := .BuildFiles }} {{ $buildFile }} {{- end }} {{- if .Parallel }} & {{- end }}
`),
},
"goyang-ygot": &scriptSpec{
"goyang-ygot": {
headerTemplate: mustTemplate("goyang-ygot-header", `#!/bin/bash
workdir={{ .ResultsDir }}
mkdir -p "$workdir"
Expand All @@ -226,8 +235,9 @@ function run-dir() {
status=0
$cmd "${options[@]}" "${script_options[@]}" "$@" &> ${prefix}pass || status=1
cd "$outdir"
go get &>> ${prefix}pass || status=1
if [[ $status -eq "0" ]]; then
go mod init &>> ${prefix}pass || status=1
go mod tidy &>> ${prefix}pass || status=1
go build &>> ${prefix}pass || status=1
fi
if [[ $status -eq "1" ]]; then
Expand All @@ -238,7 +248,7 @@ function run-dir() {
perModelTemplate: mustTemplate("goyang-ygot", `run-dir "{{ .ModelDirName }}" "{{ .ModelName }}" {{- range $i, $buildFile := .BuildFiles }} {{ $buildFile }} {{- end }} {{- if .Parallel }} & {{- end }}
`),
},
"yanglint": &scriptSpec{
"yanglint": {
headerTemplate: mustTemplate("yanglint-header", `#!/bin/bash
workdir={{ .ResultsDir }}
mkdir -p "$workdir"
Expand All @@ -261,7 +271,7 @@ function run-dir() {
perModelTemplate: mustTemplate("yanglint", `run-dir "{{ .ModelDirName }}" "{{ .ModelName }}" {{- range $i, $buildFile := .BuildFiles }} {{ $buildFile }} {{- end }} {{- if .Parallel }} & {{- end }}
`),
},
"confd": &scriptSpec{
"confd": {
headerTemplate: mustTemplate("confd-header", `#!/bin/bash
workdir={{ .ResultsDir }}
mkdir -p "$workdir"
Expand All @@ -275,7 +285,7 @@ if [[ $status -eq "1" ]]; then
fi
`),
},
"misc-checks": &scriptSpec{
"misc-checks": {
headerTemplate: mustTemplate("misc-checks-header", `#!/bin/bash
workdir={{ .ResultsDir }}
mkdir -p "$workdir"
Expand Down Expand Up @@ -341,6 +351,7 @@ type labelPoster interface {
// will be run only on a single model as specified in the .spec.yml file.
// 2. Thus, a validation command and result is provided for each model.
// 3. A file indicating pass/fail is output for each model into the given result directory.
//
// Files names follow the "modelDir==model==status" format with no file extensions.
// The local flag indicates to run this as a helper to generate the script,
// rather than running it within GCB.
Expand Down Expand Up @@ -461,7 +472,7 @@ func main() {
// If it's a push on master, just upload badge for normal validators as the only action.
if prNumber == 0 {
if branchName != "master" {
log.Fatalf("cmd_gen: There is no action to take for a non-master branch push, please re-examine your push triggers")
log.Fatalf("cmd_gen: pr-number not supplied as a flag to the build. Try re-running (by commenting \"/gcbrun\" on the GitHub PR) to see whether the $_PR_NUMBER substitution variable for Google Cloud Build gets passed into the build. If this branch is not associated with a PR, then it is inferred that this is a non-master branch push action, and thus there is no CI action that is expected, and in this case please re-examine your push triggers.")
}
pushToMaster = true
}
Expand Down
30 changes: 20 additions & 10 deletions cmd_gen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ script_options=(
function run-dir() {
declare prefix="$workdir"/"$1"=="$2"==
shift 2
echo $cmd "${options[@]}" "$@" > ${prefix}cmd
echo pyang "${options[@]}" "$@" > ${prefix}cmd
if ! $($cmd "${options[@]}" "${script_options[@]}" "$@" &> ${prefix}pass); then
mv ${prefix}pass ${prefix}fail
fi
Expand Down Expand Up @@ -97,7 +97,7 @@ script_options=(
function run-dir() {
declare prefix="$workdir"/"$1"=="$2"==
shift 2
echo $cmd "${options[@]}" "$@" > ${prefix}cmd
echo pyang "${options[@]}" "$@" > ${prefix}cmd
if ! $($cmd "${options[@]}" "${script_options[@]}" "$@" &> ${prefix}pass); then
mv ${prefix}pass ${prefix}fail
fi
Expand All @@ -116,18 +116,20 @@ mkdir -p "$workdir"
PYANG_MSG_TEMPLATE='messages:{{path:"{file}" line:{line} code:"{code}" type:"{type}" level:{level} message:'"'{msg}'}}"
cmd="$@"
options=(
-p testdata
-p /workspace/third_party/ietf
--openconfig
--ignore-error=OC_RELATIVE_PATH
-p testdata
-p /workspace/third_party/ietf
)
script_options=(
--msg-template "$PYANG_MSG_TEMPLATE"
)
function run-dir() {
declare prefix="$workdir"/"$1"=="$2"==
local cmd_display_options=( --plugindir '$OCPYANG_PLUGIN_DIR' "${options[@]}" )
local options=( --plugindir "$OCPYANG_PLUGIN_DIR" "${options[@]}" )
shift 2
echo $cmd "${options[@]}" "$@" > ${prefix}cmd
echo pyang "${cmd_display_options[@]}" "$@" > ${prefix}cmd
if ! $($cmd "${options[@]}" "${script_options[@]}" "$@" &> ${prefix}pass); then
mv ${prefix}pass ${prefix}fail
fi
Expand All @@ -147,19 +149,26 @@ mkdir -p "$workdir"
PYANG_MSG_TEMPLATE='messages:{{path:"{file}" line:{line} code:"{code}" type:"{type}" level:{level} message:'"'{msg}'}}"
cmd="$@"
options=(
-f pybind
-p testdata
-p /workspace/third_party/ietf
-f pybind
)
script_options=(
--msg-template "$PYANG_MSG_TEMPLATE"
)
function run-dir() {
declare prefix="$workdir"/"$1"=="$2"==
local options=( -o "$1"."$2".binding.py "${options[@]}" )
local output_file="$1"."$2".binding.py
local cmd_display_options=( --plugindir '$PYANGBIND_PLUGIN_DIR' -o "${output_file}" "${options[@]}" )
local options=( --plugindir "$PYANGBIND_PLUGIN_DIR" -o "${output_file}" "${options[@]}" )
shift 2
echo $cmd "${options[@]}" "$@" > ${prefix}cmd
if ! $($cmd "${options[@]}" "${script_options[@]}" "$@" &> ${prefix}pass); then
echo pyang "${cmd_display_options[@]}" "$@" > ${prefix}cmd
status=0
$cmd "${options[@]}" "${script_options[@]}" "$@" &> ${prefix}pass || status=1
if [[ $status -eq "0" ]]; then
python "${output_file}" &>> ${prefix}pass || status=1
fi
if [[ $status -eq "1" ]]; then
mv ${prefix}pass ${prefix}fail
fi
}
Expand Down Expand Up @@ -196,8 +205,9 @@ function run-dir() {
status=0
$cmd "${options[@]}" "${script_options[@]}" "$@" &> ${prefix}pass || status=1
cd "$outdir"
go get &>> ${prefix}pass || status=1
if [[ $status -eq "0" ]]; then
go mod init &>> ${prefix}pass || status=1
go mod tidy &>> ${prefix}pass || status=1
go build &>> ${prefix}pass || status=1
fi
if [[ $status -eq "1" ]]; then
Expand Down
14 changes: 14 additions & 0 deletions cmd_gen/testdata/acl/.spec.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

- name: openconfig-acl
docs:
- yang/acl/openconfig-packet-match-types.yang
Expand Down
14 changes: 14 additions & 0 deletions cmd_gen/testdata/optical-transport/.spec.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

- name: openconfig-terminal-device
docs:
- yang/optical-transport/openconfig-transport-types.yang
Expand Down
Loading

0 comments on commit aa1ed2f

Please sign in to comment.