Skip to content

Add CI workflow to check for unapproved Go dependency licenses #135

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 3 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add CI workflow to check for unapproved Go dependency licenses
A task and GitHub Actions workflow are provided here for checking the license types of Go project dependencies.

On every push and pull request that affects relevant files, the CI workflow will check:

- If the dependency licenses cache is up to date
- If any of the project's dependencies have an unapproved license type.

Approval can be based on:

- Universally allowed license type
- Individual dependency
  • Loading branch information
per1234 committed Aug 11, 2022
commit 435d59b6a6a518e5603038c58a4e9d1015d256bb
140 changes: 140 additions & 0 deletions .github/workflows/check-go-dependencies-task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-go-dependencies-task.md
name: Check Go Dependencies

env:
# See: https://github.com/actions/setup-go/tree/main#supported-version-syntax
GO_VERSION: "1.18.3"

# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
on:
create:
push:
paths:
- ".github/workflows/check-go-dependencies-task.ya?ml"
- ".licenses/**"
- ".licensed.json"
- ".licensed.ya?ml"
- "Taskfile.ya?ml"
- "**/.gitmodules"
- "**/go.mod"
- "**/go.sum"
pull_request:
paths:
- ".github/workflows/check-go-dependencies-task.ya?ml"
- ".licenses/**"
- ".licensed.json"
- ".licensed.ya?ml"
- "Taskfile.ya?ml"
- "**/.gitmodules"
- "**/go.mod"
- "**/go.sum"
schedule:
# Run periodically to catch breakage caused by external changes.
- cron: "0 8 * * WED"
workflow_dispatch:
repository_dispatch:

jobs:
run-determination:
runs-on: ubuntu-latest
outputs:
result: ${{ steps.determination.outputs.result }}
steps:
- name: Determine if the rest of the workflow should run
id: determination
run: |
RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
# The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
if [[
"${{ github.event_name }}" != "create" ||
"${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
]]; then
# Run the other jobs.
RESULT="true"
else
# There is no need to run the other jobs.
RESULT="false"
fi

echo "::set-output name=result::$RESULT"

check-cache:
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive

- name: Install licensed
uses: jonabc/setup-licensed@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}

- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Update dependencies license metadata cache
run: task --silent general:cache-dep-licenses

- name: Check for outdated cache
id: diff
run: |
git add .
if ! git diff --cached --color --exit-code; then
echo
echo "::error::Dependency license metadata out of sync. See: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-go-dependencies-task.md#metadata-cache"
exit 1
fi

# Some might find it convenient to have CI generate the cache rather than setting up for it locally
- name: Upload cache to workflow artifact
if: failure() && steps.diff.outcome == 'failure'
uses: actions/upload-artifact@v3
with:
if-no-files-found: error
name: dep-licenses-cache
path: .licenses/

check-deps:
needs: run-determination
if: needs.run-determination.outputs.result == 'true'
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive

- name: Install licensed
uses: jonabc/setup-licensed@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}

- name: Install Task
uses: arduino/setup-task@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: 3.x

- name: Check for dependencies with unapproved licenses
run: task --silent general:check-dep-licenses
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.old
build.sh
arduino-language-server*
/arduino-language-server*
!/arduino-language-server*/
/node_modules/
68 changes: 68 additions & 0 deletions .licensed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# See: https://github.com/github/licensed/blob/master/docs/configuration.md
sources:
go: true

apps:
- source_path: ./

# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-dependencies/Apache-2.0/.licensed.yml
allowed:
# Based on https://www.apache.org/legal/resolved.html#category-a
- apache-2.0
- apache-1.1
- php-3.01
# "MX4J License" - no SPDX ID
- bsd-2-clause
- bsd-2-clause-netbsd # Deprecated ID for `bsd-2-clause`
- bsd-2-clause-views
- bsd-2-clause-freebsd # Deprecated ID for `bsd-2-clause-views`
- bsd-3-clause
- bsd-3-clause-clear
# "DOM4J License" - no SPDX ID
- postgresql
# "Eclipse Distribution License 1.0" - no SPDX ID
- mit
- x11
- isc
- smlnj
- standardml-nj # Deprecated ID for `smlnj`
# "Cup Parser Generator" - no SPDX ID
- icu
- ncsa
- w3c
# "W3C Community Contributor License Agreement" - no SPDX ID
- xnet
- zlib
# "FSF autoconf license" - no SPDX ID
- afl-3.0
# "Service+Component+Architecture+Specifications" - no SPDX ID
# "OOXML XSD ECMA License"
- ms-pl
- cc-pddc
- psf-2.0
# "Python Imaging Library Software License"
- apafml
- bsl-1.0
- ogl-uk-3.0
- wtfpl
- unicode-tou
- zpl-2.0
# "ACE license" - no SPDX ID
- upl-1.0
# "Open Grid Forum License" - no SPDX ID
# 'Google "Additional IP Rights Grant (Patents)" file' - no SPDX ID
- unlicense
- hpnd
- mulanpsl-2.0
- cc0-1.0
# Based on individual license text
- lgpl-2.0-or-later
- lgpl-2.0+ # Deprecated ID for `lgpl-2.0-or-later`
- lgpl-2.1-only
- lgpl-2.1 # Deprecated ID for `lgpl-2.1-only`
- lgpl-2.1-or-later
- lgpl-2.1+ # Deprecated ID for `lgpl-2.1-or-later`
- lgpl-3.0-only
- lgpl-3.0 # Deprecated ID for `lgpl-3.0-only`
- lgpl-3.0-or-later
- lgpl-3.0+ # Deprecated ID for `lgpl-3.0-or-later`
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[![Check Go status](https://github.com/arduino/arduino-language-server/actions/workflows/check-go-task.yml/badge.svg)](https://github.com/arduino/arduino-language-server/actions/workflows/check-go-task.yml)
[![Check Markdown status](https://github.com/arduino/arduino-language-server/actions/workflows/check-markdown-task.yml/badge.svg)](https://github.com/arduino/arduino-language-server/actions/workflows/check-markdown-task.yml)
[![Check License status](https://github.com/arduino/arduino-language-server/actions/workflows/check-license.yml/badge.svg)](https://github.com/arduino/arduino-language-server/actions/workflows/check-license.yml)
[![Check Go Dependencies status](https://github.com/arduino/arduino-language-server/actions/workflows/check-go-dependencies-task.yml/badge.svg)](https://github.com/arduino/arduino-language-server/actions/workflows/check-go-dependencies-task.yml)

The **Arduino Language Server** is the tool that powers the autocompletion of the new [Arduino IDE 2][arduino-ide-repo]. It implements the standard [Language Server Protocol](https://microsoft.github.io/language-server-protocol/) so it can be used with other IDEs as well.

Expand Down