-
Notifications
You must be signed in to change notification settings - Fork 125
168 lines (167 loc) · 6.43 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
name: build
on:
push:
workflow_dispatch:
workflow_call:
env:
PKG_NAME: "levant"
jobs:
get-go-version:
name: "Determine Go toolchain version"
runs-on: ubuntu-20.04
outputs:
go-version: ${{ steps.get-go-version.outputs.go-version }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Determine Go version
id: get-go-version
run: |
echo "Building with Go $(cat .go-version)"
echo "go-version=$(cat .go-version)" >> "$GITHUB_OUTPUT"
get-product-version:
runs-on: ubuntu-20.04
outputs:
product-version: ${{ steps.get-product-version.outputs.product-version }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: get product version
id: get-product-version
run: |
make version
echo "product-version=$(make version)" >> "$GITHUB_OUTPUT"
generate-metadata-file:
needs: get-product-version
runs-on: ubuntu-20.04
outputs:
filepath: ${{ steps.generate-metadata-file.outputs.filepath }}
steps:
- name: "Checkout directory"
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Generate metadata file
id: generate-metadata-file
uses: hashicorp/actions-generate-metadata@v1
with:
version: ${{ needs.get-product-version.outputs.product-version }}
product: ${{ env.PKG_NAME }}
repositoryOwner: "hashicorp"
- uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
if: ${{ !env.ACT }}
with:
name: metadata.json
path: ${{ steps.generate-metadata-file.outputs.filepath }}
generate-ldflags:
needs: get-product-version
runs-on: ubuntu-20.04
outputs:
ldflags: ${{ steps.generate-ldflags.outputs.ldflags }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Generate ld flags
id: generate-ldflags
run: |
echo "ldflags=-X 'github.com/hashicorp/levant/version.GitDescribe=v${{ needs.get-product-version.outputs.product-version }}'" >> "$GITHUB_OUTPUT"
build:
needs:
- get-go-version
- get-product-version
- generate-ldflags
runs-on: ubuntu-20.04
strategy:
matrix:
goos: ["linux", "darwin", "windows", "freebsd"]
goarch: [ "amd64", "arm64"]
include:
- { goos: "linux", goarch: "386" }
- { goos: "linux", goarch: "arm" }
- { goos: "freebsd", goarch: "arm" }
fail-fast: true
name: Go ${{ needs.get-go-version.outputs.go-version }} ${{ matrix.goos }} ${{ matrix.goarch }} build
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
with:
go-version-file: ".go-version"
- name: Determine artifact basename
run: echo "ARTIFACT_BASENAME=${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip" >> "$GITHUB_ENV"
- name: Build Levant
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
GO_LDFLAGS: ${{ needs.generate-ldflags.outputs.ldflags }}
CGO_ENABLED: "0"
BIN_PATH: ${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}
uses: hashicorp/[email protected]
with:
product_name: ${{ env.PKG_NAME }}
product_version: ${{ needs.get-product-version.outputs.product-version }}
go_version: ${{ needs.get-go-version.outputs.go-version }}
os: ${{ matrix.goos }}
arch: ${{ matrix.goarch }}
reproducible: nope
instructions: |-
make crt
- if: ${{ matrix.goos == 'linux' }}
uses: hashicorp/actions-packaging-linux@v1
with:
name: "levant"
description: "Levant is a templating and deployment tool for HashiCorp Nomad"
arch: ${{ matrix.goarch }}
version: ${{ needs.get-product-version.outputs.product-version }}
maintainer: "HashiCorp"
homepage: "https://github.com/hashicorp/levant"
license: "MPL-2.0"
binary: out/${{ env.ARTIFACT_BASENAME }}
deb_depends: "openssl"
rpm_depends: "openssl"
- if: ${{ matrix.goos == 'linux' }}
name: Determine package file names
run: |
echo "RPM_PACKAGE=$(basename out/*.rpm)" >> "$GITHUB_ENV"
echo "DEB_PACKAGE=$(basename out/*.deb)" >> "$GITHUB_ENV"
- if: ${{ matrix.goos == 'linux' }}
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: ${{ env.RPM_PACKAGE }}
path: out/${{ env.RPM_PACKAGE }}
if-no-files-found: error
- if: ${{ matrix.goos == 'linux' }}
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: ${{ env.DEB_PACKAGE }}
path: out/${{ env.DEB_PACKAGE }}
if-no-files-found: error
build-docker-default:
needs:
- get-product-version
- build
runs-on: ubuntu-20.04
strategy:
matrix:
arch: ["arm", "arm64", "386", "amd64"]
fail-fast: true
env:
version: ${{ needs.get-product-version.outputs.product-version }}
name: Docker ${{ matrix.arch }} default release build
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Docker Build (Action)
uses: hashicorp/actions-docker-build@v1
with:
smoke_test: |
TEST_VERSION="$(docker run "${IMAGE_NAME}" version | awk '/Levant/{print $2}')"
if [ "${TEST_VERSION}" != "v${version}" ]; then
echo "Test FAILED"
exit 1
fi
echo "Test PASSED"
version: ${{ needs.get-product-version.outputs.product-version }}
target: release
arch: ${{ matrix.arch }}
tags: |
docker.io/hashicorp/${{ env.PKG_NAME }}:${{ env.version }}
dev_tags: |
docker.io/hashicorppreview/${{ env.PKG_NAME }}:${{ env.version }}-dev
docker.io/hashicorppreview/${{ env.PKG_NAME }}:${{ env.version }}-${{ github.sha }}
permissions:
contents: read