|
| 1 | +# |
| 2 | +# This GitHub action builds vagrant binaries, linux packages, |
| 3 | +# and Docker images from source, and uploads them to GitHub artifacts. |
| 4 | +# Note that artifacts available via GitHub Artifacts are not codesigned or notarized. |
| 5 | +# |
| 6 | + |
| 7 | +name: build |
| 8 | + |
| 9 | +on: |
| 10 | + workflow_dispatch: |
| 11 | + workflow_call: |
| 12 | + push: |
| 13 | + branches: |
| 14 | + - main |
| 15 | + - release/** |
| 16 | + |
| 17 | +env: |
| 18 | + REPO_NAME: "packer-plugin-vagrant" |
| 19 | + |
| 20 | +permissions: |
| 21 | + contents: read |
| 22 | + |
| 23 | +jobs: |
| 24 | + get-go-version: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + outputs: |
| 27 | + go-version: ${{ steps.get-go-version.outputs.go-version }} |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 30 | + - name: 'Determine Go version' |
| 31 | + id: get-go-version |
| 32 | + # We use .go-version as our source of truth for current Go |
| 33 | + # version, because "goenv" can react to it automatically. |
| 34 | + run: | |
| 35 | + echo "Building with Go $(cat .go-version)" |
| 36 | + echo "go-version=$(cat .go-version)" >> $GITHUB_OUTPUT |
| 37 | +
|
| 38 | + set-product-version: |
| 39 | + runs-on: ubuntu-latest |
| 40 | + outputs: |
| 41 | + product-version: ${{ steps.set-product-version.outputs.product-version }} |
| 42 | + base-product-version: ${{ steps.set-product-version.outputs.base-product-version }} |
| 43 | + product-date: ${{ steps.set-product-version.outputs.product-date }} |
| 44 | + product-prerelease-version: ${{ steps.set-product-version.outputs.prerelease-product-version }} |
| 45 | + set-ld-flags: ${{ steps.set-ld-flags.outputs.set-ld-flags }} |
| 46 | + steps: |
| 47 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 48 | + - name: set product version |
| 49 | + id: set-product-version |
| 50 | + uses: hashicorp/actions-set-product-version@v1 |
| 51 | + - name: set-ld-flags |
| 52 | + id: set-ld-flags |
| 53 | + run: | |
| 54 | + T="github.com/hashicorp/packer-plugin-vagrant/version" |
| 55 | + 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 |
| 56 | + - name: validate outputs |
| 57 | + run: | |
| 58 | + echo "Product Version: ${{ steps.set-product-version.outputs.product-version }}" |
| 59 | + echo "Base Product Version: ${{ steps.set-product-version.outputs.base-product-version }}" |
| 60 | + echo "Prerelease Version: ${{ steps.set-product-version.outputs.prerelease-product-version }}" |
| 61 | + echo "ldflags: ${{ steps.set-ld-flags.outputs.set-ld-flags }}" |
| 62 | +
|
| 63 | + generate-metadata-file: |
| 64 | + needs: set-product-version |
| 65 | + runs-on: ubuntu-latest |
| 66 | + outputs: |
| 67 | + filepath: ${{ steps.generate-metadata-file.outputs.filepath }} |
| 68 | + steps: |
| 69 | + - name: 'Checkout directory' |
| 70 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 71 | + - name: Generate metadata file |
| 72 | + id: generate-metadata-file |
| 73 | + uses: hashicorp/actions-generate-metadata@main |
| 74 | + with: |
| 75 | + version: ${{ needs.set-product-version.outputs.product-version }} |
| 76 | + product: ${{ env.REPO_NAME }} |
| 77 | + |
| 78 | + - uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0 |
| 79 | + with: |
| 80 | + name: metadata.json |
| 81 | + path: ${{ steps.generate-metadata-file.outputs.filepath }} |
| 82 | + |
| 83 | + plugin-check: |
| 84 | + needs: get-go-version |
| 85 | + runs-on: ubuntu-latest |
| 86 | + outputs: |
| 87 | + api_version: ${{ steps.plugin_describe.outputs.api_version }} |
| 88 | + steps: |
| 89 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 90 | + - name: Unshallow |
| 91 | + run: git fetch --prune --unshallow |
| 92 | + - name: Set up Go |
| 93 | + uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 |
| 94 | + with: |
| 95 | + go-version: ${{ needs.get-go-version.outputs.go-version }} |
| 96 | + - name: Describe plugin |
| 97 | + id: plugin_describe |
| 98 | + run: echo "api_version=$(go run . describe | jq -r '.api_version')" >> "$GITHUB_OUTPUT" |
| 99 | + - name: Run test |
| 100 | + run: go test ./... |
| 101 | + - name: Make plugin-check |
| 102 | + run: make plugin-check |
| 103 | + |
| 104 | + build-other: |
| 105 | + needs: |
| 106 | + - set-product-version |
| 107 | + - get-go-version |
| 108 | + - plugin-check |
| 109 | + runs-on: ubuntu-latest |
| 110 | + strategy: |
| 111 | + matrix: |
| 112 | + goos: [ freebsd, windows, netbsd, openbsd, solaris ] |
| 113 | + goarch: [ "386", "amd64", "arm"] |
| 114 | + go: [ "${{ needs.get-go-version.outputs.go-version }}" ] |
| 115 | + exclude: |
| 116 | + - goos: solaris |
| 117 | + goarch: 386 |
| 118 | + - goos: solaris |
| 119 | + goarch: arm |
| 120 | + - goos: windows |
| 121 | + goarch: arm |
| 122 | + fail-fast: true |
| 123 | + |
| 124 | + name: Go ${{ matrix.go }} ${{ matrix.goos }} ${{ matrix.goarch }} build |
| 125 | + |
| 126 | + steps: |
| 127 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 128 | + - name: Go Build |
| 129 | + env: |
| 130 | + PRODUCT_VERSION: ${{ needs.set-product-version.outputs.product-version }} |
| 131 | + PRERELEASE_VERSION: ${{ needs.set-product-version.outputs.product-prerelease-version }} |
| 132 | + LD_FLAGS: "${{ needs.set-product-version.outputs.set-ld-flags}}" |
| 133 | + CGO_ENABLED: "0" |
| 134 | + uses: hashicorp/actions-go-build@v1 |
| 135 | + with: |
| 136 | + bin_name: ${{ env.REPO_NAME }}_v${{ needs.set-product-version.outputs.product-version }}_${{ needs.plugin-check.outputs.api_version }}_${{ matrix.goos }}_${{ matrix.goarch }} |
| 137 | + product_name: ${{ env.REPO_NAME }} |
| 138 | + product_version: ${{ needs.set-product-version.outputs.product-version }} |
| 139 | + go_version: ${{ matrix.go }} |
| 140 | + os: ${{ matrix.goos }} |
| 141 | + arch: ${{ matrix.goarch }} |
| 142 | + reproducible: report |
| 143 | + instructions: |- |
| 144 | + cp LICENSE "$TARGET_DIR/LICENSE.txt" |
| 145 | + go build -o "$BIN_PATH" -ldflags="$LD_FLAGS" -trimpath -buildvcs=false |
| 146 | +
|
| 147 | + build-linux: |
| 148 | + needs: |
| 149 | + - set-product-version |
| 150 | + - get-go-version |
| 151 | + - plugin-check |
| 152 | + runs-on: ubuntu-latest |
| 153 | + strategy: |
| 154 | + matrix: |
| 155 | + goos: [ linux ] |
| 156 | + goarch: [ "arm", "arm64", "386", "amd64" ] |
| 157 | + go: [ "${{ needs.get-go-version.outputs.go-version }}" ] |
| 158 | + fail-fast: true |
| 159 | + |
| 160 | + name: Go ${{ matrix.go }} ${{ matrix.goos }} ${{ matrix.goarch }} build |
| 161 | + |
| 162 | + steps: |
| 163 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 164 | + - name: Go Build |
| 165 | + env: |
| 166 | + PRODUCT_VERSION: ${{ needs.set-product-version.outputs.product-version }} |
| 167 | + PRERELEASE_VERSION: ${{ needs.set-product-version.outputs.product-prerelease-version }} |
| 168 | + LD_FLAGS: "${{ needs.set-product-version.outputs.set-ld-flags}}" |
| 169 | + CGO_ENABLED: "0" |
| 170 | + uses: hashicorp/actions-go-build@v1 |
| 171 | + with: |
| 172 | + bin_name: ${{ env.REPO_NAME }}_v${{ needs.set-product-version.outputs.product-version }}_${{ needs.plugin-check.outputs.api_version }}_${{ matrix.goos }}_${{ matrix.goarch }} |
| 173 | + product_name: ${{ env.REPO_NAME }} |
| 174 | + product_version: ${{ needs.set-product-version.outputs.product-version }} |
| 175 | + go_version: ${{ matrix.go }} |
| 176 | + os: ${{ matrix.goos }} |
| 177 | + arch: ${{ matrix.goarch }} |
| 178 | + reproducible: report |
| 179 | + instructions: |- |
| 180 | + cp LICENSE "$TARGET_DIR/LICENSE.txt" |
| 181 | + go build -o "$BIN_PATH" -ldflags="$LD_FLAGS" -trimpath -buildvcs=false |
| 182 | +
|
| 183 | + build-darwin: |
| 184 | + needs: |
| 185 | + - set-product-version |
| 186 | + - get-go-version |
| 187 | + - plugin-check |
| 188 | + runs-on: macos-latest |
| 189 | + strategy: |
| 190 | + matrix: |
| 191 | + goos: [ darwin ] |
| 192 | + goarch: [ "amd64", "arm64" ] |
| 193 | + go: [ "${{ needs.get-go-version.outputs.go-version }}" ] |
| 194 | + fail-fast: true |
| 195 | + name: Go ${{ matrix.go }} ${{ matrix.goos }} ${{ matrix.goarch }} build |
| 196 | + |
| 197 | + steps: |
| 198 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 199 | + - name: Go Build |
| 200 | + env: |
| 201 | + PRODUCT_VERSION: ${{ needs.set-product-version.outputs.product-version }} |
| 202 | + PRERELEASE_VERSION: ${{ needs.set-product-version.outputs.product-prerelease-version }} |
| 203 | + LD_FLAGS: "${{ needs.set-product-version.outputs.set-ld-flags}}" |
| 204 | + CGO_ENABLED: "0" |
| 205 | + uses: hashicorp/actions-go-build@v1 |
| 206 | + with: |
| 207 | + bin_name: ${{ env.REPO_NAME }}_v${{ needs.set-product-version.outputs.product-version }}_${{ needs.plugin-check.outputs.api_version }}_${{ matrix.goos }}_${{ matrix.goarch }} |
| 208 | + product_name: ${{ env.REPO_NAME }} |
| 209 | + product_version: ${{ needs.set-product-version.outputs.product-version }} |
| 210 | + go_version: ${{ matrix.go }} |
| 211 | + os: ${{ matrix.goos }} |
| 212 | + arch: ${{ matrix.goarch }} |
| 213 | + reproducible: report |
| 214 | + instructions: |- |
| 215 | + cp LICENSE "$TARGET_DIR/LICENSE.txt" |
| 216 | + go build -o "$BIN_PATH" -ldflags="$LD_FLAGS" -trimpath -buildvcs=false |
| 217 | +
|
| 218 | + upload-manifest-json: |
| 219 | + needs: |
| 220 | + - set-product-version |
| 221 | + - plugin-check |
| 222 | + runs-on: ubuntu-latest |
| 223 | + steps: |
| 224 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 225 | + - name: create-manifest-json |
| 226 | + id: create-manifest-json |
| 227 | + run: | |
| 228 | + API_VERSION="${{ needs.plugin-check.outputs.api_version }}" |
| 229 | + CLEAN_API_VERSION="${API_VERSION#x}" |
| 230 | + cat > ${{ env.REPO_NAME }}_${{ needs.set-product-version.outputs.product-version }}_manifest.json << EOF |
| 231 | + { |
| 232 | + "version": "${{ needs.set-product-version.outputs.product-version }}", |
| 233 | + "metadata": { |
| 234 | + "protocol_version": "${CLEAN_API_VERSION}" |
| 235 | + } |
| 236 | + } |
| 237 | + EOF |
| 238 | + - name: Upload manifest json |
| 239 | + uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0 |
| 240 | + with: |
| 241 | + name: packer-plugin-manifest.json |
| 242 | + path: ${{ env.REPO_NAME }}_${{ needs.set-product-version.outputs.product-version }}_manifest.json |
0 commit comments