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

bump: tag and release ORAS CLI v1.1.0 #1027

Closed
wants to merge 9 commits into from
32 changes: 32 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright The ORAS Authors.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: "Close stale issues and PRs"
on:
schedule:
- cron: "30 1 * * *"

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v8
with:
stale-issue-message: "This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days."
stale-pr-message: "This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 30 days."
close-issue-message: "This issue was closed because it has been stalled for 30 days with no activity."
close-pr-message: "This PR was closed because it has been stalled for 30 days with no activity."
days-before-issue-stale: 60
days-before-pr-stale: 45
days-before-issue-close: 30
days-before-pr-close: 30
41 changes: 41 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright The ORAS Authors.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: golangci-lint

on:
pull_request:
paths-ignore:
- 'docs/**'

permissions:
contents: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.20']
fail-fast: true
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
check-latest: true
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
3 changes: 1 addition & 2 deletions .github/workflows/release-ghcr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ jobs:
if [[ "${VERSION}" == "${BRANCH_NAME}" ]]; then
VERSION=$(git rev-parse --short HEAD)
fi
echo ::set-output name=version::${VERSION}
echo ::set-output name=ref::ghcr.io/${{ github.repository }}:${VERSION}
echo "ref=ghcr.io/${{ github.repository }}:${VERSION}" >> $GITHUB_OUTPUT
- name: docker login
uses: docker/login-action@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Contributing

Please refer to the [ORAS Contributing guide](https://oras.land/docs/contributing).
Please refer to the [ORAS Contributing guide](https://oras.land/docs/community/contributing_guide).
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ teste2e-covdata: ## test e2e coverage
export GOCOVERDIR=$(CURDIR)/test/e2e/.cover; \
rm -rf $$GOCOVERDIR; \
mkdir -p $$GOCOVERDIR; \
$(MAKE) teste2e; \
$(GO_EXE) tool covdata textfmt -i=$$GOCOVERDIR -o "$(CURDIR)/test/e2e/coverage.txt"
$(MAKE) teste2e && $(GO_EXE) tool covdata textfmt -i=$$GOCOVERDIR -o "$(CURDIR)/test/e2e/coverage.txt"

.PHONY: help
help: ## Display this help
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
## Docs

Documentation for the ORAS CLI is located on
the project website: [oras.land/cli](https://oras.land/docs/category/cli)
the project website: [oras.land/cli](https://oras.land/docs/category/oras-commands)

## Development Environment Setup

Refer to the [development guide](https://oras.land/docs/CLI/developer_guide) to get started [contributing to ORAS](https://oras.land/docs/contributing).
Refer to the [development guide](https://oras.land/docs/community/developer_guide) to get started [contributing to ORAS](https://oras.land/docs/community/contributing_guide).

## Code of Conduct

Expand Down
5 changes: 3 additions & 2 deletions cmd/oras/internal/display/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (p *tagManifestStatusForRepo) PushReference(ctx context.Context, expected o
if p.printHint != nil {
p.printHint.Do(func() {
ref := p.refPrefix + "@" + expected.Digest.String()
Print("Tagging", ref)
_ = Print("Tagging", ref)
})
}
if err := p.Repository.PushReference(ctx, expected, content, reference); err != nil {
Expand All @@ -136,9 +136,10 @@ func (p *tagManifestStatusForTarget) Tag(ctx context.Context, desc ocispec.Descr
if p.printHint != nil {
p.printHint.Do(func() {
ref := p.refPrefix + "@" + desc.Digest.String()
Print("Tagging", ref)
_ = Print("Tagging", ref)
})
}

if err := p.Target.Tag(ctx, desc, reference); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/oras/internal/option/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type FlagApplier interface {
// NOTE: The option argument need to be a pointer to the options, so its value
// becomes addressable.
func ApplyFlags(optsPtr interface{}, target *pflag.FlagSet) {
rangeFields(optsPtr, func(fa FlagApplier) error {
_ = rangeFields(optsPtr, func(fa FlagApplier) error {
fa.ApplyFlags(target)
return nil
})
Expand Down
16 changes: 10 additions & 6 deletions cmd/oras/internal/option/packer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ func TestPacker_LoadManifestAnnotations_err(t *testing.T) {

func TestPacker_LoadManifestAnnotations_annotationFile(t *testing.T) {
testFile := filepath.Join(t.TempDir(), "testAnnotationFile")
os.WriteFile(testFile, []byte(testContent), fs.ModePerm)
err := os.WriteFile(testFile, []byte(testContent), fs.ModePerm)
if err != nil {
t.Fatalf("Error writing %s: %v", testFile, err)
}
opts := Packer{AnnotationFilePath: testFile}

anno, err := opts.LoadManifestAnnotations()
Expand Down Expand Up @@ -120,11 +123,12 @@ func TestPacker_LoadManifestAnnotations_annotationFlag(t *testing.T) {
t.Fatalf("unexpected error: failed when looking for '$manifest' in annotations")
}
if !reflect.DeepEqual(annotations,
map[string]map[string]string{"$manifest": {
"Key0": "",
"Key1": "Val",
"Key2": "${env:USERNAME}",
},
map[string]map[string]string{
"$manifest": {
"Key0": "",
"Key1": "Val",
"Key2": "${env:USERNAME}",
},
}) {
t.Fatalf("unexpected error: %v", errors.New("content not match"))
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/oras/internal/option/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ func (opts *Remote) NewRepository(reference string, common Common) (repo *remote
return nil, err
}
if opts.distributionSpec.referrersAPI != nil {
repo.SetReferrersCapability(*opts.distributionSpec.referrersAPI)
if err := repo.SetReferrersCapability(*opts.distributionSpec.referrersAPI); err != nil {
return nil, err
}
}
return
}
Expand Down
9 changes: 7 additions & 2 deletions cmd/oras/internal/option/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ func TestMain(m *testing.M) {
case p == "/v2/" && m == "GET":
w.WriteHeader(http.StatusOK)
case p == fmt.Sprintf("/v2/%s/tags/list", testRepo) && m == "GET":
json.NewEncoder(w).Encode(testTagList)
if err := json.NewEncoder(w).Encode(testTagList); err != nil {
http.Error(w, "error encoding", http.StatusBadRequest)
}
}
}))
defer ts.Close()
Expand Down Expand Up @@ -233,7 +235,10 @@ func TestRemote_NewRepository_Retry(t *testing.T) {
http.Error(w, "error", http.StatusTooManyRequests)
return
}
json.NewEncoder(w).Encode(testTagList)
err := json.NewEncoder(w).Encode(testTagList)
if err != nil {
http.Error(w, "error encoding", http.StatusBadRequest)
}
}))
defer ts.Close()
opts := struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/oras/root/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Example - Attach file to the manifest tagged 'v1' in an OCI image layout folder

cmd.Flags().StringVarP(&opts.artifactType, "artifact-type", "", "", "artifact type")
cmd.Flags().IntVarP(&opts.concurrency, "concurrency", "", 5, "concurrency level")
cmd.MarkFlagRequired("artifact-type")
_ = cmd.MarkFlagRequired("artifact-type")
opts.EnableDistributionSpecFlag()
option.ApplyFlags(&opts, cmd.Flags())
return cmd
Expand Down
9 changes: 6 additions & 3 deletions cmd/oras/root/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func runDiscover(ctx context.Context, opts discoverOptions) error {
fmt.Println("Digest:", desc.Digest)
if len(refs) > 0 {
fmt.Println()
printDiscoveredReferrersTable(refs, opts.Verbose)
_ = printDiscoveredReferrersTable(refs, opts.Verbose)
}
return nil
}
Expand Down Expand Up @@ -171,7 +171,7 @@ func fetchAllReferrers(ctx context.Context, repo oras.ReadOnlyGraphTarget, desc
return nil
}

func printDiscoveredReferrersTable(refs []ocispec.Descriptor, verbose bool) {
func printDiscoveredReferrersTable(refs []ocispec.Descriptor, verbose bool) error {
typeNameTitle := "Artifact Type"
typeNameLength := len(typeNameTitle)
for _, ref := range refs {
Expand All @@ -188,9 +188,12 @@ func printDiscoveredReferrersTable(refs []ocispec.Descriptor, verbose bool) {
for _, ref := range refs {
print(ref.ArtifactType, ref.Digest)
if verbose {
printJSON(ref)
if err := printJSON(ref); err != nil {
return fmt.Errorf("Error printing JSON: %w", err)
}
}
}
return nil
}

// printDiscoveredReferrersJSON prints referrer list in JSON equivalent to the
Expand Down
4 changes: 3 additions & 1 deletion internal/cache/target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ func TestProxy_fetchReference(t *testing.T) {
w.WriteHeader(http.StatusOK)
// write data to the response if this is the first request
if requestCount == 1 {
w.Write(blob)
if _, err := w.Write(blob); err != nil {
t.Errorf("Error writing blobs: %v", err)
}
}
atomic.AddInt64(&successCount, 1)
return
Expand Down
48 changes: 48 additions & 0 deletions internal/credential/store_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Copyright The ORAS Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package credential

import (
"os"
"path"
"reflect"
"strings"
"testing"
)

func TestNewStoreError(t *testing.T) {
tmpDir := t.TempDir()
filename := path.Join(tmpDir, "testfile.txt")
_, err := os.Create(filename)
if err != nil {
t.Errorf("error: cannot create file : %v", err)
}
err = os.Chmod(filename, 000)
if err != nil {
t.Errorf("error: cannot change file permissions: %v", err)
}
credStore, err := NewStore(filename)
if credStore != nil {
t.Errorf("Expected NewStore to return nil but actually returned %v ", credStore)
}
if err != nil {
ok := strings.Contains(err.Error(), "failed to open config file")
reflect.DeepEqual(ok, true)

} else {
t.Errorf("Expected err to be not nil")
}
}
19 changes: 12 additions & 7 deletions internal/graph/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestReferrers(t *testing.T) {
index
)
anno := map[string]string{"test": "foo"}
appendBlob(ocispec.MediaTypeArtifactManifest, []byte("subject content"))
appendBlob(ocispec.MediaTypeArtifactManifest, []byte(`{"name":"subject content"}`))
imageType := "test.image"
appendBlob(imageType, []byte("config content"))
generateImage(nil, nil, descs[imgConfig], descs[blob])
Expand All @@ -139,7 +139,9 @@ func TestReferrers(t *testing.T) {
referrers := []ocispec.Descriptor{descs[image], descs[image]}
memory := memory.New()
for i := range descs {
memory.Push(ctx, descs[i], bytes.NewReader(blobs[i]))
if err := memory.Push(ctx, descs[i], bytes.NewReader(blobs[i])); err != nil {
t.Errorf("Error pushing %v\n", err)
}
}
finder := &predecessorFinder{Store: memory}

Expand Down Expand Up @@ -244,7 +246,7 @@ func TestSuccessors(t *testing.T) {
artifact
index
)
appendBlob(ocispec.MediaTypeArtifactManifest, []byte("subject content"))
appendBlob(ocispec.MediaTypeArtifactManifest, []byte(`{"name":"subject content"}`))
imageType := "test.image"
appendBlob(imageType, []byte("config content"))
generateImage(&descs[subject], ocispec.MediaTypeImageManifest, descs[config])
Expand All @@ -255,7 +257,9 @@ func TestSuccessors(t *testing.T) {
memory := memory.New()
ctx := context.Background()
for i := range descs {
memory.Push(ctx, descs[i], bytes.NewReader(blobs[i]))
if err := memory.Push(ctx, descs[i], bytes.NewReader(blobs[i])); err != nil {
t.Errorf("Error pushing %v\n", err)
}
}
fetcher := &fetcher{Fetcher: memory}

Expand Down Expand Up @@ -341,7 +345,7 @@ func TestFindReferrerPredecessors(t *testing.T) {
image
)
var anno map[string]string
appendBlob(ocispec.MediaTypeArtifactManifest, []byte("subject content"))
appendBlob(ocispec.MediaTypeArtifactManifest, []byte(`{"name":"subject content"}`))
imageType := "test.image"
appendBlob(imageType, []byte("config content"))
generateImage(&descs[subject], anno, descs[imgConfig])
Expand All @@ -353,7 +357,9 @@ func TestFindReferrerPredecessors(t *testing.T) {
referrers := []ocispec.Descriptor{descs[image], descs[image]}
memory := memory.New()
for i := range descs {
memory.Push(ctx, descs[i], bytes.NewReader(blobs[i]))
if err := memory.Push(ctx, descs[i], bytes.NewReader(blobs[i])); err != nil {
t.Errorf("Error pushing %v\n", err)
}
}
finder := &predecessorFinder{Store: memory}
type args struct {
Expand All @@ -367,7 +373,6 @@ func TestFindReferrerPredecessors(t *testing.T) {
want []ocispec.Descriptor
wantErr bool
}{

{"should failed to get referrers", args{ctx, &errLister{}, ocispec.Descriptor{}}, nil, true},
{"should failed to get predecessor", args{ctx, &errFinder{}, ocispec.Descriptor{}}, nil, true},
{"should return referrers when target is a referrer lister", args{ctx, &refLister{referrers: referrers}, ocispec.Descriptor{}}, referrers, false},
Expand Down
2 changes: 1 addition & 1 deletion internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package version

var (
// Version is the current version of the oras.
Version = "1.1.0-rc.1"
Version = "1.1.0"
// BuildMetadata is the extra build time data
BuildMetadata = "unreleased"
// GitCommit is the git sha1
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/suite/command/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ var _ = Describe("OCI image layout users:", func() {
root := PrepareTempFiles()
subjectRef := LayoutRef(root, foobar.Tag)
prepare(root)
ORAS("attach", "--artifact-type", "test.attach", "-v", Flags.Layout, subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia)).
ORAS("attach", "--artifact-type", "test.attach", "-v", Flags.Layout, subjectRef, fmt.Sprintf("%s:%s", foobar.AttachFileName, foobar.AttachFileMedia), "--skip-delete-referrers").
MatchErrKeyWords("referrers deletion can only be enforced upon registry\n").
WithWorkDir(root).
Exec()
Expand Down
Loading