forked from ko-build/ko
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issues related to Go 1.18 (ko-build#657)
* Fix issues related to Go 1.18 Update our internal fork for 1.18's ParseBuildInfo for use by pre-1.18 build versions to exactly the code used in the Go 1.18 release branch. This affects users who `go install` ko running Go <1.18, since that code was old and incompatible with 1.18-produced output of `go version -m`. Add a workflow to test all combinations of pre- and post-1.18 setups for both how ko was built, and what version of Go is installed by the user. Update our release workflow to build using Go 1.18, so users who download built binaries don't depend on our forked code at all. * Only consider supported Go versions * Massage output of go version -m so it can be parsed * disable SBOM in unit test * do the massaging inside internal/ * boilerplate come on * proceed even when go mod version doesn't give us anything * undo unit test change
- Loading branch information
Showing
8 changed files
with
212 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Go 1.18 compat test | ||
|
||
on: | ||
pull_request: | ||
branches: ['main'] | ||
|
||
jobs: | ||
go118: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
ko-go-version: ['1.17.x', '1.18.x'] | ||
user-go-version: ['1.17.x', '1.18.x'] | ||
name: Go 1.18 compat (ko=${{ matrix.ko-go-version }} / user=${{ matrix.user-go-version }}) | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
# Build ko using ko-go-version | ||
- uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ matrix.ko-go-version }} | ||
- run: go install ./ | ||
|
||
# Run ko using user-go-version | ||
- uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ matrix.user-go-version }} | ||
- run: | | ||
go install github.com/google/go-containerregistry/cmd/registry@latest | ||
registry & | ||
KO_DOCKER_REPO=localhost:1338 ko build ./test/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2022 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. | ||
|
||
package sbom | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// massageGoModVersion massages the output of `go version -m` into a form that | ||
// can be consumed by ParseBuildInfo. | ||
// | ||
// `go version -m` adds a line at the beginning of its output, and tabs at the | ||
// beginning of every line, that ParseBuildInfo doesn't like. | ||
func massageGoVersionM(b []byte) ([]byte, error) { | ||
var out bytes.Buffer | ||
scanner := bufio.NewScanner(bytes.NewReader(b)) | ||
if !scanner.Scan() { | ||
// Input was malformed, and doesn't contain any newlines (it | ||
// may even be empty). This seems to happen on Windows | ||
// (https://github.com/google/ko/issues/535) and in unit tests. | ||
// Just proceed with an empty output for now, and SBOMs will be empty. | ||
// TODO: This should be an error. | ||
return nil, nil | ||
} | ||
if err := scanner.Err(); err != nil { | ||
return nil, fmt.Errorf("malformed input: %w", err) | ||
} | ||
for scanner.Scan() { | ||
line := strings.TrimSpace(scanner.Text()) | ||
fmt.Fprintln(&out, line) | ||
} | ||
if err := scanner.Err(); err != nil { | ||
return nil, err | ||
} | ||
return out.Bytes(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters