github.com/hashicorp/packer@v1.14.3/.github/workflows/build.yml (about) 1 # 2 # This GitHub action builds Packer 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 - feature/** 17 18 env: 19 REPO_NAME: "packer" 20 21 permissions: 22 contents: read 23 24 jobs: 25 get-go-version: 26 runs-on: ubuntu-latest 27 outputs: 28 go-version: ${{ steps.get-go-version.outputs.go-version }} 29 steps: 30 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 31 - name: 'Determine Go version' 32 id: get-go-version 33 # We use .go-version as our source of truth for current Go 34 # version, because "goenv" can react to it automatically. 35 run: | 36 echo "Building with Go $(cat .go-version)" 37 echo "go-version=$(cat .go-version)" >> $GITHUB_OUTPUT 38 39 set-product-version: 40 runs-on: ubuntu-latest 41 outputs: 42 product-version: ${{ steps.set-product-version.outputs.product-version }} 43 base-product-version: ${{ steps.set-product-version.outputs.base-product-version }} 44 product-date: ${{ steps.set-product-version.outputs.product-date }} 45 product-prerelease-version: ${{ steps.set-product-version.outputs.prerelease-product-version }} 46 set-ld-flags: ${{ steps.set-ld-flags.outputs.set-ld-flags }} 47 steps: 48 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 49 - name: set product version 50 id: set-product-version 51 uses: hashicorp/actions-set-product-version@v1 52 - name: set-ld-flags 53 id: set-ld-flags 54 run: | 55 T="github.com/hashicorp/packer/version" 56 echo "set-ld-flags=-s -w -B gobuildid -X ${T}.GitCommit=${GITHUB_SHA::8} -X ${T}.GitDescribe=${{ steps.set-product-version.outputs.product-version }} -X ${T}.Version=${{ steps.set-product-version.outputs.base-product-version }} -X ${T}.VersionPrerelease=${{ steps.set-product-version.outputs.prerelease-product-version }} -X ${T}.VersionMetadata=" >> $GITHUB_OUTPUT 57 - name: validate outputs 58 run: | 59 echo "Product Version: ${{ steps.set-product-version.outputs.product-version }}" 60 echo "Base Product Version: ${{ steps.set-product-version.outputs.base-product-version }}" 61 echo "Prerelease Version: ${{ steps.set-product-version.outputs.prerelease-product-version }}" 62 echo "ldflags: ${{ steps.set-ld-flags.outputs.set-ld-flags }}" 63 64 generate-metadata-file: 65 needs: set-product-version 66 runs-on: ubuntu-latest 67 outputs: 68 filepath: ${{ steps.generate-metadata-file.outputs.filepath }} 69 steps: 70 - name: 'Checkout directory' 71 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 72 - name: Generate metadata file 73 id: generate-metadata-file 74 uses: hashicorp/actions-generate-metadata@main 75 with: 76 version: ${{ needs.set-product-version.outputs.product-version }} 77 product: ${{ env.REPO_NAME }} 78 79 - uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0 80 with: 81 name: metadata.json 82 path: ${{ steps.generate-metadata-file.outputs.filepath }} 83 84 build-other: 85 needs: 86 - set-product-version 87 - get-go-version 88 runs-on: ubuntu-latest 89 strategy: 90 matrix: 91 goos: [ freebsd, windows, netbsd, openbsd, solaris ] 92 goarch: [ "386", "amd64", "arm"] 93 go: [ "${{ needs.get-go-version.outputs.go-version }}" ] 94 exclude: 95 - goos: solaris 96 goarch: 386 97 - goos: solaris 98 goarch: arm 99 - goos: windows 100 goarch: arm 101 fail-fast: true 102 103 name: Go ${{ matrix.go }} ${{ matrix.goos }} ${{ matrix.goarch }} build 104 105 env: 106 GOPRIVATE: "github.com/hashicorp" 107 GO111MODULE: on 108 steps: 109 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 110 - name: Go Build 111 env: 112 PRODUCT_VERSION: ${{ needs.set-product-version.outputs.product-version }} 113 PRERELEASE_VERSION: ${{ needs.set-product-version.outputs.product-prerelease-version }} 114 LD_FLAGS: "${{ needs.set-product-version.outputs.set-ld-flags}}" 115 CGO_ENABLED: "0" 116 uses: hashicorp/actions-go-build@v1 117 with: 118 product_name: ${{ env.REPO_NAME }} 119 product_version: ${{ needs.set-product-version.outputs.product-version }} 120 go_version: ${{ matrix.go }} 121 os: ${{ matrix.goos }} 122 arch: ${{ matrix.goarch }} 123 reproducible: report 124 instructions: |- 125 cp LICENSE "$TARGET_DIR/LICENSE.txt" 126 go build -o "$BIN_PATH" -ldflags="$LD_FLAGS" -trimpath -buildvcs=false 127 128 build-linux: 129 needs: 130 - set-product-version 131 - get-go-version 132 runs-on: ubuntu-latest 133 strategy: 134 matrix: 135 goos: [ linux ] 136 goarch: [ "arm", "arm64", "386", "amd64", "ppc64le"] 137 go: [ "${{ needs.get-go-version.outputs.go-version }}" ] 138 fail-fast: true 139 140 name: Go ${{ matrix.go }} ${{ matrix.goos }} ${{ matrix.goarch }} build 141 142 env: 143 GOPRIVATE: "github.com/hashicorp" 144 GO111MODULE: on 145 146 steps: 147 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 148 - name: Go Build 149 env: 150 PRODUCT_VERSION: ${{ needs.set-product-version.outputs.product-version }} 151 PRERELEASE_VERSION: ${{ needs.set-product-version.outputs.product-prerelease-version }} 152 LD_FLAGS: "${{ needs.set-product-version.outputs.set-ld-flags}}" 153 CGO_ENABLED: "0" 154 uses: hashicorp/actions-go-build@v1 155 with: 156 product_name: ${{ env.REPO_NAME }} 157 product_version: ${{ needs.set-product-version.outputs.product-version }} 158 go_version: ${{ matrix.go }} 159 os: ${{ matrix.goos }} 160 arch: ${{ matrix.goarch }} 161 reproducible: report 162 instructions: |- 163 cp LICENSE "$TARGET_DIR/LICENSE.txt" 164 go build -o "$BIN_PATH" -ldflags="$LD_FLAGS" -trimpath -buildvcs=false 165 166 - name: Copy license file to config_dir 167 if: ${{ matrix.goos == 'linux' }} 168 env: 169 LICENSE_DIR: ".release/linux/package/usr/share/doc/${{ env.REPO_NAME }}" 170 run: | 171 mkdir -p "$LICENSE_DIR" && cp LICENSE "$LICENSE_DIR/LICENSE.txt" 172 - name: Linux Packaging 173 uses: hashicorp/actions-packaging-linux@v1 174 with: 175 name: ${{ env.REPO_NAME }} 176 description: "HashiCorp Packer - A tool for creating identical machine images for multiple platforms from a single source configuration" 177 arch: ${{ matrix.goarch }} 178 version: ${{ needs.set-product-version.outputs.product-version }} 179 maintainer: "HashiCorp" 180 homepage: "https://www.packer.io/docs" 181 license: "BUSL-1.1" 182 binary: "dist/${{ env.REPO_NAME }}" 183 deb_depends: "openssl" 184 rpm_depends: "openssl" 185 config_dir: ".release/linux/package/" 186 - name: Add Linux Package names to env 187 run: | 188 echo "RPM_PACKAGE=$(basename out/*.rpm)" >> $GITHUB_ENV 189 echo "DEB_PACKAGE=$(basename out/*.deb)" >> $GITHUB_ENV 190 - uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0 191 with: 192 name: ${{ env.RPM_PACKAGE }} 193 path: out/${{ env.RPM_PACKAGE }} 194 - uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0 195 with: 196 name: ${{ env.DEB_PACKAGE }} 197 path: out/${{ env.DEB_PACKAGE }} 198 199 build-darwin: 200 needs: 201 - set-product-version 202 - get-go-version 203 runs-on: macos-latest 204 strategy: 205 matrix: 206 goos: [ darwin ] 207 goarch: [ "amd64", "arm64" ] 208 go: [ "${{ needs.get-go-version.outputs.go-version }}" ] 209 fail-fast: true 210 name: Go ${{ matrix.go }} ${{ matrix.goos }} ${{ matrix.goarch }} build 211 212 env: 213 GOPRIVATE: "github.com/hashicorp" 214 GO111MODULE: on 215 216 steps: 217 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 218 - name: Go Build 219 env: 220 PRODUCT_VERSION: ${{ needs.set-product-version.outputs.product-version }} 221 PRERELEASE_VERSION: ${{ needs.set-product-version.outputs.product-prerelease-version }} 222 LD_FLAGS: "${{ needs.set-product-version.outputs.set-ld-flags}}" 223 CGO_ENABLED: "0" 224 uses: hashicorp/actions-go-build@v1 225 with: 226 product_name: ${{ env.REPO_NAME }} 227 product_version: ${{ needs.set-product-version.outputs.product-version }} 228 go_version: ${{ matrix.go }} 229 os: ${{ matrix.goos }} 230 arch: ${{ matrix.goarch }} 231 reproducible: report 232 instructions: |- 233 cp LICENSE "$TARGET_DIR/LICENSE.txt" 234 go build -o "$BIN_PATH" -ldflags="$LD_FLAGS" -tags netcgo -trimpath -buildvcs=false 235 236 build-docker-light: 237 name: Docker light ${{ matrix.arch }} build 238 needs: 239 - set-product-version 240 - build-linux 241 runs-on: ubuntu-latest 242 strategy: 243 matrix: 244 arch: [ "arm", "arm64", "386", "amd64" ] 245 env: 246 version: ${{ needs.set-product-version.outputs.product-version }} 247 steps: 248 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 249 - name: Docker Build (Action) 250 uses: hashicorp/actions-docker-build@v2 251 with: 252 version: ${{ env.version }} 253 target: release-light 254 arch: ${{ matrix.arch }} 255 tags: | 256 ${{ steps.set-product-version.output.prerelease-product-version == '' && format('docker.io/hashicorp/{0}:light', env.REPO_NAME) }} 257 docker.io/hashicorp/${{ env.REPO_NAME }}:light-${{ env.version }} 258 docker.io/hashicorp/${{ env.REPO_NAME }}:${{ env.version }} 259 ${{ steps.set-product-version.output.prerelease-product-version == '' && format('public.ecr.aws/hashicorp/{0}:light', env.REPO_NAME) }} 260 public.ecr.aws/hashicorp/${{ env.REPO_NAME }}:light-${{ env.version }} 261 public.ecr.aws/hashicorp/${{ env.REPO_NAME }}:${{ env.version }} 262 dev_tags: | 263 docker.io/hashicorppreview/${{ env.REPO_NAME }}:${{ env.version }} 264 docker.io/hashicorppreview/${{ env.REPO_NAME }}:${{ env.version }}-${{ github.sha }} 265 266 build-docker-full: 267 name: Docker full ${{ matrix.arch }} build 268 needs: 269 - set-product-version 270 - build-linux 271 runs-on: ubuntu-latest 272 strategy: 273 matrix: 274 arch: [ "arm", "arm64", "386", "amd64" ] 275 env: 276 version: ${{ needs.set-product-version.outputs.product-version }} 277 steps: 278 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 279 - name: Docker Build (Action) 280 uses: hashicorp/actions-docker-build@v2 281 with: 282 version: ${{ env.version }} 283 target: release-full 284 arch: ${{ matrix.arch }} 285 tags: | 286 ${{ steps.set-product-version.output.prerelease-product-version == '' && format('docker.io/hashicorp/{0}:full', env.REPO_NAME) }} 287 docker.io/hashicorp/${{ env.REPO_NAME }}:full-${{ env.version }} 288 ${{ steps.set-product-version.output.prerelease-product-version == '' && format('public.ecr.aws/hashicorp/{0}:full', env.REPO_NAME) }} 289 public.ecr.aws/hashicorp/${{ env.REPO_NAME }}:full-${{ env.version }} 290 dev_tags: | 291 docker.io/hashicorppreview/${{ env.REPO_NAME }}:full-${{ env.version }} 292 docker.io/hashicorppreview/${{ env.REPO_NAME }}:full-${{ env.version }}-${{ github.sha }}