Skip to content
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

ci: add versions fixture generator for Red Hat #1356

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f691fd2
feat: create redhat version parser
G-Rath Oct 24, 2024
cec48ac
feat: create redhat version comparer
G-Rath Oct 25, 2024
b75d772
fix: give version priority over arch (and actually ignore arch entirely)
G-Rath Oct 25, 2024
a86d72f
fix: trim characters before continuing
G-Rath Oct 25, 2024
a1c8f51
fix: use the remainder of the version
G-Rath Oct 25, 2024
814c380
fix: roll the indexes back before ending subsegment parsing
G-Rath Oct 25, 2024
e11762d
fix: handle reaching the end of a version string
G-Rath Oct 25, 2024
f49cce0
fix: properly compare the remaining length of version strings
G-Rath Oct 25, 2024
3fa3b33
feat: focus on the version string index rather than the current chara…
G-Rath Oct 28, 2024
7892a7f
fix: compare epochs
G-Rath Oct 29, 2024
c62d27d
refactor: encapsulate logic for comparing each component
G-Rath Oct 29, 2024
63ea274
feat: add basic support for comparing by release
G-Rath Oct 29, 2024
74bd05c
feat: support properly comparing releases
G-Rath Oct 29, 2024
6c66a34
fix: preserve the leading `-` in the release value to indicate a rele…
G-Rath Oct 29, 2024
d9ba5ea
test: add cases for architecture
G-Rath Oct 29, 2024
a1a8d73
fix: only do trimming and length comparing if segments are digits
G-Rath Oct 29, 2024
dee4bbe
refactor: deduplicate code
G-Rath Oct 29, 2024
d2a87bc
chore: clean up comments
G-Rath Oct 29, 2024
3289332
refactor: update order to be consistent
G-Rath Oct 29, 2024
39bb66f
refactor: move early exit into generic comparator
G-Rath Oct 29, 2024
247093b
refactor: inline functions
G-Rath Oct 29, 2024
fe8ffea
fix: support non-numeric epochs
G-Rath Oct 29, 2024
5c8b28f
chore: fix function comment
G-Rath Oct 29, 2024
866679f
fix: support the caret character
G-Rath Oct 29, 2024
c2bc2b5
fix: treat non-ascii characters as the same
G-Rath Oct 29, 2024
a0dd4ca
refactor: rename variables to match parameter names
G-Rath Oct 30, 2024
8daf765
chore: update comment
G-Rath Oct 30, 2024
ebc6e41
refactor: simplify trimming loops
G-Rath Oct 30, 2024
4085480
refactor: rename variable
G-Rath Nov 5, 2024
057538d
chore: create redhat versions fixture generator
G-Rath Oct 29, 2024
360c1b0
test: use generated red hat versions fixture if it exists
G-Rath Oct 29, 2024
29201f7
chore: ignore the redhat versions generated file
G-Rath Oct 29, 2024
502c632
ci: add `semantic` job for generating redhat versions
G-Rath Oct 29, 2024
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
34 changes: 34 additions & 0 deletions .github/workflows/semantic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,39 @@ jobs:
path: /tmp/debian-versions-generator-cache.csv
key: ${{ runner.os }}-${{ hashFiles('debian-db.zip') }}

generate-redhat-versions:
permissions:
contents: read # to fetch code (actions/checkout)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1

- uses: actions/cache/restore@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4.1.1
with:
path: /tmp/redhat-versions-generator-cache.csv
key: ${{ runner.os }}-

- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
with:
persist-credentials: false
- uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0
with:
python-version: "3.10"
- run: sudo apt install rpm
- run: rpm --version
- run: python3 scripts/generators/generate-redhat-versions.py
- run: git status
- run: stat redhat-db.zip
- uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: generated-redhat-versions
path: internal/semantic/fixtures/redhat-versions-generated.txt

- uses: actions/cache/save@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4.1.1
with:
path: /tmp/redhat-versions-generator-cache.csv
key: ${{ runner.os }}-${{ hashFiles('redhat-db.zip') }}

generate-packagist-versions:
permissions:
contents: read # to fetch code (actions/checkout)
Expand Down Expand Up @@ -173,6 +206,7 @@ jobs:
- generate-rubygems-versions
- generate-maven-versions
- generate-cran-versions
- generate-redhat-versions
if: always()
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@
*.pprof
.go-version
node_modules

# we don't want to check in this file as it's very very large
/internal/semantic/fixtures/redhat-versions-generated.txt
23 changes: 23 additions & 0 deletions internal/semantic/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package semantic_test

import (
"bufio"
"errors"
"io/fs"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -234,7 +236,28 @@ func TestVersion_Compare_Ecosystems(t *testing.T) {
name: "Alpine",
file: "alpine-versions-generated.txt",
},
{
name: "Red Hat",
file: "redhat-versions.txt",
},
}

// we don't check the generated fixture for Red Hat in due to its size
// so we only add it if it exists, so that people can have it locally
// without needing to do a dance with git everytime they commit
_, err := os.Stat("fixtures/redhat-versions-generated.txt")
if err == nil {
tests = append(tests, struct {
name string
file string
}{
name: "Red Hat",
file: "redhat-versions-generated.txt",
})
} else if !errors.Is(err, fs.ErrNotExist) {
t.Fatalf("fixtures/redhat-versions-generated.txt exists but could not be read: %v", err)
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
Expand Down
172 changes: 172 additions & 0 deletions internal/semantic/fixtures/redhat-versions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
1.0 = 1.0
1.0 < 2.0
2.0 > 1.0
2.0.1 = 2.0.1
2.0 < 2.0.1
2.0.1 > 2.0
2.0.1a = 2.0.1a
2.0.1a > 2.0.1
2.0.1 < 2.0.1a
5.5p1 = 5.5p1
5.5p1 < 5.5p2
5.5p2 > 5.5p1
5.5p10 = 5.5p10
5.5p1 < 5.5p10
5.5p10 > 5.5p1
10xyz < 10.1xyz
10.1xyz > 10xyz
xyz10 = xyz10
xyz10 < xyz10.1
xyz10.1 > xyz10
xyz.4 = xyz.4
xyz.4 < 8
8 > xyz.4
xyz.4 < 2
2 > xyz.4
5.5p2 < 5.6p1
5.6p1 > 5.5p2
5.6p1 < 6.5p1
6.5p1 > 5.6p1
6.0.rc1 > 6.0
6.0 < 6.0.rc1
10b2 > 10a1
10a2 < 10b2
1.0aa = 1.0aa
1.0a < 1.0aa
1.0aa > 1.0a
10.0001 = 10.0001
10.0001 = 10.1
10.1 = 10.0001
10.0001 < 10.0039
10.0039 > 10.0001
4.999.9 < 5.0
5.0 > 4.999.9
20101121 = 20101121
20101121 < 20101122
20101122 > 20101121
2_0 = 2_0
2.0 = 2_0
2_0 = 2.0
a = a
a+ = a+
a+ = a_
a_ = a+
+a = +a
+a = _a
_a = +a
+_ = +_
_+ = +_
_+ = _+
+ = _
_ = +
1.0~rc1 = 1.0~rc1

1.0~rc1 < 1.0
1.0 > 1.0~rc1

1.0~rc1 < 1.0~rc2
1.0~rc2 > 1.0~rc1

1.0~rc1~git123 = 1.0~rc1~git123
1.0~rc1~git123 < 1.0~rc1
1.0~rc1 < 1.0arc1

# epochs
1:1 = 1:1
0:1 < 1:1
0:1 < 1:2
0:1~1 < 1:2
3:1~1 > 1:2
1~1 < 1:2
3 < 1:2
13 < 14:2
13:5 < 14:2
13:5 > 04:2
13:5 > 004:2
013:5 > 004:2
130:5 > 004:2
184:2 > 177:5
01:2 = 1:2

a:1 = a:1
a:1 < b:1
a:1 < a:2
a:1~1 < a:2
c:1~1 > a:2

a1:1 = a1:1
a1:1 < b1:1
a1:1 < a1:2
a2:1 > a1:2

b1:1 > a2:1
a:1 < a1:1
b:1 > a1:1
b~1:1 > a1:1

# releases
1-123 > 1-2
1-1 = 1-1
1-2 > 1-1
1 < 1-1
1 < 1-0
1 < 1-
1- = 1-

1-123 > 1-1.el7

# arch
0:3.10.0-229.el7 < 0:3.10.0-229.1.2.ael7b
0:2.4.21-9.EL < 0:2.4.21-9.0.1.EL

0:3.10.0-229.el7 < 0:3.10.0-229.1.2.ael7b
1-1.a > 1-1.
1-1. = 1-1.
1-1. = 1-1
1-1 < 1-1.1
1. = 1
1-1.a = 1-1.a
1-1.a < 1-1.e
1-1.c > 1-1.b
1-1.4 > 1-1.3
1-1.1 < 1-1.2
1-1.ael7b < 1-1.el7
0:3.10.0-229.1.2.ael7b < 0:3.10.0-229.1.2.el7

1 < 1-
0:3.10.0-229.1.2.ael7b < 0:3.10.0-229.4.2.ael7b

1.0^ = 1.0^
1.0^ > 1.0
1.0 < 1.0^
1.0^git1 = 1.0^git1
1.0^git1 > 1.0
1.0 < 1.0^git1
1.0^git1 < 1.0^git2
1.0^git2 > 1.0^git1
1.0^git1 < 1.01
1.01 > 1.0^git1
1.0^20160101 = 1.0^20160101
1.0^20160101 < 1.0.1
1.0.1 > 1.0^20160101
1.0^20160101^git1 = 1.0^20160101^git1
1.0^20160102 > 1.0^20160101^git1
1.0^20160101^git1 < 1.0^20160102

1.0~rc1^git1 = 1.0~rc1^git1
1.0~rc1^git1 > 1.0~rc1
1.0~rc1 < 1.0~rc1^git1
1.0^git1~pre = 1.0^git1~pre
1.0^git1 > 1.0^git1~pre
1.0^git1~pre < 1.0^git1

1.1.α = 1.1.α
1.1.α = 1.1.β
1.1.β = 1.1.α
1.1.αα = 1.1.α
1.1.α = 1.1.ββ
1.1.ββ = 1.1.αα

1.1.a < 1.2.ββ
1.1.a < 0:1.2.ββ
1.1.α < 1.1.a
2 changes: 2 additions & 0 deletions internal/semantic/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func Parse(str string, ecosystem models.Ecosystem) (Version, error) {
return parseSemverVersion(str), nil
case "PyPI":
return parsePyPIVersion(str), nil
case "Red Hat":
return parseRedHatVersion(str), nil
case "RubyGems":
return parseRubyGemsVersion(str), nil
case "Ubuntu":
Expand Down
Loading