Skip to content

Commit

Permalink
Relace go-bindata with go:embed
Browse files Browse the repository at this point in the history
- Update makefile to move expected data into place rather than invole
  `go-bindata`
- Simplify call sites where `assets.Asset(...)` has been used
  • Loading branch information
aramprice committed Sep 8, 2023
1 parent 14b5aad commit 8d941e8
Show file tree
Hide file tree
Showing 35 changed files with 26 additions and 2,230 deletions.
18 changes: 7 additions & 11 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,20 @@ jobs:
lint:
strategy:
matrix:
# removing windows-2019 until go-bindata can be generated
os: [ubuntu-latest]
os: [windows-2019, ubuntu-latest]
name: lint
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: go.mod
- name: generate fake go-bindata for assets package
if: ${{ matrix.os != 'windows-2019' }}
- name: Provide `StemcellAutomation.zip` for `go:embed` consumption in `assets` package
run: |
go run github.com/go-bindata/go-bindata/go-bindata \
-o assets/stemcell_automation.go \
-pkg assets \
-prefix assets \
<(echo 'fake assets')
# - uses: golangci/golangci-lint-action@v3
# if: ${{ matrix.os == 'windows-2019' }}
make generate-fake-stemcell-automation
- uses: golangci/golangci-lint-action@v3
if: ${{ matrix.os == 'windows-2019' }}
- uses: golangci/golangci-lint-action@v3
if: ${{ matrix.os != 'windows-2019' }}
with:
args: --enable goimports
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ stembuild
stembuild.exe
gordiff
gordiff.exe
stemcell_automation.go
temp
rdiff/*.c
rdiff/*.h
Expand Down
7 changes: 4 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ run:
output:
# Sort results by: filepath, line and column.
sort-results: true
linters:
enable:
- goimports

issues:
max-issues-per-linter: 0
max-same-issues: 0
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
GOSRC = $(shell find . -name "*.go" ! -name "*test.go" ! -name "*fake*" ! -path "./integration/*")
FAKE_STEMCELL_AUTOMATION_PATH = integration/construct/assets/StemcellAutomation.zip
FAKE_STEMCELL_AUTOMATION_PREFIX = $(shell dirname "${FAKE_STEMCELL_AUTOMATION_PATH}")
STEMCELL_VERSION = $(shell echo "$${STEMBUILD_VERSION}")
LD_FLAGS = "-w -s -X github.com/cloudfoundry/stembuild/version.Version=${STEMCELL_VERSION}"

Expand Down Expand Up @@ -51,10 +50,9 @@ integration-badger : generate-fake-stemcell-automation
go run github.com/onsi/ginkgo/v2/ginkgo -r -v --randomize-all --until-it-fails --timeout 3h integration

generate-fake-stemcell-automation: $(GOSRC) $(FAKE_STEMCELL_AUTOMATION_PATH)
go run github.com/go-bindata/go-bindata/go-bindata -o assets/stemcell_automation.go -pkg assets -prefix $(FAKE_STEMCELL_AUTOMATION_PREFIX) $(FAKE_STEMCELL_AUTOMATION_PATH)
cp $(FAKE_STEMCELL_AUTOMATION_PATH) assets/

generate: assets/StemcellAutomation.zip
go run github.com/go-bindata/go-bindata/go-bindata -o assets/stemcell_automation.go -pkg assets -prefix assets assets/StemcellAutomation.zip

out/stembuild : generate $(GOSRC)
CGO_ENABLED=0 go build -o $(COMMAND) -ldflags $(LD_FLAGS) .
Expand Down
1 change: 0 additions & 1 deletion assets/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
*.go
StemcellAutomation.zip
8 changes: 8 additions & 0 deletions assets/stemcell_automation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package assets

import (
_ "embed"
)

//go:embed StemcellAutomation.zip
var StemcellAutomation []byte
7 changes: 2 additions & 5 deletions construct/archive/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ var _ = Describe("Zip", func() {

Describe("Unzip", func() {
It("should return byte array of the file when it is found in the archive", func() {
fileArchive, err := assets.Asset("StemcellAutomation.zip")
Expect(err).ToNot(HaveOccurred())
fileArchive := assets.StemcellAutomation
Expect(fileArchive).ToNot(BeNil())

r, err := zip.Unzip(fileArchive, "Setup.ps1")
Expand All @@ -24,15 +23,13 @@ var _ = Describe("Zip", func() {
})

It("should return an error if the file cannot be found in the archive", func() {
fileArchive, err := assets.Asset("StemcellAutomation.zip")
Expect(err).ToNot(HaveOccurred())
fileArchive := assets.StemcellAutomation
Expect(fileArchive).ToNot(BeNil())

r, err := zip.Unzip(fileArchive, "Setup2.ps1")
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError("could not find Setup2.ps1 in zip archive"))
Expect(r).To(BeNil())

})

It("should return an error if the fileArchive is not a zip file", func() {
Expand Down
5 changes: 1 addition & 4 deletions construct/winrm.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ type WinRMManager struct {

func (w *WinRMManager) Enable() error {
failureString := "failed to enable WinRM: %s"
saZip, err := assets.Asset(stemcellAutomationName)
if err != nil {
return fmt.Errorf(failureString, err)
}
saZip := assets.StemcellAutomation

bmZip, err := w.Unarchiver.Unzip(saZip, boshPsModules)
if err != nil {
Expand Down
4 changes: 1 addition & 3 deletions construct/winrm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ var _ = Describe("WinRMManager", func() {
fakeGuestManager = &constructfakes.FakeGuestManager{}
fakeZipUnarchiver = &constructfakes.FakeZipUnarchiver{}

var err error
saByteData, err = assets.Asset("StemcellAutomation.zip")
Expect(err).ToNot(HaveOccurred())
saByteData = assets.StemcellAutomation

winrmManager = &construct.WinRMManager{
GuestManager: fakeGuestManager,
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ toolchain go1.21.0

require (
github.com/concourse/pool-resource v1.1.1
github.com/go-bindata/go-bindata v3.1.2+incompatible
github.com/golang/mock v1.6.0
github.com/google/subcommands v1.2.0
github.com/google/uuid v1.3.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/go-bindata/go-bindata v3.1.2+incompatible h1:5vjJMVhowQdPzjE1LdxyFF7YFTXg5IgGVW4gBr5IbvE=
github.com/go-bindata/go-bindata v3.1.2+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
Expand Down
8 changes: 2 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@ func main() {
_, _ = fmt.Fprintf(os.Stderr, "Warning: The following environment variable is set and might override flags provided to stembuild: %s\n", envName)
}
}
data, err := assets.Asset("StemcellAutomation.zip")
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, "StemcellAutomation not found")
os.Exit(1)
}

s := "./StemcellAutomation.zip"
err = os.WriteFile(s, data, 0644)
err := os.WriteFile(s, assets.StemcellAutomation, 0644)
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, "Unable to write StemcellAutomation.zip")
os.Exit(1)
Expand Down
1 change: 0 additions & 1 deletion tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package main

import (
_ "github.com/go-bindata/go-bindata/go-bindata"
_ "github.com/golang/mock/mockgen"
_ "github.com/maxbrunsfeld/counterfeiter/v6"
_ "github.com/onsi/ginkgo/v2/ginkgo"
Expand Down
16 changes: 0 additions & 16 deletions vendor/github.com/go-bindata/go-bindata/.gitignore

This file was deleted.

79 changes: 0 additions & 79 deletions vendor/github.com/go-bindata/go-bindata/CONTRIBUTING.md

This file was deleted.

3 changes: 0 additions & 3 deletions vendor/github.com/go-bindata/go-bindata/LICENSE

This file was deleted.

2 changes: 0 additions & 2 deletions vendor/github.com/go-bindata/go-bindata/Makefile

This file was deleted.

Loading

0 comments on commit 8d941e8

Please sign in to comment.