diff --git a/.github/workflows/go-test-darwin.yml b/.github/workflows/go-test-darwin.yml deleted file mode 100644 index 9b9f601c..00000000 --- a/.github/workflows/go-test-darwin.yml +++ /dev/null @@ -1,46 +0,0 @@ -# -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - -# This GitHub action runs Packer go tests across -# MacOS runners. -# - -name: "Go Test MacOS" - -on: - push: - branches: - - 'main' - pull_request: - -permissions: - contents: read - -jobs: - get-go-version: - runs-on: ubuntu-latest - outputs: - go-version: ${{ steps.get-go-version.outputs.go-version }} - steps: - - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - - name: 'Determine Go version' - id: get-go-version - run: | - echo "Found Go $(cat .go-version)" - echo "go-version=$(cat .go-version)" >> $GITHUB_OUTPUT - darwin-go-tests: - needs: - - get-go-version - runs-on: macos-latest - name: Darwin Go tests - steps: - - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 - with: - go-version: ${{ needs.get-go-version.outputs.go-version }} - - run: | - echo "Testing with Go ${{ needs.get-go-version.outputs.go-version }}" - go test -race -count 1 ./... -timeout=3m - - diff --git a/.github/workflows/go-test-linux.yml b/.github/workflows/go-test-linux.yml deleted file mode 100644 index 092890c1..00000000 --- a/.github/workflows/go-test-linux.yml +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - -# -# This GitHub action runs Packer go tests across -# Linux runners. -# - -name: "Go Test Linux" - -on: - push: - branches: - - 'main' - pull_request: - -permissions: - contents: read - -jobs: - get-go-version: - runs-on: ubuntu-latest - outputs: - go-version: ${{ steps.get-go-version.outputs.go-version }} - steps: - - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - - name: 'Determine Go version' - id: get-go-version - run: | - echo "Found Go $(cat .go-version)" - echo "go-version=$(cat .go-version)" >> $GITHUB_OUTPUT - linux-go-tests: - needs: - - get-go-version - runs-on: ubuntu-latest - name: Linux Go tests - steps: - - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 - with: - go-version: ${{ needs.get-go-version.outputs.go-version }} - - run: | - echo "Testing with Go ${{ needs.get-go-version.outputs.go-version }}" - go test -race -count 1 ./... -timeout=3m diff --git a/.github/workflows/go-test-windows.yml b/.github/workflows/go-test-windows.yml deleted file mode 100644 index 63033e60..00000000 --- a/.github/workflows/go-test-windows.yml +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - -# -# This GitHub action runs Packer go tests across -# Windows runners. -# - -name: "Go Test Windows" - -on: - push: - branches: - - 'main' - pull_request: - -permissions: - contents: read - -jobs: - get-go-version: - runs-on: ubuntu-latest - outputs: - go-version: ${{ steps.get-go-version.outputs.go-version }} - steps: - - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - - name: 'Determine Go version' - id: get-go-version - run: | - echo "Found Go $(cat .go-version)" - echo "go-version=$(cat .go-version)" >> $GITHUB_OUTPUT - windows-go-tests: - needs: - - get-go-version - runs-on: windows-latest - name: Windows Go tests - steps: - - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 - with: - go-version: ${{ needs.get-go-version.outputs.go-version }} - - run: | - echo "Testing with Go ${{ needs.get-go-version.outputs.go-version }}" - go test -race -count 1 ./... -timeout=3m - diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..5c3aeb18 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,45 @@ +name: Test + +on: + push: + branches: [main] + pull_request: + +permissions: + contents: read + +jobs: + unit: + strategy: + fail-fast: false + matrix: + runs-on: [ubuntu-latest, windows-latest, macos-latest] + + runs-on: ${{ matrix.runs-on }} + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: "1.20" + + - run: make test + + acceptance: + strategy: + fail-fast: false + matrix: + runs-on: [ubuntu-latest, windows-latest, macos-latest] + + permissions: + id-token: write # Required by hetznercloud/tps-action + + runs-on: ${{ matrix.runs-on }} + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: "1.20" + + - uses: hetznercloud/tps-action@main + + - run: make testacc diff --git a/GNUmakefile b/GNUmakefile index c9be6902..a2ca97ee 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,34 +1,38 @@ NAME=hcloud -BINARY=packer-plugin-${NAME} +BINARY=packer-plugin-$(NAME) +ifeq ($(OS), Windows_NT) +# Prevent "Ignoring plugin match packer-plugin-hcloud, no exe extension" +BINARY=packer-plugin-$(NAME).exe +endif COUNT?=1 -TEST?=$(shell go list ./...) +TEST?=./... HASHICORP_PACKER_PLUGIN_SDK_VERSION?=$(shell go list -m github.com/hashicorp/packer-plugin-sdk | cut -d " " -f2) .PHONY: dev build: - @go build -o ${BINARY} + go build -o $(BINARY) dev: build - @mkdir -p ~/.packer.d/plugins/ - @mv ${BINARY} ~/.packer.d/plugins/${BINARY} + mkdir -p ~/.config/packer/plugins + mv $(BINARY) ~/.config/packer/plugins test: - @go test -race -count $(COUNT) $(TEST) -timeout=3m + go test -race -count $(COUNT) -v $(TEST) -timeout=3m -install-packer-sdc: ## Install packer sofware development command - @go install github.com/hashicorp/packer-plugin-sdk/cmd/packer-sdc@${HASHICORP_PACKER_PLUGIN_SDK_VERSION} +install-packer-sdc: ## Install packer software development command + go install github.com/hashicorp/packer-plugin-sdk/cmd/packer-sdc@$(HASHICORP_PACKER_PLUGIN_SDK_VERSION) plugin-check: install-packer-sdc build - @packer-sdc plugin-check ${BINARY} + packer-sdc plugin-check $(BINARY) -testacc: dev - @PACKER_ACC=1 go test -count $(COUNT) -v $(TEST) -timeout=120m +testacc: build + PACKER_ACC=1 PACKER_PLUGIN_PATH=$(PWD) go test -count $(COUNT) -v $(TEST) -timeout=120m generate: install-packer-sdc - @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" "hashicorp" - @rm -r ".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" "hashicorp" + rm -r ".docs" diff --git a/builder/hcloud/builder_acc_test.go b/builder/hcloud/builder_acc_test.go index 441cfd14..5ffef5d4 100644 --- a/builder/hcloud/builder_acc_test.go +++ b/builder/hcloud/builder_acc_test.go @@ -22,12 +22,22 @@ func TestBuilderAcc_basic(t *testing.T) { return nil }, Template: testBuilderAccBasic, - Check: func(buildCommand *exec.Cmd, logfile string) error { + Check: func(buildCommand *exec.Cmd, logFile string) error { if buildCommand.ProcessState != nil { - if buildCommand.ProcessState.ExitCode() != 0 { - return fmt.Errorf("Bad exit code. Logfile: %s", logfile) + if buildCommand.ProcessState.ExitCode() == 0 { + return nil } + + logs, err := os.ReadFile(logFile) + if err != nil { + return err + } + return fmt.Errorf("invalid exit code: %d\n%s", + buildCommand.ProcessState.ExitCode(), + logs, + ) } + return nil }, }