Skip to content

Commit

Permalink
Extract license check from integration tests (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ikryvanos authored Aug 27, 2024
1 parent 4d1444b commit e7ef4fa
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 26 deletions.
15 changes: 10 additions & 5 deletions .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ jobs:
go-version-file: 'go.mod'
- uses: actions/setup-python@v3
- uses: pre-commit/action@v3.0.0
unit_test:
chack_license:
name: Check license
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Check license in project files
run: ./scripts/check-license.sh
shell: bash
test:
name: Unit tests
runs-on: ubuntu-20.04
steps:
Expand All @@ -37,11 +45,8 @@ jobs:
- name: integration bash tests
run: ./testing/integrate.sh
shell: bash
- name: integration tests
run: go test -tags=integration ./...
shell: bash
integration_test:
name: Unit tests
name: Integration tests
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ repos:
- id: go-fmt
- id: go-build
- id: go-mod-tidy
- repo: local
hooks:
- id: check-license
name: check-license
entry: scripts/check-license.sh
language: script
pass_filenames: false
- repo: https://github.com/golangci/golangci-lint
rev: v1.59.1
hooks:
Expand Down
71 changes: 71 additions & 0 deletions scripts/check-license.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env bash

# Copyright (c) 2019 Snowflake Inc. All rights reserved.
#
# 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.

set -o nounset

function create_tempfile() {
tempprefix=$(basename "$0")
mktemp /tmp/${tempprefix}.XXXXXX
}


# check_status takes 3 args:
#
# A code to compare against
# Logfile to print on error
# Any text to output on failure (all remaining args).
function check_status {
STATUS=$1
shift
LOG=$1
shift
FAIL=$*

if [ "${STATUS}" != 0 ]; then
{
echo "FAIL ${FAIL}"
} >&2
if [ "${LOG}" != "/dev/null" ]; then
ls "${LOGS}"
print_logs "${LOG}" "${FAIL}"
fi
exit 1
fi
}

license_go_files=$(create_tempfile)
license_proto_files=$(create_tempfile)

# Check licensing
# For Go we can ignore generate protobuf files.
find . -type f -name \*.go ! -name \*.pb.go >"${license_go_files}"
find . -type f -name \*.proto >"${license_proto_files}"

cat "${license_go_files}" "${license_proto_files}" | (
broke=""
while read -r i; do
if ! grep -q "Licensed under the Apache License" ${i}; then
echo "${i} is missing required license."
broke=true
fi
done

if [ "${broke}" == "true" ]; then
exit 1
fi
)
check_status $? /dev/null Files missing license
21 changes: 0 additions & 21 deletions testing/integrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -263,27 +263,6 @@ cd "${dir}/.." || {
echo "package sansshell.authz" >${LOGS}/policy
echo "default allow = true" >>${LOGS}/policy

# Check licensing
# For Go we can ignore generate protobuf files.
find . -type f -name \*.go ! -name \*.pb.go >${LOGS}/license-go
find . -type f -name \*.sh >${LOGS}/license-sh
find . -type f -name \*.proto >${LOGS}/license-proto

cat "${LOGS}/license-go" "${LOGS}/license-proto" | (
broke=""
while read -r i; do
if ! grep -q "Licensed under the Apache License" ${i}; then
echo "${i} is missing required license."
broke=true
fi
done

if [ "${broke}" == "true" ]; then
exit 1
fi
)
check_status $? /dev/null Files missing license

echo
echo "Checking with go vet"
echo
Expand Down

0 comments on commit e7ef4fa

Please sign in to comment.