Skip to content

Commit 91c8940

Browse files
authored
Merge pull request #1 from aboutcode-org/init
Go library to validate PURLs using prebuilt FST
2 parents 7012481 + a05260d commit 91c8940

13 files changed

Lines changed: 755729 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Test CI
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
10+
jobs:
11+
build-test:
12+
name: Run test and build
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
os:
17+
- ubuntu-latest
18+
- ubuntu-24.04-arm
19+
- macos-14
20+
- macos-15
21+
- macos-15-intel
22+
23+
runs-on: ${{ matrix.os }}
24+
25+
steps:
26+
- name: Checkout source
27+
uses: actions/checkout@v4
28+
29+
- name: Install Go
30+
uses: actions/setup-go@v6
31+
with:
32+
go-version: 'stable'
33+
34+
- name: Install dependencies
35+
run: make dev
36+
37+
- name: Validate code format
38+
run: make check
39+
40+
- name: Run tests
41+
run: make test
42+
43+
- name: Build
44+
run: make build-fst

.github/workflows/release.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Create GitHub release
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
tags:
7+
- "v*.*.*"
8+
9+
jobs:
10+
publish:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Create a GitHub release
15+
uses: softprops/action-gh-release@v2
16+
with:
17+
generate_release_notes: true
18+
draft: false

Makefile

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
#
3+
# Copyright (c) nexB Inc. and others. All rights reserved.
4+
# ScanCode is a trademark of nexB Inc.
5+
# SPDX-License-Identifier: Apache-2.0
6+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
7+
# See https://github.com/aboutcode-org/purl-validator-go for support or download.
8+
# See https://aboutcode.org for more information about nexB OSS projects.
9+
#
10+
11+
GOCMD=go
12+
GOFMT=gofmt
13+
GOIMPORTS=goimports
14+
GOLINT=golangci-lint
15+
GOFMT_CMD = $(GOFMT) -l .
16+
GOIMPORTS_CMD = $(GOIMPORTS) -l .
17+
GOSEC=gosec
18+
19+
build-fst:
20+
go run ./cmd/main.go
21+
22+
clean:
23+
$(GOCMD) clean
24+
rm -rf $(BUILD_DIR)
25+
26+
test:
27+
$(GOCMD) test -v
28+
29+
dev:
30+
$(GOCMD) install golang.org/x/tools/cmd/goimports@latest
31+
$(GOCMD) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
32+
$(GOCMD) install github.com/securego/gosec/v2/cmd/gosec@latest
33+
$(GOCMD) mod tidy
34+
35+
gofmt:
36+
@echo "-> Apply gofmt code formatter"
37+
$(GOFMT) -w .
38+
39+
goimports:
40+
@echo "-> Apply goimports changes to ensure proper imports ordering"
41+
$(GOIMPORTS) -w .
42+
43+
valid: goimports gofmt
44+
45+
check-gofmt:
46+
@echo "-> Running gofmt for code formatting validation..."
47+
@files=$$($(GOFMT_CMD)); \
48+
if [ -n "$$files" ]; then \
49+
echo "The following files are not properly formatted:"; \
50+
echo "$$files"; \
51+
exit 1; \
52+
fi
53+
54+
check-goimports:
55+
@echo "-> Running goimports for import ordering validation..."
56+
@files=$$($(GOIMPORTS_CMD)); \
57+
if [ -n "$$files" ]; then \
58+
echo "The following files have incorrect imports:"; \
59+
echo "$$files"; \
60+
exit 1; \
61+
fi
62+
63+
check: check-gofmt check-goimports
64+
@echo "\n-> Running golangci-lint for linting..."
65+
$(GOLINT) run --issues-exit-code=1 ./...
66+
@echo "\n-> Running gosec for security checks..."
67+
$(GOSEC) ./...
68+
69+
.PHONY: build-fst clean test dev gofmt goimports valid check-gofmt check-goimports check

README.md

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,82 @@
1-
# purl-validator-go
1+
# purlvalidator
2+
3+
[![License](https://img.shields.io/badge/License-Apache--2.0-blue.svg?style=for-the-badge)](https://opensource.org/licenses/Apache-2.0)
4+
[![Version](https://img.shields.io/github/v/release/aboutcode-org/purlvalidator-go?style=for-the-badge)](https://github.com/aboutcode-org/purlvalidator-go/releases)
5+
[![Test](https://img.shields.io/github/actions/workflow/status/aboutcode-org/purlvalidator-go/ci.yml?style=for-the-badge&logo=github)](https://github.com/aboutcode-org/purlvalidator-go/actions)
6+
7+
**purlvalidator** is a Go library for validating [Package URLs (PURLs)](https://github.com/package-url/purl-spec). It works fully offline, including in **air-gapped** or **restricted environments**, and answers one key question: **Does the package this PURL represents actually exist?**
8+
9+
## How It Works?
10+
11+
**purlvalidator** is shipped with a pre-built FST (Finite State Transducer), a set of compact automata containing latest Package URLs mined by the MineCode[^1]. Library uses this FST to perform lookups and confirm whether the **base PURL**[^2] exists.
12+
13+
## Currently Supported Ecosystems
14+
15+
- **nuget**: [https://www.nuget.org/](https://www.nuget.org/)
16+
17+
## Usage
18+
19+
Add `purlvalidator` as dependency in your go.mod
20+
21+
```bash
22+
require github.com/aboutcode-org/purlvalidator-go v0.1.0
23+
```
24+
25+
Use it in your code like this
26+
27+
```rust
28+
import "github.com/aboutcode-org/purlvalidator-go"
29+
30+
var result bool = purlvalidator.Validate("pkg:nuget/FluentValidation");
31+
```
32+
33+
## Contribution
34+
35+
We welcome contributions from the community! If you find a bug or have an idea for a new feature, please open an issue on the GitHub repository. If you want to contribute code, you can fork the repository, make your changes, and submit a pull request.
36+
37+
* Please try to write a good commit message, see [good commit message wiki](https://aboutcode.readthedocs.io/en/latest/contributing/writing_good_commit_messages.html).
38+
* Add DCO `Sign Off` to your commits.
39+
40+
## Development Setup
41+
42+
Run these commands, starting from a git clone of [https://github.com/aboutcode-org/purl-validator-rust.git](https://github.com/aboutcode-org/purlvalidator-go.git)
43+
44+
Generate FST:
45+
46+
```bash
47+
make build-fst
48+
```
49+
50+
Run tests:
51+
52+
```bash
53+
make test
54+
```
55+
56+
Fix formatting and linting:
57+
58+
```bash
59+
make valid
60+
```
61+
62+
## License
63+
64+
SPDX-License-Identifier: Apache-2.0
65+
66+
purl-validator is licensed under Apache License version 2.0.
67+
68+
```text
69+
You may not use this software except in compliance with the License.
70+
You may obtain a copy of the License at
71+
72+
http://www.apache.org/licenses/LICENSE-2.0
73+
74+
Unless required by applicable law or agreed to in writing, software
75+
distributed under the License is distributed on an "AS IS" BASIS,
76+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
77+
See the License for the specific language governing permissions and
78+
limitations under the License.
79+
```
80+
81+
[^1]: MineCode continuously collects package metadata from various package ecosystems to maintain an up-to-date catalog of known packages.
82+
[^2]: A Base Package URL is a Package URL without a version or subpath.

0 commit comments

Comments
 (0)