Skip to content

Commit

Permalink
Add presubmit workflow (#994)
Browse files Browse the repository at this point in the history
Fix all the things that it caught :(
  • Loading branch information
jonjohnsonjr committed Apr 23, 2021
1 parent 37467b5 commit 83f4080
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 50 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/presubmit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2021 Google LLC All Rights Reserved.
#
# 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: Presubmit

on:

push:
branches: [ 'main', 'master' ]

pull_request:
branches: [ 'main', 'master', 'release-*' ]

jobs:

test:
name: Presubmit
strategy:
matrix:
go-version: [1.15.x]
platform: [ubuntu-latest]

runs-on: ${{ matrix.platform }}

steps:

- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
id: go

- name: Check out code
uses: actions/checkout@v2

- name: Run presubmit
run: ./hack/presubmit.sh
3 changes: 1 addition & 2 deletions hack/presubmit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ find . -name "*.go" | grep -v vendor/ | xargs gofmt -d -e -l
mkdir -p /tmp/gendoc && go run cmd/crane/help/main.go --dir /tmp/gendoc && diff -Naur /tmp/gendoc/ cmd/crane/doc/

go test ./...
./pkg/name/internal/must_test.sh

pushd ${PROJECT_ROOT}/pkg/authn/k8schain
trap popd EXIT

go test ./...

./pkg/name/internal/must_test.sh
42 changes: 2 additions & 40 deletions pkg/authn/k8schain/go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/name/internal/must_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ set -o pipefail
go test ./pkg/name/internal

# Actually trying to compile should fail.
go test -tags=compile ./pkg/name/internal
go test -tags=compile ./pkg/name/internal 2>&1 > /dev/null
if [[ $? -eq 0 ]]; then
echo "pkg/name/internal test compiled successfully, expected failure"
exit 1
Expand Down
3 changes: 3 additions & 0 deletions pkg/registry/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"sort"
"strconv"
Expand Down Expand Up @@ -49,6 +50,7 @@ type manifests struct {
// maps repo -> manifest tag/digest -> manifest
manifests map[string]map[string]manifest
lock sync.Mutex
log *log.Logger
}

func isManifest(req *http.Request) bool {
Expand Down Expand Up @@ -186,6 +188,7 @@ func (m *manifests) handle(resp http.ResponseWriter, req *http.Request) *regErro
}
} else {
// TODO: Probably want to do an existence check for blobs.
m.log.Printf("TODO: Check blobs for %q", desc.Digest)
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func New(opts ...Option) http.Handler {
},
manifests: manifests{
manifests: map[string]map[string]manifest{},
log: log.New(os.Stderr, "", log.LstdFlags),
},
}
for _, o := range opts {
Expand All @@ -98,5 +99,6 @@ type Option func(r *registry)
func Logger(l *log.Logger) Option {
return func(r *registry) {
r.log = l
r.manifests.log = l
}
}
6 changes: 3 additions & 3 deletions pkg/v1/layout/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,9 @@ func (l Path) writeIndexToFile(indexFile string, ii v1.ImageIndex) error {
var blob io.ReadCloser
// Workaround for #819.
if wl, ok := ii.(withLayer); ok {
layer, err := wl.Layer(desc.Digest)
if err != nil {
return err
layer, lerr := wl.Layer(desc.Digest)
if lerr != nil {
return lerr
}
blob, err = layer.Compressed()
} else if wb, ok := ii.(withBlob); ok {
Expand Down
9 changes: 5 additions & 4 deletions pkg/v1/layout/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,7 @@ func TestRemoveBlob(t *testing.T) {

defer os.RemoveAll(tmp)

var ii v1.ImageIndex
ii = empty.Index
var ii v1.ImageIndex = empty.Index
l, err := Write(tmp, ii)
if err != nil {
t.Fatal(err)
Expand All @@ -440,6 +439,9 @@ func TestRemoveBlob(t *testing.T) {
// create a random blob
b := []byte("abcdefghijklmnop")
hash, _, err := v1.SHA256(bytes.NewReader(b))
if err != nil {
t.Fatal(err)
}

if err := l.WriteBlob(hash, ioutil.NopCloser(bytes.NewReader(b))); err != nil {
t.Fatal(err)
Expand All @@ -457,8 +459,7 @@ func TestRemoveBlob(t *testing.T) {
t.Fatal(err)
}
// now it should not exist
b2, err = l.Bytes(hash)
if err == nil {
if _, err = l.Bytes(hash); err == nil {
t.Fatal("still existed after deletion")
}
}

0 comments on commit 83f4080

Please sign in to comment.