Skip to content
Merged
12 changes: 12 additions & 0 deletions .github/instructions/license-range-review.instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
description: "Use when reviewing generated SPDX license range changes, especially additions or removals of complete license range families."
applyTo: "spdxexp/spdxlicenses/license_ranges.go"
---

# License Range Family Review

- Treat the addition or removal of a complete license range family as requiring human review.
- Always leave an inline review comment on the added or removed family block, or on the nearest changed line when the family was removed. Start the comment with **Human review required: license range family changed** and identify the family.
- Ask the human reviewer to verify that the family change is intended and that its version grouping and ordering are correct.
- Compare the diff with the **License range families** summary in the pull request description and report any discrepancy.
- Do not leave this comment for a version added to or removed from an existing family unless the grouping or ordering is incorrect.
10 changes: 9 additions & 1 deletion .github/workflows/fetch-licenses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ on:
jobs:
fetch-licenses:
runs-on: ubuntu-latest
env:
DT_STAMP: ''
GENFILES_CHANGED: 'false'
SRC_CHANGED: 'false'
permissions:
contents: write
pull-requests: write
Expand Down Expand Up @@ -84,6 +88,10 @@ jobs:
fi
echo "GENFILES_CHANGED=$genfiles_changed" >> $GITHUB_ENV

- name: Generate Pull Request description
if: ${{ env.GENFILES_CHANGED == 'true' || github.event.inputs.force_run == 'true' }}
run: go run ./cmd pr-body -o "${RUNNER_TEMP}/license-pr-body.md"

- name: Create Pull Request
if: ${{ env.GENFILES_CHANGED == 'true' || github.event.inputs.force_run == 'true' }}
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1
Expand All @@ -93,5 +101,5 @@ jobs:
branch: auto-update-licenses
base: main
title: "Update SPDX license files (${{ env.DT_STAMP }})"
body: "The files in this PR are auto-generated by the [fetch-licenses](./.git/workflows/fetch-license.yaml) workflow when it runs the `extract` command defined in [cmd/main.go](./cmd/main.go). It updates SPDX licenses based on the latest released set in the [spdx/license-list-data](https://github.com/spdx/license-list-data) repository maintained by [SPDX](https://spdx.org/licenses/). \n\nTODO: [spdxexp/spdxlicenses/license_ranges.go](./spdxexp/spdxlicenses/license_range.go) has to be updated manually."
body-path: ${{ runner.temp }}/license-pr-body.md
labels: 'auto-update,licenses'
7 changes: 3 additions & 4 deletions cmd/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ The source data needs to be manually updated by copying the licenses.json file f
https://github.com/spdx/license-list-data/blob/main/json/licenses.json and exceptions.json
file from https://github.com/spdx/license-list-data/blob/main/json/exceptions.json.

After running the extract command, the license_ids.json, deprecated_ids.json, and exception_ids.json
files will be overwritten with the extracted ids. These license ids can then be used to update the
spdxexp/license.go file.
After running the extract command, the generated license, deprecated license, exception, and license
range Go files in spdxexp/spdxlicenses will be overwritten with data derived from the SPDX license list.

Command to run all extractions (run command from the /cmd directory):

Expand All @@ -16,7 +15,7 @@ Command to run all extractions (run command from the /cmd directory):
Usage options:

-h: prints this help message
-l: Extract license ids
-l: Extract licenses and ranges
-e: Extract exception ids
*/
package main
22 changes: 15 additions & 7 deletions cmd/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ type License struct {
IsOsiApproved bool `json:"isOsiApproved"`
}

// extractLicenseIDs reads the official licenses.json file copied from spdx/license-list-data
// and writes two files, license_ids.json and deprecated_license_ids.json, containing just
// the license IDs and deprecated license IDs, respectively. It returns an error if it
// encounters one.
func extractLicenseIDs() error {
// extractLicenses reads the official licenses.json file copied from spdx/license-list-data
// and generates the active license, deprecated license, and license range Go files.
func extractLicenses() error {
// open file
file, err := os.Open("licenses.json")
if err != nil {
Expand Down Expand Up @@ -56,13 +54,19 @@ func extractLicenseIDs() error {
}

// generate the GetLicenses() function in get_licenses.go
getLicensesContents := []byte(`package spdxlicenses
getLicensesContents := fmt.Appendf(nil, `package spdxlicenses

// Code generated by go-spdx cmd/license.go. DO NOT EDIT.
// Source: https://github.com/spdx/license-list-data specifies official SPDX license list.

import "strings"

// LicenseListVersion returns the SPDX License List version from which the
// generated license IDs were sourced.
func LicenseListVersion() string {
return %q
}

// IsActiveLicense does a case-insensitive lookup for the license id in the active licenses map.
// It returns true and the case-sensitive ID if found, otherwise false and the original id.
func IsActiveLicense(id string) (bool, string) {
Expand All @@ -85,7 +89,7 @@ func GetLicensesMap() map[string]string {
// GetLicenses returns a slice of active license IDs.
func GetLicenses() []string {
return []string{
`)
`, licenseData.Version)
for _, id := range activeLicenseIDs {
getLicensesContents = append(getLicensesContents, ` "`+id+`",
`...)
Expand Down Expand Up @@ -175,5 +179,9 @@ func GetDeprecated() []string {
}
fmt.Println("Writing `../spdxexp/spdxlicenses/get_deprecated.go`... COMPLETE")

if err := generateLicenseRanges(licenseData.Licenses, "../spdxexp/spdxlicenses/license_ranges.go"); err != nil {
return fmt.Errorf("generate license ranges: %w", err)
}

return nil
}
191 changes: 191 additions & 0 deletions cmd/license_ranges.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading