-
Notifications
You must be signed in to change notification settings - Fork 5
176 lines (170 loc) · 5.99 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
---
name: build
on:
# Run the build workflow manually from GitHub Actions menu
workflow_dispatch:
# Run the build workflow on merge to main
push:
branches:
- main
env:
PKG_NAME: "enos"
jobs:
product-metadata:
runs-on: ubuntu-latest
outputs:
filepath: ${{ steps.generate-metadata-file.outputs.filepath }}
product-version: ${{ steps.product-metadata.outputs.product-version }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- id: product-metadata
run: |
make version
echo "product-version=$(make version)" >> "$GITHUB_OUTPUT"
- id: generate-metadata-file
uses: hashicorp/actions-generate-metadata@main
with:
version: ${{ steps.product-metadata.outputs.product-version }}
product: ${{ env.PKG_NAME }}
- uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: metadata.json
path: ${{ steps.generate-metadata-file.outputs.filepath }}
profile-binary:
runs-on: ubuntu-latest
env:
GOPRIVATE: 'github.com/hashicorp/*'
TOKEN: ${{ secrets.ELEVATED_GITHUB_TOKEN }}
outputs:
profile-path: ${{ steps.final-profile.outputs.profile-path }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: go.mod
- id: product-metadata
run: |
make version
echo "product-version=$(make version)" >> "$GITHUB_OUTPUT"
- uses: ./.github/actions/build
name: Standard build
with:
bundle: false
goarch: amd64
goos: linux
version: ${{ steps.product-metadata.outputs.product-version }}
- uses: ./.github/actions/profile-build
name: Profile standard build
with:
upload-profile: false
- uses: ./.github/actions/build
name: Optimized build
with:
bundle: false
goarch: amd64
goos: linux
pgo: true
version: ${{ steps.product-metadata.outputs.product-version }}
- uses: ./.github/actions/profile-build
id: final-profile
name: Profile optimized build
build:
needs:
- product-metadata
- profile-binary
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux, darwin]
goarch: [amd64, arm64]
fail-fast: true
name: Go ${{ matrix.goos }} ${{ matrix.goarch }} build
env:
GOPRIVATE: 'github.com/hashicorp/*'
TOKEN: ${{ secrets.ELEVATED_GITHUB_TOKEN }}
outputs:
artifact-name: ${{ steps.build.outputs.artifact-name }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: go.mod
- uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4
id: download
with:
name: ${{ needs.profile-binary.outputs.profile-path }}
- uses: ./.github/actions/build
name: Build
id: build
with:
goarch: ${{ matrix.goarch }}
goos: ${{ matrix.goos }}
pgo: true
version: ${{ needs.product-metadata.outputs.product-version }}
- name: Upload Artifacts
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: ${{ steps.build.outputs.artifact-name }}
path: ${{ steps.build.outputs.artifact-path }}
retention-days: 1
- if: ${{ matrix.goos == 'linux' }}
uses: hashicorp/actions-packaging-linux@v1
with:
name: ${{ github.event.repository.name }}
description: "enos CLI package"
arch: ${{ matrix.goarch }}
version: ${{ needs.product-metadata.outputs.product-version }}
maintainer: "HashiCorp"
homepage: "https://github.com/hashicorp/enos"
license: "MPL-2.0"
binary: "dist/${{ env.PKG_NAME }}"
deb_depends: "openssl"
rpm_depends: "openssl"
- name: Set Package Names
if: ${{ matrix.goos == 'linux' }}
run: |
echo "RPM_PACKAGE=$(basename out/*.rpm)" >> "$GITHUB_ENV"
echo "DEB_PACKAGE=$(basename out/*.deb)" >> "$GITHUB_ENV"
- name: Upload RHEL Packages
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
if: ${{ matrix.goos == 'linux' }}
with:
name: ${{ env.RPM_PACKAGE }}
path: out/${{ env.RPM_PACKAGE }}
- name: Upload Debian Packages
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
if: ${{ matrix.goos == 'linux' }}
with:
name: ${{ env.DEB_PACKAGE }}
path: out/${{ env.DEB_PACKAGE }}
build-docker:
name: Docker ${{ matrix.arch }} build
needs:
- product-metadata
- build
runs-on: ubuntu-latest
strategy:
matrix:
arch: ["arm64", "amd64"]
env:
repo: ${{github.event.repository.name}}
version: ${{needs.product-metadata.outputs.product-version}}
GOPRIVATE: 'github.com/hashicorp/*'
TOKEN: ${{ secrets.ELEVATED_GITHUB_TOKEN }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: hashicorp/actions-docker-build@v1
with:
version: ${{env.version}}
target: default
arch: ${{matrix.arch}}
tags: |
docker.io/hashicorp/${{env.repo}}:${{env.version}}
986891699432.dkr.ecr.us-east-1.amazonaws.com/hashicorp/${{env.repo}}:${{env.version}}
validate-artifact:
name: Validate Artifact
needs: [build, product-metadata]
uses: ./.github/workflows/validate.yml
with:
artifact-name: "enos_${{ needs.product-metadata.outputs.product-version }}_linux_amd64.zip"
secrets: inherit