Skip to content

Commit 68a093a

Browse files
authored
Merge pull request #3 from aboutcode-org/fedcode-integration
Automate FST regeneration and release creatio
2 parents b828cb2 + 516e69a commit 68a093a

5 files changed

Lines changed: 147 additions & 20 deletions

File tree

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ on:
99
jobs:
1010
publish:
1111
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
1214

1315
steps:
1416
- name: Create a GitHub release

.github/workflows/sync-purls.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Collect latest PURLs from FederatedCode and create release with latest FST
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '0 0 * * *'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
collect-purls:
13+
strategy:
14+
max-parallel: 1
15+
matrix:
16+
include:
17+
- ecosystem: apk
18+
- ecosystem: cargo
19+
- ecosystem: composer
20+
- ecosystem: conan
21+
- ecosystem: cpan
22+
- ecosystem: cran
23+
- ecosystem: debain
24+
- ecosystem: maven
25+
- ecosystem: npm
26+
- ecosystem: nuget
27+
- ecosystem: pypi
28+
- ecosystem: swift
29+
30+
uses: aboutcode-org/purl-validator.rs/.github/workflows/collect-purls_template.yml
31+
with:
32+
ecosystem: ${{ matrix.ecosystem }}
33+
path: "cmd/data/${{ matrix.ecosystem }}.txt"
34+
35+
regen-fst-and-release:
36+
name: Regenerate FST and create release using new FST
37+
needs: collect-purls
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: Checkout source
41+
uses: actions/checkout@v4
42+
with:
43+
token: ${{ secrets.GH_TAG_RELEASE_TOKEN }}
44+
45+
- name: Install Go
46+
uses: actions/setup-go@v6
47+
with:
48+
go-version: 'stable'
49+
50+
- name: Install dependencies
51+
run: make dev
52+
53+
- name: Regenerate FST
54+
id: regen_fst
55+
run: |-
56+
git pull
57+
make build-fst
58+
git diff --name-only | grep -q 'purls.fst' && echo "changed=true" >> $GITHUB_OUTPUT \
59+
|| echo "changed=false" >> $GITHUB_OUTPUT
60+
61+
# Commit latest FST
62+
git config user.name "AboutCode Automation"
63+
git config user.email "automation@aboutcode.org"
64+
git add purls.fst
65+
git commit -m "$(echo -e "Regenerate FST using latest PURLs\n\nSigned-off-by: AboutCode Automation <automation@aboutcode.org>")" || exit 0
66+
git push
67+
68+
- name: Bump minor version
69+
id: bump
70+
if: steps.regen_fst.outputs.changed == 'true'
71+
run: |-
72+
new_version=$(git tag --sort=version:refname | tail -n1 | awk -F'[v.]' '{ printf "v%d.%d.0\n", $2, $3+1 }')
73+
74+
echo "new_version=$new_version" >> $GITHUB_OUTPUT
75+
76+
- name: Add Changelog
77+
if: steps.regen_fst.outputs.changed == 'true'
78+
run: |-
79+
# Add Changelog
80+
today=$(date +%Y-%m-%d)
81+
awk -v ver="${{ steps.bump.outputs.new_version }}" -v date="$today" '
82+
NR==1{
83+
print "# Changelog\n\n## v" ver " (" date ")\n\n - Update FST with latest PURLs"
84+
next
85+
}1' CHANGELOG.md > .tmp.CHANGELOG.md && mv .tmp.CHANGELOG.md CHANGELOG.md
86+
87+
- name: Commit Changelog
88+
if: steps.regen_fst.outputs.changed == 'true'
89+
run: |-
90+
git config user.name "AboutCode Automation"
91+
git config user.email "automation@aboutcode.org"
92+
git add -A
93+
git commit -m "$(echo -e "Bump version for v${{ steps.bump.outputs.new_version }} release\n\nSigned-off-by: AboutCode Automation <automation@aboutcode.org>")" || exit 0
94+
git push
95+
96+
- name: Push tag
97+
if: steps.regen_fst.outputs.changed == 'true'
98+
run: |-
99+
# Push tag
100+
git tag -a "v${{ steps.bump.outputs.new_version }}" -m "Release v${{ steps.bump.outputs.new_version }}"
101+
git push origin "v${{ steps.bump.outputs.new_version }}"

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@
1212

1313
## Currently Supported Ecosystems
1414

15-
- **nuget**: [https://www.nuget.org/](https://www.nuget.org/)
15+
- **apk**
16+
- **cargo**
17+
- **composer**
18+
- **conan**
19+
- **cpan**
20+
- **cran**
21+
- **debain**
22+
- **maven**
23+
- **npm**
24+
- **nuget**
25+
- **pypi**
26+
- **swift**
1627

1728
## Usage
1829

cmd/data/testpurls.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

cmd/main.go

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,61 @@ package main
1414
import (
1515
"log"
1616
"os"
17+
"path/filepath"
1718
"sort"
1819
"strings"
1920

2021
"github.com/blevesearch/vellum"
2122
)
2223

2324
func main() {
24-
data, _ := os.ReadFile("cmd/data/purls.txt")
25-
lines := strings.FieldsFunc(string(data), func(r rune) bool {
26-
return r == '\n'
27-
})
28-
sort.Strings(lines)
29-
output := strings.Join(lines, "\n")
30-
31-
// #nosec G306
32-
err := os.WriteFile("cmd/data/purls.txt", []byte(output), 0644)
25+
f, err := os.Create("purls.fst")
26+
var purlCount int
3327
if err != nil {
34-
panic(err)
28+
log.Fatal(err)
3529
}
3630

37-
f, err := os.Create("purls.fst")
31+
dirname := "cmd/data/"
32+
entries, err := os.ReadDir(dirname)
3833
if err != nil {
3934
log.Fatal(err)
4035
}
36+
4137
builder, err := vellum.New(f, nil)
4238
if err != nil {
4339
log.Fatal(err)
4440
}
4541

46-
for _, line := range lines {
47-
err = builder.Insert([]byte(line), 0)
48-
if err != nil {
49-
log.Fatal(err)
42+
for _, entry := range entries {
43+
if !entry.IsDir() && strings.HasSuffix(strings.ToLower(entry.Name()), ".txt") {
44+
fullPath := filepath.Join(dirname, entry.Name())
45+
purlCount += insert_purls(builder, fullPath)
5046
}
5147
}
5248

5349
err = builder.Close()
5450
if err != nil {
5551
log.Fatal(err)
5652
}
53+
log.Printf("FST generated with %d base PackageURLs", purlCount)
54+
log.Printf("FST generated at %s", f.Name())
55+
}
56+
57+
func insert_purls(builder *vellum.Builder, file string) int {
58+
var err error
59+
// #nosec G304
60+
data, _ := os.ReadFile(file)
61+
lines := strings.FieldsFunc(string(data), func(r rune) bool {
62+
return r == '\n'
63+
})
64+
sort.Strings(lines)
65+
66+
log.Printf("Insert PURLs from %s in FST", file)
67+
for _, line := range lines {
68+
err = builder.Insert([]byte(line), 0)
69+
if err != nil {
70+
log.Fatal(err)
71+
}
72+
}
73+
return len(lines)
5774
}

0 commit comments

Comments
 (0)