-
Notifications
You must be signed in to change notification settings - Fork 3.3k
253 lines (233 loc) · 9.59 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#
# This GitHub action builds Packer 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"
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@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- 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.get-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@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- 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/version"
echo "set-ld-flags=-s -w -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
- 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@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- 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@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: metadata.json
path: ${{ steps.generate-metadata-file.outputs.filepath }}
build-other:
needs:
- set-product-version
- get-go-version
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
env:
GOPRIVATE: "github.com/hashicorp"
GO111MODULE: on
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- 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/[email protected]
with:
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: |-
go build -o "$BIN_PATH" -ldflags="$LD_FLAGS" -trimpath -buildvcs=false
build-linux:
needs:
- set-product-version
- get-go-version
runs-on: ubuntu-latest
strategy:
matrix:
goos: [ linux ]
goarch: [ "arm", "arm64", "386", "amd64", "ppc64le"]
go: [ "${{ needs.get-go-version.outputs.go-version }}" ]
fail-fast: true
name: Go ${{ matrix.go }} ${{ matrix.goos }} ${{ matrix.goarch }} build
env:
GOPRIVATE: "github.com/hashicorp"
GO111MODULE: on
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- 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/[email protected]
with:
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: |-
go build -o "$BIN_PATH" -ldflags="$LD_FLAGS" -trimpath -buildvcs=false
- name: Linux Packaging
uses: hashicorp/actions-packaging-linux@v1
with:
name: ${{ env.REPO_NAME }}
description: "HashiCorp Packer - A tool for creating identical machine images for multiple platforms from a single source configuration"
arch: ${{ matrix.goarch }}
version: ${{ needs.set-product-version.outputs.product-version }}
maintainer: "HashiCorp"
homepage: "https://www.packer.io/docs"
license: "MPL-2.0"
binary: "dist/${{ env.REPO_NAME }}"
deb_depends: "openssl"
rpm_depends: "openssl"
- name: Add Linux Package names to env
run: |
echo "RPM_PACKAGE=$(basename out/*.rpm)" >> $GITHUB_ENV
echo "DEB_PACKAGE=$(basename out/*.deb)" >> $GITHUB_ENV
- uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: ${{ env.RPM_PACKAGE }}
path: out/${{ env.RPM_PACKAGE }}
- uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: ${{ env.DEB_PACKAGE }}
path: out/${{ env.DEB_PACKAGE }}
build-darwin:
needs:
- set-product-version
- get-go-version
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
env:
GOPRIVATE: "github.com/hashicorp"
GO111MODULE: on
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- 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/[email protected]
with:
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: |-
go build -o "$BIN_PATH" -ldflags="$LD_FLAGS" -tags netcgo -trimpath -buildvcs=false
build-docker:
name: Docker light ${{ matrix.arch }} build
needs:
- set-product-version
- build-linux
runs-on: ubuntu-latest
strategy:
matrix:
arch: [ "arm", "arm64", "386", "amd64" ]
env:
version: ${{ needs.set-product-version.outputs.product-version }}
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: Docker Build (Action)
uses: hashicorp/actions-docker-build@v1
with:
version: ${{ env.version }}
target: release-light
arch: ${{ matrix.arch }}
tags: |
docker.io/hashicorp/${{ env.REPO_NAME }}:light
docker.io/hashicorp/${{ env.REPO_NAME }}:light-${{ env.version }}
docker.io/hashicorp/${{ env.REPO_NAME }}:${{ env.version }}
public.ecr.aws/hashicorp/${{ env.REPO_NAME }}:light
public.ecr.aws/hashicorp/${{ env.REPO_NAME }}:light-${{ env.version }}
public.ecr.aws/hashicorp/${{ env.REPO_NAME }}:${{ env.version }}
dev_tags: |
docker.io/hashicorppreview/${{ env.REPO_NAME }}:${{ env.version }}
docker.io/hashicorppreview/${{ env.REPO_NAME }}:${{ env.version }}-${{ github.sha }}