Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .github/workflows/test_and_publish_docker_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ jobs:
- run: go build
- run: go mod verify
- run: go test -race ./...
- name: Check vitality scoring data in the runtime image
run: |
docker build -t crawler-runtime-test .
docker run --rm --entrypoint sh crawler-runtime-test -c \
'test "$PWD" = / && test -s vitality-ranges.yml'
- uses: golang/govulncheck-action@032d45514ae346b1db93c04b0c90b841c370344f # v1.1.0
with:
repo-checkout: false
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ RUN apk add --no-cache gcompat git \
&& mkdir -p /var/crawler/data

COPY --from=build /src/publiccode-crawler /usr/local/bin/publiccode-crawler
COPY --from=build /src/vitality-ranges.yml /vitality-ranges.yml
CMD ["publiccode-crawler", "crawl"]
39 changes: 39 additions & 0 deletions git/repo_activity_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,42 @@ func TestCalculateRepoActivityLongevityBoundary(t *testing.T) {
assert.Equal(t, float64(56), total)
assert.Len(t, index, 1)
}

// TestCalculateRepoActivityRuntimeLayout uses only the scoring data and cache,
// with the working directory laid out like the runtime image root.
func TestCalculateRepoActivityRuntimeLayout(t *testing.T) {
rangesData, err := os.ReadFile("../vitality-ranges.yml")
require.NoError(t, err)

runtimeDir := t.TempDir()
require.NoError(t, os.WriteFile(filepath.Join(runtimeDir, "vitality-ranges.yml"), rangesData, 0o644))
t.Chdir(runtimeDir)

dataDir := filepath.Join(runtimeDir, "var", "crawler", "data")
previousDataDir := viper.Get("DATADIR")
viper.Set("DATADIR", dataDir)
t.Cleanup(func() { viper.Set("DATADIR", previousDataDir) })

cache := vitality.Cache{
LastUpdated: fixedNow,
OldestCommitDate: fixedNow.AddDate(0, 0, -365),
FirstEntryDate: fixedNow.AddDate(0, 0, -1),
Authors: []string{"author@example.com"},
Entries: []vitality.DayEntry{
{Delta: 0, Commits: 1, Authors: []uint16{0}},
{Delta: 1, Commits: 4},
},
Tags: []vitality.TagEntry{{Delta: 1, Count: 1}},
}
writeCache(t, dataDir, "example.com", "owner", "repo", cache)

repo := common.Repository{Name: "owner/repo"}
repo.URL.Host = "example.com"

total, index, err := CalculateRepoActivity(repo, 1, fixedNow)
require.NoError(t, err)

// One author (4), four commits (8), one release (30), one year (30).
assert.Equal(t, float64(72), total)
assert.Equal(t, map[int]float64{0: 72}, index)
}
Loading