Skip to content

Commit

Permalink
feat(refactor): plugin refactor for v4
Browse files Browse the repository at this point in the history
  • Loading branch information
FalcoSuessgott committed Oct 6, 2024
1 parent fb262d8 commit a39867c
Show file tree
Hide file tree
Showing 48 changed files with 3,189 additions and 1,320 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: golangci-lint
on:
push:
paths:
- '**.go'
branches:
- master
pull_request:

permissions:
# Required: allow read access to the content for analysis.
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
pull-requests: read
# Optional: Allow write access to checks to allow the action to annotate code in the PR.
checks: write

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: '1.21'
cache: false

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.59.1
args: -c .golang-ci.yml -v --timeout=5m
env:
GO111MODULES: off
22 changes: 19 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,30 @@ jobs:

steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: '1.21'
cache: false

- run: go generate -tags tools tools/tools.go

- uses: hashicorp/setup-packer@main

- run: |
make build
make install
packer plugin install github.com/hashicorp/docker
- name: go get
run: go get ./...

- name: Run tests
run: go test -v ./...
- name: unit tests
run: make test
env:
PACKER_ACC: 1

- name: acc tests
run: make test-acc

- name: e2e tests
run: make test-e2e
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
example/packer_cache
.envrc
packer-plugin-goss
**/*.tar
**/test-results.xml
34 changes: 34 additions & 0 deletions .golang-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
linters-settings:
lll:
line-length: 180
allow-leading-space: true
linters:
enable-all: true
disable:
- testpackage
- forbidigo
- paralleltest
- wrapcheck
- gochecknoglobals
- varnamelen
- funlen
- gomnd
- containedctx
- nlreturn
- wsl
- err113
- exhaustruct
- nolintlint
- maintidx
- dupl
- revive
- depguard
- tagalign
- perfsprint
- godox
- intrange
- copyloopvar
- gomoddirectives
- goconst
- godot
- execinquery
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ env:
- PACKER_PROTOCOL_VERSION=x5.0
before:
hooks:
- go generate -tags tools tools/tools.go
- go mod tidy
- go test ./...
- make plugin-check
builds:
-
id: plugin-check
Expand Down
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
repos:
- repo: https://github.com/tekwizely/pre-commit-golang
rev: v1.0.0-rc.1
hooks:
- id: go-build-mod
- id: go-test-mod
- id: go-vet-mod
- id: go-staticcheck-mod
- id: go-fmt
- id: go-fumpt
- id: go-imports
- id: go-lint
- id: golangci-lint-mod
args: [-c.golang-ci.yml]
62 changes: 62 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
E2E_DIR ?= examples

default: help

.PHONY: help
help: ## list makefile targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

PHONY: lint
lint: ## lint go files
golangci-lint run -c .golang-ci.yml

.PHONY: fmt
fmt: ## format go files
gofumpt -w .
gci write .
packer fmt -recursive -write .

.PHONY: build
build: ## build the plugin
go build -ldflags="-X github.com/YaleUniversity/packer-provisioner-goss/version.VersionPrerelease=dev" -o packer-plugin-goss

.PHONY: install
install: build ## install the plugin
packer plugins install --path packer-plugin-goss github.com/YaleUniversity/goss

.PHONY: test
test: ## run tests
PACKER_ACC=1 gotestsum

.PHONY: test-acc
test-acc: clean build install ## run acceptance tests
PACKER_ACC=1 go test -count 1 -v ./provisioner/goss/provisioner_goss_test.go -timeout=120m

.PHONY: test-e2e
test-e2e: clean build install ## run e2e tests
cd $(E2E_DIR) && packer init .
cd $(E2E_DIR) && packer build .

.PHONY: clean
clean: ## remove tmp files
rm -f $(E2E_DIR)/*.tar $(E2E_DIR)/test-results.xml packer-plugin-goss

.PHONY: generate
generate: ## go generate
go generate ./...

.PHONY: plugin-check
plugin-check: build ## will check whether a plugin binary seems to work with packer
@packer-sdc plugin-check packer-plugin-goss

.PHONY: docs
docs: ## gen packer plugin docs
@go generate ./...
@rm -rf .docs
@packer-sdc renderdocs -src "docs" -partials docs-partials/ -dst ".docs/"
@./.web-docs/scripts/compile-to-webdocs.sh "." ".docs" ".web-docs" "YaleUniversity"
@rm -r ".docs"

.PHONY: example
example: install ## run example
cd examples && packer build .
Loading

0 comments on commit a39867c

Please sign in to comment.