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

Add gochecks workflow #216

Merged
merged 3 commits into from
Feb 23, 2023
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
44 changes: 44 additions & 0 deletions .github/workflows/gochecks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Checks

on:
pull_request:

jobs:
Golangci-Lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.19

- name: Install dependencies
run: |
go version
go install github.com/golangci/golangci-lint/cmd/[email protected]

- name: Run golangci-lint
run: |
golangci-lint run builder/...

Go-Fmt:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.19

- name: Run fmt
run: |
gofmt_files=$(gofmt -l builder)
if [[ -n ${gofmt_files} ]]; then
echo 'gofmt needs running on the following files:'
echo "${gofmt_files}"
exit 1
fi
exit 0
3 changes: 1 addition & 2 deletions builder/vultr/artifact_test.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import (
)

func TestArtifact_Impl(t *testing.T) {
var raw interface{}
raw = &Artifact{}
var raw interface{} = &Artifact{}
if _, ok := raw.(packer.Artifact); !ok {
t.Fatalf("Artifact should be artifact")
}
Expand Down
29 changes: 3 additions & 26 deletions builder/vultr/builder_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package vultr

import (
"fmt"
"io/ioutil"
"io"
"os"
"os/exec"
"regexp"
Expand Down Expand Up @@ -39,7 +39,7 @@ func TestBuilderAcc(t *testing.T) {
}
defer logs.Close()

logsBytes, err := ioutil.ReadAll(logs)
logsBytes, err := io.ReadAll(logs)
if err != nil {
return fmt.Errorf("Unable to read %s", logfile)
}
Expand All @@ -53,18 +53,11 @@ func TestBuilderAcc(t *testing.T) {
},
}
acctest.TestPlugin(t, basicTestCase)

// isoTestCase := basicTestCase
// isoTestCase.Name = "test-vultr-builder-iso"
// isoTestCase.Template = testBuilderAccISO
// acctest.TestPlugin(t, isoTestCase)
}

func testAccPreCheck(t *testing.T) bool {
if os.Getenv(acctest.TestEnvVar) == "" {
t.Skip(fmt.Sprintf(
"Acceptance tests skipped unless env '%s' set",
acctest.TestEnvVar))
t.Skipf("Acceptance tests skipped unless env '%s' set", acctest.TestEnvVar)
return true
}

Expand All @@ -89,19 +82,3 @@ const testBuilderAccBasic = `
}]
}
`

// Requires a specially modified ISO that has been crafted to configure SSH access + relevant configuration options
const testBuilderAccISO = `
{
"builders": [{
"type": "vultr",
"snapshot_description": "packer-test-snapshot-from-iso",
"region_id": "ewr",
"plan_id": "vc2-1c-1gb",
"ssh_timeout": "10m",
"ssh_username": "root",
"iso_url": "https://example.com/customized.iso",
"state_timeout": "60m"
}]
}
`
3 changes: 1 addition & 2 deletions builder/vultr/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ func testConfig() map[string]interface{} {
}

func TestBuilder_ImplementsBuilder(t *testing.T) {
var raw interface{}
raw = &Builder{}
var raw interface{} = &Builder{}
if _, ok := raw.(packer.Builder); !ok {
t.Fatalf("Builder should be a builder")
}
Expand Down
4 changes: 2 additions & 2 deletions builder/vultr/step_create_iso.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func (s *stepCreateISO) Run(ctx context.Context, state multistep.StateBag) multi
return multistep.ActionHalt
}

if iso, err = s.client.ISO.Get(context.Background(), iso.ID); err != nil {
err := fmt.Errorf("Error getting ISO: %s", err)
if _, err = s.client.ISO.Get(context.Background(), iso.ID); err != nil {
err := fmt.Errorf("error getting ISO: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
Expand Down
2 changes: 1 addition & 1 deletion builder/vultr/step_create_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (s *stepCreateServer) Run(ctx context.Context, state multistep.StateBag) mu
}

if instance, err = s.client.Instance.Get(context.Background(), instance.ID); err != nil {
err := fmt.Errorf("Error getting server: %s", err)
err := fmt.Errorf("error getting server: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
Expand Down
6 changes: 3 additions & 3 deletions builder/vultr/step_create_ssh_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *stepCreateSSHKey) Run(_ context.Context, state multistep.StateBag) mult

priv, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
err := fmt.Errorf("Error creating temporary SSH key: %s", err)
err := fmt.Errorf("error creating temporary SSH key: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
Expand All @@ -52,7 +52,7 @@ func (s *stepCreateSSHKey) Run(_ context.Context, state multistep.StateBag) mult

pub, err := ssh.NewPublicKey(&priv.PublicKey)
if err != nil {
err := fmt.Errorf("Error creating temporary SSH key: %s", err)
err := fmt.Errorf("error creating temporary SSH key: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
Expand All @@ -68,7 +68,7 @@ func (s *stepCreateSSHKey) Run(_ context.Context, state multistep.StateBag) mult
}
key, err := s.client.SSHKey.Create(context.Background(), sshKeyReq)
if err != nil {
err := fmt.Errorf("Error creating temporary SSH key: %s", err)
err := fmt.Errorf("error creating temporary SSH key: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
Expand Down
4 changes: 2 additions & 2 deletions builder/vultr/step_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (s *stepCreateSnapshot) Run(ctx context.Context, state multistep.StateBag)
}
snapshot, err := s.client.Snapshot.Create(ctx, snapshotReq)
if err != nil {
err := fmt.Errorf("Error creating snapshot: %s", err)
err := fmt.Errorf("error creating snapshot: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
Expand All @@ -42,7 +42,7 @@ func (s *stepCreateSnapshot) Run(ctx context.Context, state multistep.StateBag)

err = waitForSnapshotState("complete", snapshot.ID, s.client, c.stateTimeout)
if err != nil {
err := fmt.Errorf("Error waiting for snapshot: %s", err)
err := fmt.Errorf("error waiting for snapshot: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
Expand Down