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
83 changes: 0 additions & 83 deletions .github/workflows/ci-pr-title.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions .github/workflows/license.yaml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/reuse.yaml

This file was deleted.

30 changes: 27 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
name: "Unit tests"
on:
push:
branches: [main]
paths:
- 'pkg/**'
- 'cmd/**'
- 'Dockerfile*'
- 'go.mod'
- 'go.sum'
- '.golangci.yaml'
pull_request:
paths:
- 'pkg/**'
Expand All @@ -11,7 +20,7 @@ on:

jobs:
lint:
runs-on: [ default ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
Expand All @@ -26,7 +35,7 @@ jobs:
run: make lint

build:
runs-on: [ default ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
Expand All @@ -38,4 +47,19 @@ jobs:
go-version-file: 'go.mod'
token: ${{ secrets.GITHUB_TOKEN }}
- name: build
run: make build
run: make build

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Go
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
with:
go-version-file: 'go.mod'
token: ${{ secrets.GITHUB_TOKEN }}
- name: test
run: make test
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ fmt: goimports
lint: golint
$(GOLINT) run -v --timeout 5m

.PHONY: test
test:
go test ./...

.PHONY: check
check: fmt lint

Expand Down
9 changes: 8 additions & 1 deletion cmd/check/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ func main() {
fmt.Fprintf(os.Stderr, "invalid source configuration: %s\n", err)
}

resp, err := resource.Check(context.Background(), req)
ctx := context.Background()
repo, err := resource.NewRepositoryForSource(ctx, req.Source)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to create repository client: %s\n", err)
os.Exit(1)
}

resp, err := resource.Check(ctx, req, repo)
if err != nil {
fmt.Fprintf(os.Stderr, "invalid source configuration: %s\n", err)
}
Expand Down
10 changes: 9 additions & 1 deletion cmd/in/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ func main() {
if err := req.Validate(); err != nil {
fmt.Fprintf(os.Stderr, "invalid source configuration: %s\n", err)
}
response, err := resource.Get(context.Background(), req, outputDir)

ctx := context.Background()
repo, err := resource.NewRepositoryForSource(ctx, req.Source)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to create repository client: %s\n", err)
os.Exit(1)
}

response, err := resource.Get(ctx, req, outputDir, repo)
if err != nil {
fmt.Fprintf(os.Stderr, "get failed: %s\n", err)
os.Exit(1)
Expand Down
14 changes: 4 additions & 10 deletions pkg/resource/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/Masterminds/semver/v3"
"github.com/pkg/errors"
"oras.land/oras-go/v2/registry"
"oras.land/oras-go/v2/registry/remote"
)

type (
Expand All @@ -28,12 +27,7 @@ func (cr *CheckRequest) Validate() error {
return cr.Source.Validate()
}

func Check(ctx context.Context, request CheckRequest) (*CheckResponse, error) {
repo, err := newRepositoryForSource(ctx, request.Source)
if err != nil {
return nil, errors.Wrap(err, "failed to create repository client")
}

func Check(ctx context.Context, request CheckRequest, repo Repository) (*CheckResponse, error) {
// Fetch repository tags
allTags, err := registry.Tags(ctx, repo)
if err != nil {
Expand Down Expand Up @@ -68,7 +62,7 @@ func Check(ctx context.Context, request CheckRequest) (*CheckResponse, error) {
return nil, fmt.Errorf("no latest tag found for source %s", request.Source.String())
}

resolvedVersions, err := resolveImageDigests(ctx, sortedSemvers, repo)
resolvedVersions, err := resolveImageDigests(ctx, sortedSemvers, repo, request.Source.String())
if err != nil {
return nil, err
}
Expand All @@ -93,10 +87,10 @@ func sortBySemver(allTags []string) []semver.Version {
return allVersions
}

func resolveImageDigests(ctx context.Context, sortedSemvers []semver.Version, repo *remote.Repository) (CheckResponse, error) {
func resolveImageDigests(ctx context.Context, sortedSemvers []semver.Version, repo Repository, source string) (CheckResponse, error) {
resolvedVersions := make(CheckResponse, len(sortedSemvers))
for i, version := range sortedSemvers {
digest, err := getDigestForTag(ctx, repo, version.Original())
digest, err := getDigestForTag(ctx, repo, source, version.Original())
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch digest for latest tag %q (parsed as %s)", version.Original(), version.String()))
}
Expand Down
Loading
Loading