forked from openconfig/featureprofiles
-
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.
This reverts commit 4501274.
- Loading branch information
Showing
7 changed files
with
419 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: Go | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
schedule: | ||
- cron: "0 0 * * *" | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Go | ||
uses: actions/setup-go@v2.1.3 | ||
with: | ||
go-version: 1.19.x | ||
- name: Cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: | | ||
~/go/pkg/mod | ||
~/.cache/go-build | ||
key: ${{ github.job }}-${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} | ||
restore-keys: ${{ github.job }}-${{ runner.os }}-go-build- | ||
- name: Build | ||
run: go build -v ./... | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Go | ||
uses: actions/setup-go@v2.1.3 | ||
with: | ||
go-version: 1.19.x | ||
- name: Cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: | | ||
~/go/pkg/mod | ||
~/.cache/go-build | ||
key: ${{ github.job }}-${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} | ||
restore-keys: ${{ github.job }}-${{ runner.os }}-go-build- | ||
- run: go test -v -coverprofile=profile.cov $(go list ./... | grep -v /.*test.*) | ||
- name: Send coverage | ||
uses: shogo82148/actions-goveralls@v1 | ||
with: | ||
path-to-profile: profile.cov |
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,121 @@ | ||
name: Protobufs | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
schedule: | ||
- cron: "0 0 * * *" | ||
|
||
jobs: | ||
validate_protobufs: | ||
name: Validate Protobufs | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: '1.19' | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/go/pkg/mod | ||
~/.cache/go-build | ||
key: ${{ github.job }}-${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} | ||
restore-keys: ${{ github.job }}-${{ runner.os }}-go-build- | ||
- name: Install protobuf | ||
uses: arduino/setup-protoc@v1 | ||
with: | ||
version: '3.x' | ||
repo-token: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Lint protobufs | ||
run: | | ||
go install github.com/googleapis/api-linter/cmd/api-linter@latest | ||
# Set directory to hold symlink | ||
readonly PROTOBUF_IMPORT_DIR='protobuf-import' | ||
mkdir -p "${PROTOBUF_IMPORT_DIR}" | ||
# Remove any existing symlinks & empty directories | ||
find "${PROTOBUF_IMPORT_DIR}" -type l -delete | ||
find "${PROTOBUF_IMPORT_DIR}" -type d -empty -delete | ||
# Download the required dependencies | ||
go mod download | ||
# Get ondatra modules we use and create required directory structure | ||
go list -f "${PROTOBUF_IMPORT_DIR}/{{ .Path }}" -m github.com/openconfig/ondatra | xargs -L1 dirname | sort | uniq | xargs mkdir -p | ||
# Create symlink | ||
go list -f "{{ .Dir }} "${PROTOBUF_IMPORT_DIR}"/{{ .Path }}" -m github.com/openconfig/ondatra | xargs -L1 -- ln -s | ||
find . -name \*.proto -exec api-linter -I./"${PROTOBUF_IMPORT_DIR}" --disable-rule all --enable-rule core {} \+ | ||
- name: Compile topology binding textprotos | ||
run: | | ||
fail=0 | ||
# Set directory to hold symlink | ||
readonly PROTOBUF_IMPORT_DIR='protobuf-import' | ||
mkdir -p "${PROTOBUF_IMPORT_DIR}" | ||
# Remove any existing symlinks & empty directories | ||
find "${PROTOBUF_IMPORT_DIR}" -type l -delete | ||
find "${PROTOBUF_IMPORT_DIR}" -type d -empty -delete | ||
# Download the required dependencies | ||
go mod download | ||
# Get ondatra modules we use and create required directory structure | ||
go list -f "${PROTOBUF_IMPORT_DIR}/{{ .Path }}" -m github.com/openconfig/ondatra | xargs -L1 dirname | sort | uniq | xargs mkdir -p | ||
# Create symlink | ||
go list -f "{{ .Dir }} \"${PROTOBUF_IMPORT_DIR}\"/{{ .Path }}" -m github.com/openconfig/ondatra | xargs -L1 -- ln -s | ||
for i in `find topologies/ -type f -name "*.binding"`; do | ||
if ! output=$(protoc -I="${PROTOBUF_IMPORT_DIR}" --proto_path=topologies/proto --encode=openconfig.testing.Binding topologies/proto/binding.proto < $i 2>&1 >/dev/null); then | ||
fail=1 | ||
echo -e "Compile $i failed:\n$output\n" | ||
fi | ||
done | ||
if [ "$fail" == "1" ]; then exit 1; fi | ||
- name: Compile feature profile textprotos | ||
run: | | ||
fail=0 | ||
for i in `find feature/ -type f -name "feature.textproto"`; do | ||
if ! output=$(protoc --encode=openconfig.profiles.FeatureProfile proto/feature.proto < $i 2>&1 >/dev/null); then | ||
fail=1 | ||
echo -e "Compile $i failed:\n$output\n" | ||
fi | ||
done | ||
if [ "$fail" == "1" ]; then exit 1; fi | ||
validate_oc_paths: | ||
name: Validate OpenConfig Paths | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: '1.19' | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: | | ||
~/go/pkg/mod | ||
~/.cache/go-build | ||
key: ${{ github.job }}-${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} | ||
restore-keys: ${{ github.job }}-${{ runner.os }}-go-build- | ||
- name: Fetch Openconfig Models | ||
run: make openconfig_public | ||
- name: Validate Paths | ||
run: | | ||
# https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables | ||
if [ ! -z "${GITHUB_BASE_REF}" ]; then | ||
readonly HEAD=${{ github.event.pull_request.head.sha }} | ||
readonly BASE="$(git merge-base origin/main "${HEAD}")" | ||
if ! git diff --diff-filter=D --name-only "${BASE}" | grep -E 'feature.textproto$'; then | ||
# If it is a pull request AND if no feature.textproto files were | ||
# deleted, then we can skip checking all but the added/modified | ||
# feature.textproto files. | ||
export FEATURE_FILES=changed-feature-textprotos.githubactions.txt | ||
# grep: don't error out on no match. | ||
git diff --diff-filter=d --name-only "${BASE}" | { grep -E 'feature.textproto$' || true; } > "${FEATURE_FILES}" | ||
fi | ||
fi | ||
make validate_paths | ||
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,109 @@ | ||
name: Pull Request | ||
on: [pull_request] | ||
jobs: | ||
check_style: | ||
name: Check style against CONTRIBUTING.md | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup Perl | ||
uses: perl-actions/install-with-cpanm@v1 | ||
with: | ||
install: | | ||
Net::IP | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: IP Addresses Assignment | ||
run: | | ||
find . -name \*.go -exec ./tools/check_ip_addresses.pl \{} + | ||
- name: Allowed File Types | ||
run: ./tools/allowed_file_types.sh | ||
- name: Enum | ||
run: | | ||
fail=0 | ||
if find . -name \*.go -exec egrep -n '\.Union.*?\([0-9]+\)' \{} + | ||
then | ||
echo "Please do not use numerical constants in a union." >&2 | ||
echo "See CONTRIBUTING.md#enum" >&2 | ||
fail=1 | ||
fi | ||
if find . -name \*.go -exec egrep -n '_Union\([0-9]+\)' \{} + | ||
then | ||
echo "Please do not use numerical constants in a union." >&2 | ||
echo "See CONTRIBUTING.md#enum" >&2 | ||
fail=1 | ||
fi | ||
exit "${fail}" | ||
- name: Default NetworkInstance | ||
run: | | ||
if find . -name \*.go -exec egrep -n '"default"' \{} + | ||
then | ||
echo "Default network instance name should be uppercase." >&2 | ||
echo "See CONTRIBUTING.md#default-network-instance" >&2 | ||
exit 1 | ||
fi | ||
static_analysis: | ||
name: Static Analysis | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Install go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: '1.19' | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: | | ||
~/go/pkg/mod | ||
~/.cache/go-build | ||
~/.cache/staticcheck | ||
key: ${{ github.job }}-${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} | ||
restore-keys: ${{ github.job }}-${{ runner.os }}-go-build- | ||
- name: Go vet | ||
run: GOGC=30 go vet ./... | ||
- name: Gofmt | ||
run: | | ||
# gofmt always returns true, so we use grep '^' which returns | ||
# true on non-empty output, but will otherwise passthrough all | ||
# output lines. | ||
if gofmt -d -s . | grep '^'; then | ||
exit 1 | ||
fi | ||
- name: Get goimports | ||
run: go install golang.org/x/tools/cmd/goimports@latest | ||
- name: Goimports | ||
run: | | ||
# goimports always returns true, so we use grep '^' which returns | ||
# true on non-empty output, but will otherwise passthrough all | ||
# output lines. | ||
# | ||
# goimports does not support "gofmt -s" so both goimports and gofmt are | ||
# required. | ||
if goimports -d . | grep '^'; then | ||
exit 1 | ||
fi | ||
- name: Get revive | ||
run: go install github.com/mgechev/revive@latest | ||
- name: Run revive | ||
run: revive ./... | ||
- name: Get staticcheck | ||
run: go install honnef.co/go/tools/cmd/staticcheck@latest | ||
- name: Run staticcheck | ||
run: GOGC=30 staticcheck ./... | ||
|
||
otg_changes: | ||
name: OTG Changes Required | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Check if OTG changes required | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
const script = require('./.github/workflows/required_otg_changes_check.js') | ||
await script({github, context, core}) |
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,49 @@ | ||
name: Rebase Check | ||
on: [pull_request] | ||
|
||
jobs: | ||
check_files: | ||
name: Check for outdated files | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout PR | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Check if dependencies and checks are up to date. | ||
run: | | ||
readonly -a CHECKED_FILES=( | ||
go.mod | ||
.github/CODEOWNERS | ||
.github/workflows/ | ||
) | ||
# Notes: | ||
# * Do not use ${GITHUB_REF}, github.sha, or HEAD because they are | ||
# the merged commit of the pull request and main. There are no | ||
# outdated files in the merged commit. | ||
# * refs/pull/${pr_number}/head is not available, so use | ||
# github.event.pull_request.head.sha which is the "head sha" of | ||
# the event that triggered the pull request. | ||
# * Do not use github.event.pull_request.base.sha because it is | ||
# the base when the pull request was created, not after a rebase. | ||
# Ask git merge-base to tell us a suitable base. | ||
readonly HEAD="${{ github.event.pull_request.head.sha }}" | ||
readonly BASE="$(git merge-base origin/main "${HEAD}")" | ||
# Notes: | ||
# * Diff between "${BASE}" and origin/main detects outdated files. | ||
# * Diff between "${BASE}" and "${HEAD}" detects files changed by PR. | ||
# * Merge conflict between "${HEAD}" and main is not detected here, | ||
# but GitHub will prevent merging if that's the case. | ||
# * comm -23 SET1 SET2 shows what's in SET1 and not in SET2. | ||
outdated_unchanged="$( | ||
comm -23 \ | ||
<(git diff --name-only "${BASE}" origin/main -- "${CHECKED_FILES[@]}" | sort) \ | ||
<(git diff --name-only "${BASE}" "${HEAD}" -- "${CHECKED_FILES[@]}" | sort) | ||
)" | ||
if [ "${outdated_unchanged}" ]; then | ||
echo "The following files are outdated: ${outdated_unchanged}" | ||
echo "Please rebase your pull request to main and rerun checks." | ||
exit 1 | ||
fi |
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,32 @@ | ||
module.exports = async ({github, context, core}) => { | ||
// Get all files in the repository in the 'main' branch | ||
const fpFiles = new Set(); | ||
const rspGetTree = await github.rest.git.getTree({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
tree_sha: 'main', | ||
recursive: true | ||
}); | ||
rspGetTree.data.tree.forEach(t => fpFiles.add(t.path)) | ||
// Get all changed files in a pull request | ||
const listFiles = github.rest.pulls.listFiles.endpoint.merge({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: context.payload.pull_request.number | ||
}); | ||
const changedFiles = new Set(); | ||
const rspListFiles = await github.paginate(listFiles); | ||
rspListFiles.forEach(f => changedFiles.add(f.filename)); | ||
changedFiles.forEach(file => { | ||
console.log('Found changed file: ' + file); | ||
if (file.includes('ate_tests')) { | ||
const otgFile = file.replace('ate_tests', 'otg_tests'); | ||
if (fpFiles.has(otgFile)) { | ||
console.log('Found matching OTG file: ' + otgFile); | ||
if (!changedFiles.has(otgFile)) { | ||
core.setFailed(otgFile + ' needs to be updated to match ' + file) | ||
} | ||
} | ||
} | ||
}) | ||
} |
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,12 @@ | ||
name: Rundata Check | ||
on: [pull_request] | ||
|
||
jobs: | ||
check_rundata: | ||
name: Check for Rundata | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout PR | ||
uses: actions/checkout@v3 | ||
- name: Check that addrundata is up to date. | ||
run: go run ./tools/addrundata |
Oops, something went wrong.