Skip to content

Commit

Permalink
Pull request #25: BMA-6099 Do release via GitHub Actions
Browse files Browse the repository at this point in the history
Merge in INFRA/terraform-provider-leaseweb from feature/BMA-6099/github-actions to master

* commit 'e506a314b585719fe87b1a795a75a2fd0e9ce8c1':
  BMA-6099 Bump version to 0.1.2
  BMA-6099 Update Changelog for next release
  BMA-6099 Improve line ending linting command
  BMA-6099 Remove trailing whitespaces in new .yml files
  BMA-6099 Remove Makefile release target
  BMA-6099 Add GitHub action release workflow
  BMA-6099 Add GoReleaser config
  BMA-6099 Add comment in docs about only dedicated servers plugin
  BMA-6099 Remove comment about improvements to logging and error messages in docs
  BMA-6099 Simplify batch loop in to retrieve all servers
  BMA-6099 Fix consistency of ip variable name
  • Loading branch information
tardypad committed Nov 18, 2022
2 parents 3d9e406 + e506a31 commit 02b441b
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 34 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# This GitHub action can publish assets for release when a tag is created.
# Currently its setup to run on any tag that matches the pattern "v*" (ie. v0.1.0).
#
# This uses an action (hashicorp/ghaction-import-gpg) that assumes you set your
# private key in the `GPG_PRIVATE_KEY` secret and passphrase in the `PASSPHRASE`
# secret. If you would rather own your own GPG handling, please fork this action
# or use an alternative one for key handling.
#
# You will need to pass the `--batch` flag to `gpg` in your signing step
# in `goreleaser` to indicate this is being used in a non-interactive mode.
#
name: release
on:
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Unshallow
run: git fetch --prune --unshallow
-
name: Set up Go
uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
cache: true
-
name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v5
id: import_gpg
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3.2.0
with:
version: latest
args: release --rm-dist
env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
# GitHub sets this automatically
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60 changes: 60 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Visit https://goreleaser.com for documentation on how to customize this
# behavior.
before:
hooks:
# this is just an example and not a requirement for provider building/publishing
- go mod tidy
builds:
- env:
# goreleaser does not work with CGO, it could also complicate
# usage by users in CI/CD systems like Terraform Cloud where
# they are unable to install libraries.
- CGO_ENABLED=0
mod_timestamp: '{{ .CommitTimestamp }}'
flags:
- -trimpath
ldflags:
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
goos:
- freebsd
- windows
- linux
- darwin
goarch:
- amd64
- '386'
- arm
- arm64
ignore:
- goos: darwin
goarch: '386'
binary: '{{ .ProjectName }}_v{{ .Version }}'
archives:
- format: zip
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
checksum:
extra_files:
- glob: 'terraform-registry-manifest.json'
name_template: '{{ .ProjectName }}_{{ .Version }}_manifest.json'
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
algorithm: sha256
signs:
- artifacts: checksum
args:
# if you are using this in a GitHub action or some other automated pipeline, you
# need to pass the batch flag to indicate its not interactive.
- "--batch"
- "--local-user"
- "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key
- "--output"
- "${signature}"
- "--detach-sign"
- "${artifact}"
release:
extra_files:
- glob: 'terraform-registry-manifest.json'
name_template: '{{ .ProjectName }}_{{ .Version }}_manifest.json'
# If you want to manually examine the release before its live, uncomment this line:
# draft: true
changelog:
skip: true
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## 0.2.0 (Unreleased)

## 0.1.2 (November 18, 2022)

Add some logging and improve error messages

## 0.1.1 (September 19, 2022)

Fix release
Expand Down
12 changes: 2 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NAME ?= terraform-provider-leaseweb
VERSION ?= 0.1.1
VERSION ?= 0.1.2
GOOS ?= linux
GOARCH ?= amd64
BINARY = $(NAME)-$(VERSION)-$(GOOS)-$(GOARCH)
Expand All @@ -19,7 +19,7 @@ lint: lint-eol lint-spaces lint-tabs lint-go
.PHONY: lint-eol
lint-eol:
@echo "==> Validating unix style line endings of files:"
@! git ls-files | xargs grep --files-with-matches --recursive --exclude Makefile '' || ( echo '[ERROR] Above files have CRLF line endings' && exit 1 )
@! git ls-files | xargs grep --files-with-matches --recursive --perl-regexp "\r" || ( echo '[ERROR] Above files have CRLF line endings' && exit 1 )
@echo All files have valid line endings

.PHONY: lint-spaces
Expand Down Expand Up @@ -52,14 +52,6 @@ format:
go fmt ./...
terraform fmt -recursive examples/

.PHONY: release
release:
$(MAKE) build GOOS=darwin GOARCH=amd64
$(MAKE) build GOOS=darwin GOARCH=arm64
$(MAKE) build GOOS=freebsd GOARCH=amd64
$(MAKE) build GOOS=linux GOARCH=amd64
$(MAKE) build GOOS=windows GOARCH=amd64

.PHONY: install
install: build
mkdir -p ~/.terraform.d/plugins/terraform.local/local/leaseweb/$(VERSION)/$(GOOS)_$(GOARCH)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ It can then be used the following way in your config:
required_providers {
leaseweb = {
source = "terraform.local/local/leaseweb"
version = "0.1.1"
version = "0.1.2"
}
}
}
8 changes: 4 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ proper credentials before it can be used.

!>
This provider is currently considered in a **beta version**.
The documented features are expected to work however several things such as
better logging and error reporting will be improved later on.
Only a limited set of the dedicated server features are available now, other
products will be added later on.
As we gather feedback from our customers, it is possible that some items
might change in a non backward compatible way as we continue our improvements
towards a stable 1.0.0 version.
Expand All @@ -25,7 +25,7 @@ towards a stable 1.0.0 version.
terraform {
required_providers {
leaseweb = {
version = "0.1.1"
version = "0.1.2"
source = "leaseweb/leaseweb"
}
}
Expand Down Expand Up @@ -64,7 +64,7 @@ in your resources.
terraform {
required_providers {
leaseweb = {
version = "0.1.1"
version = "0.1.2"
source = "leaseweb/leaseweb"
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/provider/multiple_providers.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
leaseweb = {
version = "0.1.1"
version = "0.1.2"
source = "leaseweb/leaseweb"
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/provider/provider.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
leaseweb = {
version = "0.1.1"
version = "0.1.2"
source = "leaseweb/leaseweb"
}
}
Expand Down
29 changes: 14 additions & 15 deletions leaseweb/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,9 @@ func closeNetworkInterface(ctx context.Context, serverID string, networkType str
return nil
}

func nullIP(ctx context.Context, serverID string, IP string) error {
apiCtx := fmt.Sprintf("nulling server %s IP %s", serverID, IP)
url := fmt.Sprintf("%s/bareMetals/v2/servers/%s/ips/%s/null", leasewebAPIURL, serverID, IP)
func nullIP(ctx context.Context, serverID string, ip string) error {
apiCtx := fmt.Sprintf("nulling server %s IP %s", serverID, ip)
url := fmt.Sprintf("%s/bareMetals/v2/servers/%s/ips/%s/null", leasewebAPIURL, serverID, ip)
method := http.MethodPost

response, err := doAPIRequest(ctx, method, url, nil)
Expand All @@ -575,9 +575,9 @@ func nullIP(ctx context.Context, serverID string, IP string) error {
return nil
}

func unnullIP(ctx context.Context, serverID string, IP string) error {
apiCtx := fmt.Sprintf("unnulling server %s IP %s", serverID, IP)
url := fmt.Sprintf("%s/bareMetals/v2/servers/%s/ips/%s/unnull", leasewebAPIURL, serverID, IP)
func unnullIP(ctx context.Context, serverID string, ip string) error {
apiCtx := fmt.Sprintf("unnulling server %s IP %s", serverID, ip)
url := fmt.Sprintf("%s/bareMetals/v2/servers/%s/ips/%s/unnull", leasewebAPIURL, serverID, ip)
method := http.MethodPost

response, err := doAPIRequest(ctx, method, url, nil)
Expand Down Expand Up @@ -1052,19 +1052,18 @@ func getAllServers(ctx context.Context, site string) ([]Server, error) {
offset := 0
limit := 20

serversBatch, err := getServersBatch(ctx, offset, limit, site)
if err != nil {
return nil, err
}
allServers = append(allServers, serversBatch...)

for len(serversBatch) != 0 {
offset += limit
serversBatch, err = getServersBatch(ctx, offset, limit, site)
for {
serversBatch, err := getServersBatch(ctx, offset, limit, site)
if err != nil {
return nil, err
}

if len(serversBatch) == 0 {
break
}

allServers = append(allServers, serversBatch...)
offset += limit
}

return allServers, nil
Expand Down
4 changes: 2 additions & 2 deletions templates/index.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ proper credentials before it can be used.

!>
This provider is currently considered in a **beta version**.
The documented features are expected to work however several things such as
better logging and error reporting will be improved later on.
Only a limited set of the dedicated server features are available now, other
products will be added later on.
As we gather feedback from our customers, it is possible that some items
might change in a non backward compatible way as we continue our improvements
towards a stable 1.0.0 version.
Expand Down

0 comments on commit 02b441b

Please sign in to comment.