diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e4e61e5 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,45 @@ +name: Release +on: + push: + branches: + - main + pull_request: + branches: + - '**' +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: Jerome1337/gofmt-action@v1.0.5 + with: + gofmt-flags: '-l -d' + - uses: actions/setup-go@v3 + with: + go-version: 1.21 + - uses: golangci/golangci-lint-action@v3 + test: + runs-on: ubuntu-latest + needs: lint + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: 1.21 + - run: go test -v ./... + release: + runs-on: ubuntu-latest + needs: test + permissions: + contents: write + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: 1.21 + - uses: go-semantic-release/action@v1 + with: + prerelease: true + hooks: goreleaser + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/netbox/device.go b/netbox/device.go index 53c4d02..54686a9 100644 --- a/netbox/device.go +++ b/netbox/device.go @@ -1,6 +1,7 @@ package netbox import ( + "fmt" "net/netip" "github.com/netbox-community/go-netbox/v3/netbox/client" @@ -81,8 +82,7 @@ func dcimDeviceToDevice(dev *models.DeviceWithConfigContext) (*Device, error) { } func ListDevices(c *client.NetBoxAPI) (Devices, error) { - var limit int64 - limit = 0 + limit := int64(0) r := dcim.NewDcimDevicesListParams() r.Limit = &limit @@ -106,9 +106,8 @@ func ListDevices(c *client.NetBoxAPI) (Devices, error) { } func GetDevice(c *client.NetBoxAPI, id int64) (*Device, error) { - var limit int64 - limit = 0 - idStr := string(id) + limit := int64(0) + idStr := fmt.Sprint(id) r := dcim.NewDcimDevicesListParams() r.Limit = &limit diff --git a/netbox/interface.go b/netbox/interface.go index 2772a2e..f9f6cfe 100644 --- a/netbox/interface.go +++ b/netbox/interface.go @@ -141,8 +141,7 @@ func dcimInterfaceToInterface(i *models.Interface) (*Interface, error) { } func ListInterfaces(c *client.NetBoxAPI) (Interfaces, error) { - var limit int64 - limit = 0 + limit := int64(0) r := dcim.NewDcimInterfacesListParams() r.Limit = &limit @@ -166,9 +165,8 @@ func ListInterfaces(c *client.NetBoxAPI) (Interfaces, error) { } func GetInterface(c *client.NetBoxAPI, id int64) (*Interface, error) { - var limit int64 - limit = 0 - idStr := string(id) + limit := int64(0) + idStr := fmt.Sprint(id) r := dcim.NewDcimInterfacesListParams() r.Limit = &limit diff --git a/netbox/ipaddr.go b/netbox/ipaddr.go index 072c78c..99ddaf3 100644 --- a/netbox/ipaddr.go +++ b/netbox/ipaddr.go @@ -1,6 +1,7 @@ package netbox import ( + "fmt" "net/netip" "reflect" @@ -88,8 +89,7 @@ func ipamAddressToIPAddr(i *models.IPAddress) (*IPAddr, error) { } func ListIPAddrs(c *client.NetBoxAPI) (IPAddrs, error) { - var limit int64 - limit = 0 + limit := int64(0) r := ipam.NewIpamIPAddressesListParams() r.Limit = &limit @@ -113,9 +113,8 @@ func ListIPAddrs(c *client.NetBoxAPI) (IPAddrs, error) { } func GetIPAddr(c *client.NetBoxAPI, id int64) (*IPAddr, error) { - var limit int64 - limit = 0 - idStr := string(id) + limit := int64(0) + idStr := fmt.Sprint(id) r := ipam.NewIpamIPAddressesListParams() r.Limit = &limit diff --git a/netbox/ipprefix.go b/netbox/ipprefix.go index a465f02..e0aa971 100644 --- a/netbox/ipprefix.go +++ b/netbox/ipprefix.go @@ -1,6 +1,7 @@ package netbox import ( + "fmt" "net/netip" "github.com/netbox-community/go-netbox/v3/netbox/client" @@ -9,24 +10,24 @@ import ( ) type IPPrefix struct { - ID int64 - Prefix netip.Prefix - Display string - Family string - Status string - Description string - Tags map[string]bool // Tags.Name -> true - VRF string + ID int64 + Prefix netip.Prefix + Display string + Family string + Status string + Description string + Tags map[string]bool // Tags.Name -> true + VRF string } type IPPrefixes []*IPPrefix func ipamPrefixToIPPrefix(i *models.Prefix) (*IPPrefix, error) { ip := &IPPrefix{ - Description: i.Description, - Display: i.Display, - ID: i.ID, - Tags: make(map[string]bool), + Description: i.Description, + Display: i.Display, + ID: i.ID, + Tags: make(map[string]bool), } if i.Prefix != nil { @@ -53,8 +54,7 @@ func ipamPrefixToIPPrefix(i *models.Prefix) (*IPPrefix, error) { } func ListIPPrefixes(c *client.NetBoxAPI) (IPPrefixes, error) { - var limit int64 - limit = 0 + limit := int64(0) r := ipam.NewIpamPrefixesListParams() r.Limit = &limit @@ -78,9 +78,8 @@ func ListIPPrefixes(c *client.NetBoxAPI) (IPPrefixes, error) { } func GetIPPrefix(c *client.NetBoxAPI, id int64) (*IPPrefix, error) { - var limit int64 - limit = 0 - idStr := string(id) + limit := int64(0) + idStr := fmt.Sprint(id) r := ipam.NewIpamPrefixesListParams() r.Limit = &limit