-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The initial implementation of the SPDX go bindings
- Loading branch information
Showing
25 changed files
with
18,749 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
name: Test SPDX Go Bindings | ||
on: | ||
- push | ||
- pull_request | ||
- workflow_call | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
go-version: | ||
- "1.18" | ||
- "1.19" | ||
- "1.20" | ||
- "1.21" | ||
- "1.22" | ||
- "1.23" | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup Go ${{ matrix.go-version }} | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
- name: Install dependencies | ||
run: go get . | ||
- name: Run tests | ||
run: go test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,36 @@ | ||
# spdx-go-model-3 | ||
|
||
Generated Golang code for the SPDX Spec version 3 | ||
|
||
All bindings in this repository are generated using | ||
[shacl2code](https://github.com/JPEWdev/shacl2code) at the time the package is | ||
built with the `generate-bindings` script. The binding should not be manually | ||
edited. | ||
|
||
**NOTE:** The bindings are pretty low level, intended for more directly | ||
manipulating SPDX files. While they are fully functions, they lack higher level | ||
helper functions that may be useful for creating SPDX documents. If you want a | ||
higher level approach, please see the | ||
[SPDX Golang Tools](https://github.com/spdx/tools-golang) (however this repo | ||
doesn't yet support SPDX 3) | ||
|
||
## Usage | ||
|
||
Each version of the SPDX spec has a module named `v{MAJOR}_{MINOR}_{MICRO}` | ||
that contains the bindings for that version under the `github.com/spdx/spdx-go-model` | ||
top level modules. It is recommend you import this with an alias like: | ||
|
||
```golang | ||
import ( | ||
Spdx3_0_1 "github.com/spdx/spdx-go-model/v3_0_1" | ||
) | ||
|
||
... | ||
p := Spdx3_0_1.MakePerson() | ||
... | ||
``` | ||
|
||
## Testing | ||
|
||
This repository has support for running tests against the generated bindings using | ||
`go test`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#! /bin/sh | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
SPDX_VERSIONS="3.0.1" | ||
SHACL2CODE_VERSION="0.0.18" | ||
|
||
THIS_DIR="$(dirname "$0")" | ||
VENV_DIR="$(mktemp -d)" | ||
|
||
cd $THIS_DIR | ||
|
||
# Install shacl2code in a virtual environment | ||
python3 -m venv "$VENV_DIR" | ||
"$VENV_DIR/bin/pip" install -q "shacl2code==$SHACL2CODE_VERSION" | ||
|
||
# Remove existing go files in subdirectories | ||
find . -path './*/*.go' -delete | ||
|
||
for v in $SPDX_VERSIONS; do | ||
MODNAME="spdx_v$(echo "$v" | sed 's/[^a-zA-Z0-9_]/_/g')" | ||
rm -rf "$MODNAME" | ||
mkdir -p "$MODNAME" | ||
|
||
"$VENV_DIR/bin/shacl2code" generate \ | ||
--input https://spdx.org/rdf/$v/spdx-model.ttl \ | ||
--input https://spdx.org/rdf/$v/spdx-json-serialize-annotations.ttl \ | ||
--context https://spdx.org/rdf/$v/spdx-context.jsonld \ | ||
--license Apache-2.0 \ | ||
golang \ | ||
-o "$MODNAME" -p "$MODNAME" | ||
done | ||
|
||
go mod tidy | ||
|
||
rm -rf "$VENV_DIR" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/spdx/spdx-go-model | ||
|
||
go 1.18 | ||
|
||
require github.com/ncruces/go-strftime v0.1.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= | ||
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package spdx_go_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/spdx/spdx-go-model/spdx_v3_0_1" | ||
) | ||
|
||
|
||
func TestImport(t *testing.T) { | ||
spdx_v3_0_1.MakePerson() | ||
} |
Oops, something went wrong.