Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 13 additions & 0 deletions .github/licenses.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# GitHub CLI dependencies

The following open source dependencies are used to build the [cli/cli][] GitHub CLI.

## Go Packages

Some packages may only be included on certain architectures or operating systems.

{{ range . }}
- [{{.Name}}](https://pkg.go.dev/{{.Name}}) ([{{.LicenseName}}]({{.LicenseURL}}))
{{- end }}

[cli/cli]: https://github.com/cli/cli
13 changes: 13 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ on:
- "**.go"
- go.mod
- go.sum
- ".github/licenses.tmpl"
- "script/licenses*"
pull_request:
paths:
- "**.go"
- go.mod
- go.sum
- ".github/licenses.tmpl"
- "script/licenses*"

permissions:
contents: read
Expand Down Expand Up @@ -46,3 +50,12 @@ jobs:
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
with:
version: v2.1.6

# actions/setup-go does not setup the installed toolchain to be preferred over the system install,
# which causes go-licenses to raise "Package ... does not have module info" errors.
# for more information, https://github.com/google/go-licenses/issues/244#issuecomment-1885098633
- name: Check licenses
run: |
export GOROOT=$(go env GOROOT)
export PATH=${GOROOT}/bin:$PATH
make licenses-check
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,11 @@ ifndef VERSION
endif
./script/release --local "$(VERSION)" --platform macos
./script/pkgmacos $(VERSION)

.PHONY: licenses
licenses:
./script/licenses

.PHONY: licenses-check
licenses-check:
./script/licenses-check
46 changes: 46 additions & 0 deletions docs/license-compliance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# License Compliance

GitHub CLI complies with the software licenses of its dependencies. This document explains how license compliance is maintained.

## Overview

When a dependency is added or updated, the license information needs to be updated. We use the [`google/go-licenses`](https://github.com/google/go-licenses) tool to:

1. Generate markdown documentation listing all Go dependencies and their licenses
2. Copy license files for dependencies that require redistribution

## License Files

The following files contain license information:

- `third-party-licenses.darwin.md` - License information for macOS dependencies
- `third-party-licenses.linux.md` - License information for Linux dependencies
- `third-party-licenses.windows.md` - License information for Windows dependencies
- `third-party/` - Directory containing source code and license files that require redistribution

## Updating License Information

When dependencies change, you need to update the license information:

1. Update license information for all platforms:

```shell
make licenses
```

2. Commit the changes:

```shell
git add third-party-licenses.*.md third-party/
git commit -m "Update third-party license information"
```

## Checking License Compliance

The CI workflow checks if license information is up to date. To check locally:

```sh
make licenses-check
```

If the check fails, follow the instructions to update the license information.
25 changes: 25 additions & 0 deletions script/licenses
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

go install github.com/google/go-licenses@latest
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Question: Are we comfortable with always using the latest here, or should we pin to a sha for stability/security etc?

I know that pinning comes with the "when does this get updated then?" question, and I don't know the answer to that either :P

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess this is especially in my mind with this script being used in actions... 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@BagToad : what do you think about conditionalizing this to skip installing this if CI, leaving that to the workflow?

otherwise, everything running the script has to manage its installation. conditionalizing it will make it easy for contributors and maintainers.


# Setup temporary directory to collect updated third-party source code
export TEMPDIR="$(mktemp -d)"
trap "rm -fr ${TEMPDIR}" EXIT
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(praise) Smart!


# Clear third-party source code to avoid stale content
rm -rf third-party
mkdir -p third-party

Comment on lines +9 to +12
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Question: Should we check successes (exit codes) here? Are we okay with this maybe failing but then continuing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not worried about these commands failing, but if there is a concern then we might want to set -e so any errors cause the whole script to fail.

for goos in linux darwin windows ; do
# Note: we ignore warnings because we want the command to succeed, however the output should be checked
# for any new warnings, and potentially we may need to add license information.
#
# Normally these warnings are packages containing non go code, which may or may not require explicit attribution,
# depending on the license.
echo "Generating licenses for ${goos}..."
GOOS="${goos}" go-licenses save ./... --save_path="${TEMPDIR}/${goos}" --force || echo "Ignore warnings"
GOOS="${goos}" go-licenses report ./... --template .github/licenses.tmpl --ignore github.com/cli/cli > third-party-licenses.${goos}.md || echo "Ignore warnings"
cp -fR "${TEMPDIR}/${goos}"/* third-party/
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Question: Similar question here - should we check exit codes here or keep going even if something failed?

done

echo "Licenses generated for all platforms."
23 changes: 23 additions & 0 deletions script/licenses-check
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

go install github.com/google/go-licenses@latest

# Setup temporary directory for generated license reports
export TEMPDIR="$(mktemp -d)"
trap "rm -fr ${TEMPDIR}" EXIT

for goos in linux darwin windows ; do
# Note: we ignore warnings because we want the command to succeed, however the output should be checked
# for any new warnings, and potentially we may need to add license information.
#
# Normally these warnings are packages containing non go code, which may or may not require explicit attribution,
# depending on the license.
echo "Checking licenses for ${goos}..."
GOOS="${goos}" go-licenses report ./... --template .github/licenses.tmpl --ignore github.com/cli/cli > "${TEMPDIR}/third-party-licenses.${goos}.md" || echo "Ignore warnings"
if ! diff -s "${TEMPDIR}/third-party-licenses.${goos}.md" "third-party-licenses.${goos}.md"; then
echo "::error title=License check failed::Please update the license files by running \`make licenses\` and committing the output."
exit 1
fi
done

echo "License check passed for all platforms."
Loading
Loading