Skip to content

Check AGPL code doesn't import enterprise #3602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/coder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ jobs:
with:
version: v1.46.0

check-enterprise-imports:
name: check/enterprise-imports
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check imports of enterprise code
run: ./scripts/check_enterprise_imports.sh

style-lint-shellcheck:
name: style/lint/shellcheck
timeout-minutes: 5
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ lint: lint/shellcheck lint/go
.PHONY: lint

lint/go:
./scripts/check_enterprise_imports.sh
golangci-lint run
.PHONY: lint/go

Expand Down
19 changes: 19 additions & 0 deletions scripts/check_enterprise_imports.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

# This file checks all our AGPL licensed source files to be sure they don't
# import any enterprise licensed packages (the inverse is fine).

set -euo pipefail
# shellcheck source=scripts/lib.sh
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
cdroot

set +e
find . -regex ".*\.go" | grep -v "./enterprise" | xargs grep -n "github.com/coder/coder/enterprise"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
find . -regex ".*\.go" | grep -v "./enterprise" | xargs grep -n "github.com/coder/coder/enterprise"
find . -name ./enterprise -prune -o -name '*.go' -print0 | xargs -0 grep -n "github.com/coder/coder/enterprise"

Not at a computer; so can’t test. But use if you want. Silly tool optimization. This even handles spaces in names which isn’t ever going to be a problem with Go source files 🤪

# reverse the exit code because we want this script to fail if grep finds anything.
status=$?
set -e
if [ $status -eq 0 ]; then
error "AGPL code cannot import enterprise!"
fi
log "AGPL imports OK"