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 Nov 4, 2024
1 parent 9df4f14 commit 1cb2693
Show file tree
Hide file tree
Showing 51 changed files with 2,867 additions and 1,351 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ updates:
- "dependencies"
commit-message:
prefix: "feat"
include: "scope"
include: "scope"
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
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
go-version: "1.21"

# if tag release
-
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
if: startsWith(github.ref, 'refs/tags/v')
Expand Down
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
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-case-conflict
- id: check-symlinks
- id: check-json
- id: mixed-line-ending
args: ["--fix=lf"]
- id: no-commit-to-branch
args: [--branch, main]
- id: pretty-format-json
args: [--autofix, --no-sort-keys]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
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 1cb2693

Please sign in to comment.