Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
242 changes: 242 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
#
# This GitHub action builds vagrant binaries, linux packages,
# and Docker images from source, and uploads them to GitHub artifacts.
# Note that artifacts available via GitHub Artifacts are not codesigned or notarized.
#

name: build

on:
workflow_dispatch:
workflow_call:
push:
branches:
- main
- release/**

env:
REPO_NAME: "packer-plugin-vagrant"

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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: 'Determine Go version'
id: get-go-version
# We use .go-version as our source of truth for current Go
# version, because "goenv" can react to it automatically.
run: |
echo "Building with Go $(cat .go-version)"
echo "go-version=$(cat .go-version)" >> $GITHUB_OUTPUT

set-product-version:
runs-on: ubuntu-latest
outputs:
product-version: ${{ steps.set-product-version.outputs.product-version }}
base-product-version: ${{ steps.set-product-version.outputs.base-product-version }}
product-date: ${{ steps.set-product-version.outputs.product-date }}
product-prerelease-version: ${{ steps.set-product-version.outputs.prerelease-product-version }}
set-ld-flags: ${{ steps.set-ld-flags.outputs.set-ld-flags }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: set product version
id: set-product-version
uses: hashicorp/actions-set-product-version@v1
- name: set-ld-flags
id: set-ld-flags
run: |
T="github.com/hashicorp/packer-plugin-vagrant/version"
echo "set-ld-flags=-s -w -X ${T}.Version=${{ steps.set-product-version.outputs.base-product-version }} -X ${T}.VersionPrerelease=${{ steps.set-product-version.outputs.prerelease-product-version }}" >> $GITHUB_OUTPUT
- name: validate outputs
run: |
echo "Product Version: ${{ steps.set-product-version.outputs.product-version }}"
echo "Base Product Version: ${{ steps.set-product-version.outputs.base-product-version }}"
echo "Prerelease Version: ${{ steps.set-product-version.outputs.prerelease-product-version }}"
echo "ldflags: ${{ steps.set-ld-flags.outputs.set-ld-flags }}"

generate-metadata-file:
needs: set-product-version
runs-on: ubuntu-latest
outputs:
filepath: ${{ steps.generate-metadata-file.outputs.filepath }}
steps:
- name: 'Checkout directory'
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Generate metadata file
id: generate-metadata-file
uses: hashicorp/actions-generate-metadata@main
with:
version: ${{ needs.set-product-version.outputs.product-version }}
product: ${{ env.REPO_NAME }}

- uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: metadata.json
path: ${{ steps.generate-metadata-file.outputs.filepath }}

plugin-check:
needs: get-go-version
runs-on: ubuntu-latest
outputs:
api_version: ${{ steps.plugin_describe.outputs.api_version }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Unshallow
run: git fetch --prune --unshallow
- name: Set up Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: ${{ needs.get-go-version.outputs.go-version }}
- name: Describe plugin
id: plugin_describe
run: echo "api_version=$(go run . describe | jq -r '.api_version')" >> "$GITHUB_OUTPUT"
- name: Run test
run: go test ./...
- name: Make plugin-check
run: make plugin-check

build-other:
needs:
- set-product-version
- get-go-version
- plugin-check
runs-on: ubuntu-latest
strategy:
matrix:
goos: [ freebsd, windows, netbsd, openbsd, solaris ]
goarch: [ "386", "amd64", "arm"]
go: [ "${{ needs.get-go-version.outputs.go-version }}" ]
exclude:
- goos: solaris
goarch: 386
- goos: solaris
goarch: arm
- goos: windows
goarch: arm
fail-fast: true

name: Go ${{ matrix.go }} ${{ matrix.goos }} ${{ matrix.goarch }} build

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Go Build
env:
PRODUCT_VERSION: ${{ needs.set-product-version.outputs.product-version }}
PRERELEASE_VERSION: ${{ needs.set-product-version.outputs.product-prerelease-version }}
LD_FLAGS: "${{ needs.set-product-version.outputs.set-ld-flags}}"
CGO_ENABLED: "0"
uses: hashicorp/actions-go-build@v1
with:
bin_name: ${{ env.REPO_NAME }}_v${{ needs.set-product-version.outputs.product-version }}_${{ needs.plugin-check.outputs.api_version }}_${{ matrix.goos }}_${{ matrix.goarch }}
product_name: ${{ env.REPO_NAME }}
product_version: ${{ needs.set-product-version.outputs.product-version }}
go_version: ${{ matrix.go }}
os: ${{ matrix.goos }}
arch: ${{ matrix.goarch }}
reproducible: report
instructions: |-
cp LICENSE "$TARGET_DIR/LICENSE.txt"
go build -o "$BIN_PATH" -ldflags="$LD_FLAGS" -trimpath -buildvcs=false

build-linux:
needs:
- set-product-version
- get-go-version
- plugin-check
runs-on: ubuntu-latest
strategy:
matrix:
goos: [ linux ]
goarch: [ "arm", "arm64", "386", "amd64" ]
go: [ "${{ needs.get-go-version.outputs.go-version }}" ]
fail-fast: true

name: Go ${{ matrix.go }} ${{ matrix.goos }} ${{ matrix.goarch }} build

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Go Build
env:
PRODUCT_VERSION: ${{ needs.set-product-version.outputs.product-version }}
PRERELEASE_VERSION: ${{ needs.set-product-version.outputs.product-prerelease-version }}
LD_FLAGS: "${{ needs.set-product-version.outputs.set-ld-flags}}"
CGO_ENABLED: "0"
uses: hashicorp/actions-go-build@v1
with:
bin_name: ${{ env.REPO_NAME }}_v${{ needs.set-product-version.outputs.product-version }}_${{ needs.plugin-check.outputs.api_version }}_${{ matrix.goos }}_${{ matrix.goarch }}
product_name: ${{ env.REPO_NAME }}
product_version: ${{ needs.set-product-version.outputs.product-version }}
go_version: ${{ matrix.go }}
os: ${{ matrix.goos }}
arch: ${{ matrix.goarch }}
reproducible: report
instructions: |-
cp LICENSE "$TARGET_DIR/LICENSE.txt"
go build -o "$BIN_PATH" -ldflags="$LD_FLAGS" -trimpath -buildvcs=false

build-darwin:
needs:
- set-product-version
- get-go-version
- plugin-check
runs-on: macos-latest
strategy:
matrix:
goos: [ darwin ]
goarch: [ "amd64", "arm64" ]
go: [ "${{ needs.get-go-version.outputs.go-version }}" ]
fail-fast: true
name: Go ${{ matrix.go }} ${{ matrix.goos }} ${{ matrix.goarch }} build

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Go Build
env:
PRODUCT_VERSION: ${{ needs.set-product-version.outputs.product-version }}
PRERELEASE_VERSION: ${{ needs.set-product-version.outputs.product-prerelease-version }}
LD_FLAGS: "${{ needs.set-product-version.outputs.set-ld-flags}}"
CGO_ENABLED: "0"
uses: hashicorp/actions-go-build@v1
with:
bin_name: ${{ env.REPO_NAME }}_v${{ needs.set-product-version.outputs.product-version }}_${{ needs.plugin-check.outputs.api_version }}_${{ matrix.goos }}_${{ matrix.goarch }}
product_name: ${{ env.REPO_NAME }}
product_version: ${{ needs.set-product-version.outputs.product-version }}
go_version: ${{ matrix.go }}
os: ${{ matrix.goos }}
arch: ${{ matrix.goarch }}
reproducible: report
instructions: |-
cp LICENSE "$TARGET_DIR/LICENSE.txt"
go build -o "$BIN_PATH" -ldflags="$LD_FLAGS" -trimpath -buildvcs=false

upload-manifest-json:
needs:
- set-product-version
- plugin-check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: create-manifest-json
id: create-manifest-json
run: |
API_VERSION="${{ needs.plugin-check.outputs.api_version }}"
CLEAN_API_VERSION="${API_VERSION#x}"
cat > ${{ env.REPO_NAME }}_${{ needs.set-product-version.outputs.product-version }}_manifest.json << EOF
{
"version": "${{ needs.set-product-version.outputs.product-version }}",
"metadata": {
"protocol_version": "${CLEAN_API_VERSION}"
}
}
EOF
- name: Upload manifest json
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
with:
name: packer-plugin-manifest.json
path: ${{ env.REPO_NAME }}_${{ needs.set-product-version.outputs.product-version }}_manifest.json
146 changes: 0 additions & 146 deletions .github/workflows/build_plugin_binaries.yml

This file was deleted.

Loading
Loading