diff --git a/.github/actions/build-and-persist-plugin-binary/action.yml b/.github/actions/build-and-persist-plugin-binary/action.yml deleted file mode 100644 index 4d358ddd..00000000 --- a/.github/actions/build-and-persist-plugin-binary/action.yml +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - -name: build-and-persist-plugin-binary -inputs: - GOOS: - required: true - GOARCH: - required: true -runs: - using: composite - steps: - - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - - run: "GOOS=${{ inputs.GOOS }} GOARCH=${{ inputs.GOARCH }} go build -o ./pkg/packer_plugin_hcloud_${{ inputs.GOOS }}_${{ inputs.GOARCH }} ." - shell: bash - - run: zip ./pkg/packer_plugin_hcloud_${{ inputs.GOOS }}_${{ inputs.GOARCH }}.zip ./pkg/packer_plugin_hcloud_${{ inputs.GOOS }}_${{ inputs.GOARCH }} - shell: bash - - run: rm ./pkg/packer_plugin_hcloud_${{ inputs.GOOS }}_${{ inputs.GOARCH }} - shell: bash - - uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 - with: - name: "packer_plugin_hcloud_${{ inputs.GOOS }}_${{ inputs.GOARCH }}.zip" - path: "pkg/packer_plugin_hcloud_${{ inputs.GOOS }}_${{ inputs.GOARCH }}.zip" - retention-days: 30 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..cecb5911 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,34 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +# 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). + +name: Build + +on: + push: + branches: [main] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/setup-go@v4 + with: + go-version: "1.20" + + - uses: goreleaser/goreleaser-action@v4 + with: + version: latest + args: release --clean --timeout 120m --snapshot --skip=sign + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - uses: actions/upload-artifact@v3 + with: + path: dist/*.zip diff --git a/.github/workflows/build_plugin_binaries.yml b/.github/workflows/build_plugin_binaries.yml deleted file mode 100644 index b205ae9a..00000000 --- a/.github/workflows/build_plugin_binaries.yml +++ /dev/null @@ -1,146 +0,0 @@ -# Copyright (c) HashiCorp, Inc. -# SPDX-License-Identifier: MPL-2.0 - -name: hashicorp/packer-plugin-hcloud/build_plugin_binaries -permissions: - contents: read -on: - push: - branches: - - main -jobs: - build_darwin: - defaults: - run: - working-directory: ~/go/src/github.com/hetznercloud/packer-plugin-hcloud - runs-on: ubuntu-latest - container: - image: cimg/go:1.20 - steps: - - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - - uses: "./.github/actions/build-and-persist-plugin-binary" - with: - GOOS: darwin - GOARCH: amd64 - - uses: "./.github/actions/build-and-persist-plugin-binary" - with: - GOOS: darwin - GOARCH: arm64 - build_freebsd: - defaults: - run: - working-directory: ~/go/src/github.com/hetznercloud/packer-plugin-hcloud - runs-on: ubuntu-latest - container: - image: cimg/go:1.20 - steps: - - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - - uses: "./.github/actions/build-and-persist-plugin-binary" - with: - GOOS: freebsd - GOARCH: 386 - - uses: "./.github/actions/build-and-persist-plugin-binary" - with: - GOOS: freebsd - GOARCH: amd64 - - uses: "./.github/actions/build-and-persist-plugin-binary" - with: - GOOS: freebsd - GOARCH: arm - build_linux: - defaults: - run: - working-directory: ~/go/src/github.com/hetznercloud/packer-plugin-hcloud - runs-on: ubuntu-latest - container: - image: cimg/go:1.20 - steps: - - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - - uses: "./.github/actions/build-and-persist-plugin-binary" - with: - GOOS: linux - GOARCH: 386 - - uses: "./.github/actions/build-and-persist-plugin-binary" - with: - GOOS: linux - GOARCH: amd64 - - uses: "./.github/actions/build-and-persist-plugin-binary" - with: - GOOS: linux - GOARCH: arm - - uses: "./.github/actions/build-and-persist-plugin-binary" - with: - GOOS: linux - GOARCH: arm64 - build_netbsd: - defaults: - run: - working-directory: ~/go/src/github.com/hetznercloud/packer-plugin-hcloud - runs-on: ubuntu-latest - container: - image: cimg/go:1.20 - steps: - - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - - uses: "./.github/actions/build-and-persist-plugin-binary" - with: - GOOS: netbsd - GOARCH: 386 - - uses: "./.github/actions/build-and-persist-plugin-binary" - with: - GOOS: netbsd - GOARCH: amd64 - - uses: "./.github/actions/build-and-persist-plugin-binary" - with: - GOOS: netbsd - GOARCH: arm - build_openbsd: - defaults: - run: - working-directory: ~/go/src/github.com/hetznercloud/packer-plugin-hcloud - runs-on: ubuntu-latest - container: - image: cimg/go:1.20 - steps: - - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - - uses: "./.github/actions/build-and-persist-plugin-binary" - with: - GOOS: openbsd - GOARCH: 386 - - uses: "./.github/actions/build-and-persist-plugin-binary" - with: - GOOS: openbsd - GOARCH: amd64 - - uses: "./.github/actions/build-and-persist-plugin-binary" - with: - GOOS: openbsd - GOARCH: arm - build_solaris: - defaults: - run: - working-directory: ~/go/src/github.com/hetznercloud/packer-plugin-hcloud - runs-on: ubuntu-latest - container: - image: cimg/go:1.20 - steps: - - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - - uses: "./.github/actions/build-and-persist-plugin-binary" - with: - GOOS: solaris - GOARCH: amd64 - build_windows: - defaults: - run: - working-directory: ~/go/src/github.com/hetznercloud/packer-plugin-hcloud - runs-on: ubuntu-latest - container: - image: cimg/go:1.20 - steps: - - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - - uses: "./.github/actions/build-and-persist-plugin-binary" - with: - GOOS: windows - GOARCH: 386 - - uses: "./.github/actions/build-and-persist-plugin-binary" - with: - GOOS: windows - GOARCH: amd64 diff --git a/.github/workflows/notify-integration-release-via-manual.yaml b/.github/workflows/notify-integration-release-via-manual.yaml deleted file mode 100644 index 6244065d..00000000 --- a/.github/workflows/notify-integration-release-via-manual.yaml +++ /dev/null @@ -1,46 +0,0 @@ -name: Notify Integration Release (Manual) -on: - workflow_dispatch: - inputs: - version: - description: "The release version (semver)" - default: 0.0.1 - required: false - branch: - description: "A branch or SHA" - default: 'main' - required: false -jobs: - notify-release: - runs-on: ubuntu-latest - steps: - - name: Checkout this repo - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - with: - ref: ${{ github.event.inputs.branch }} - # Ensure that Docs are Compiled - - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 - - shell: bash - run: make generate - - shell: bash - run: | - if [[ -z "$(git status -s)" ]]; then - echo "OK" - else - echo "Docs have been updated, but the compiled docs have not been committed." - echo "Run 'make generate', and commit the result to resolve this error." - exit 1 - fi - # Perform the Release - - name: Checkout integration-release-action - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - with: - repository: hashicorp/integration-release-action - path: ./integration-release-action - - name: Notify Release - uses: ./integration-release-action - with: - integration_identifier: "packer/hetznercloud/hcloud" - release_version: ${{ github.event.inputs.version }} - release_sha: ${{ github.event.inputs.branch }} - github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/notify-integration-release-via-tag.yaml b/.github/workflows/notify-integration-release-via-tag.yaml deleted file mode 100644 index 42b6cdee..00000000 --- a/.github/workflows/notify-integration-release-via-tag.yaml +++ /dev/null @@ -1,52 +0,0 @@ -name: Notify Integration Release (Tag) -on: - push: - tags: - - '*.*.*' # Proper releases -jobs: - strip-version: - runs-on: ubuntu-latest - outputs: - packer-version: ${{ steps.strip.outputs.packer-version }} - steps: - - name: Strip leading v from version tag - id: strip - env: - REF: ${{ github.ref_name }} - run: | - echo "packer-version=$(echo "$REF" | sed -E 's/v?([0-9]+\.[0-9]+\.[0-9]+)/\1/')" >> "$GITHUB_OUTPUT" - notify-release: - needs: - - strip-version - runs-on: ubuntu-latest - steps: - - name: Checkout this repo - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - with: - ref: ${{ github.ref }} - # Ensure that Docs are Compiled - - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 - - shell: bash - run: make generate - - shell: bash - run: | - if [[ -z "$(git status -s)" ]]; then - echo "OK" - else - echo "Docs have been updated, but the compiled docs have not been committed." - echo "Run 'make generate', and commit the result to resolve this error." - exit 1 - fi - # Perform the Release - - name: Checkout integration-release-action - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - with: - repository: hashicorp/integration-release-action - path: ./integration-release-action - - name: Notify Release - uses: ./integration-release-action - with: - integration_identifier: "packer/hetznercloud/hcloud" - release_version: ${{ needs.strip-version.outputs.packer-version }} - release_sha: ${{ github.ref }} - github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2dcdbcd5..09c3be32 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,57 +3,56 @@ # 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 `GPG_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 + +name: Release on: push: - tags: - - "v*" - -permissions: - contents: write - packages: read + tags: [v*] jobs: - goreleaser: + release: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 - - - name: Unshallow - run: git fetch --prune --unshallow + - uses: actions/checkout@v4 + with: + fetch-depth: 0 - - name: Set up Go - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 + - uses: actions/setup-go@v4 with: go-version: "1.20" - - name: Describe plugin - id: plugin_describe - run: echo "api_version=$(go run . describe | jq -r '.api_version')" >> "$GITHUB_OUTPUT" - - name: Import GPG key id: import_gpg - uses: crazy-max/ghaction-import-gpg@111c56156bcc6918c056dbef52164cfa583dc549 # v5.2.0 + uses: crazy-max/ghaction-import-gpg@v5 with: gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.GPG_PASSPHRASE }} + + - name: Describe plugin api_version + id: describe_plugin + run: echo "api_version=$(go run . describe | jq -r '.api_version')" >> "$GITHUB_OUTPUT" - name: Run GoReleaser - uses: goreleaser/goreleaser-action@f82d6c1c344bcacabba2c841718984797f664a6b # v4.2.0 + uses: goreleaser/goreleaser-action@v4 with: version: latest args: release --clean --timeout 120m env: - GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - API_VERSION: ${{ steps.plugin_describe.outputs.api_version }} + GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} + API_VERSION: ${{ steps.describe_plugin.outputs.api_version }} + + notify-release: + needs: [release] + + runs-on: ubuntu-latest + steps: + - run: echo "RELEASE_VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV" + + - uses: hashicorp/integration-release-action@main + with: + integration_identifier: packer/hetznercloud/hcloud + release_version: ${{ env.RELEASE_VERSION }} + release_sha: ${{ github.sha }} + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yml b/.goreleaser.yml index 5ccbdfba..44ed3aa8 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,96 +1,61 @@ # Copyright (c) HashiCorp, Inc. # SPDX-License-Identifier: MPL-2.0 -# This is an example goreleaser.yaml file with some defaults. -# Make sure to check the documentation at http://goreleaser.com -version: 1 - -env: - - CGO_ENABLED=0 - -before: - hooks: - # We strongly recommend running tests to catch any regression before release. - # Even though, this an optional step. - - go test ./... - # Check plugin compatibility with required version of the Packer SDK - - make plugin-check +# See http://goreleaser.com +# version: 1 builds: - # A separated build to run the packer-plugins-check only once for a linux_amd64 binary - - id: plugin-check - mod_timestamp: "{{ .CommitTimestamp }}" - flags: - - -trimpath #removes all file system paths from the compiled executable - ldflags: - - "-s -w -X {{ .ModulePath }}/version.Version={{.Version}} -X {{ .ModulePath }}/version.VersionPrerelease= " - goos: - - linux - goarch: - - amd64 - binary: "{{ .ProjectName }}_v{{ .Version }}_{{ .Env.API_VERSION }}_{{ .Os }}_{{ .Arch }}" - - - id: linux-builds + - id: build mod_timestamp: "{{ .CommitTimestamp }}" + env: + - CGO_ENABLED=0 flags: - - -trimpath #removes all file system paths from the compiled executable + - -trimpath ldflags: - - "-s -w -X {{ .ModulePath }}/version.Version={{.Version}} -X {{ .ModulePath }}/version.VersionPrerelease= " - goos: - - linux - goarch: - - amd64 - - "386" - - arm - - arm64 - ignore: - - goos: linux - goarch: amd64 - binary: "{{ .ProjectName }}_v{{ .Version }}_{{ .Env.API_VERSION }}_{{ .Os }}_{{ .Arch }}" + - -s + - -w + - -X {{ .ModulePath }}/version.Version={{ .Version }} + - -X {{ .ModulePath }}/version.VersionPrerelease={{- if .IsSnapshot -}}dev+{{ .ShortCommit }}{{- end -}} + binary: >- + {{- if .IsSnapshot -}} + {{ replace .ProjectName "-" "_" }}_{{ .Os }}_{{ .Arch }} + {{- else -}} + {{ .ProjectName }}_v{{ .Version }}_{{ .Env.API_VERSION }}_{{ .Os }}_{{ .Arch }} + {{- end -}} - - id: darwin-builds - mod_timestamp: "{{ .CommitTimestamp }}" - flags: - - -trimpath #removes all file system paths from the compiled executable - ldflags: - - "-s -w -X {{ .ModulePath }}/version.Version={{.Version}} -X {{ .ModulePath }}/version.VersionPrerelease= " - goos: - - darwin - goarch: - - amd64 - - arm64 - binary: "{{ .ProjectName }}_v{{ .Version }}_{{ .Env.API_VERSION }}_{{ .Os }}_{{ .Arch }}" + targets: + - linux_386 + - linux_amd64_v1 + - linux_arm_6 + - linux_arm64 + - freebsd_386 + - freebsd_amd64_v1 + - freebsd_arm + - netbsd_386 + - netbsd_amd64_v1 + - netbsd_arm + - openbsd_386 + - openbsd_amd64_v1 + - openbsd_arm + - solaris_amd64_v1 + - darwin_amd64_v1 + - darwin_arm64 + - windows_386 + - windows_amd64_v1 - - id: other-builds - mod_timestamp: "{{ .CommitTimestamp }}" - flags: - - -trimpath #removes all file system paths from the compiled executable - ldflags: - - "-s -w -X {{ .ModulePath }}/version.Version={{.Version}} -X {{ .ModulePath }}/version.VersionPrerelease= " - goos: - - netbsd - - openbsd - - freebsd - - windows - - solaris - goarch: - - amd64 - - "386" - - arm - ignore: - - goos: windows - goarch: arm - - goos: solaris - goarch: arm - - goos: solaris - goarch: "386" - binary: "{{ .ProjectName }}_v{{ .Version }}_{{ .Env.API_VERSION }}_{{ .Os }}_{{ .Arch }}" +snapshot: + name_template: "{{ .Version }}-dev+{{ .ShortCommit }}" archives: - format: zip files: - none* - name_template: "{{ .ProjectName }}_v{{ .Version }}_{{ .Env.API_VERSION }}_{{ .Os }}_{{ .Arch }}" + name_template: >- + {{- if .IsSnapshot -}} + {{ replace .ProjectName "-" "_" }}_{{ .Os }}_{{ .Arch }} + {{- else -}} + {{ .ProjectName }}_v{{ .Version }}_{{ .Env.API_VERSION }}_{{ .Os }}_{{ .Arch }} + {{- end -}} checksum: name_template: "{{ .ProjectName }}_v{{ .Version }}_SHA256SUMS" @@ -99,12 +64,8 @@ checksum: signs: - artifacts: checksum args: - # if you are using this is 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 }}" - - "--output" - - "${signature}" - - "--detach-sign" - - "${artifact}" + - --batch + - --local-user={{ .Env.GPG_FINGERPRINT }} + - --output=${signature} + - --detach-sign + - ${artifact}